ImExporters from ccm-docrepo now implement new interface
parent
ef34c2b7f8
commit
f7e8d2f957
|
|
@ -20,7 +20,6 @@ package org.libreccm.docrepo;
|
|||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
import org.libreccm.core.CcmObject;
|
||||
import org.libreccm.imexport.Exportable;
|
||||
import org.libreccm.security.User;
|
||||
|
|
@ -36,6 +35,8 @@ import javax.validation.constraints.NotNull;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* Abstract entity class of a resource. Instances will be persisted into the
|
||||
* database through the inheriting subclasses.
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
package org.libreccm.docrepo;
|
||||
|
||||
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import org.libreccm.core.Identifiable;
|
||||
import org.libreccm.imexport.Exportable;
|
||||
|
||||
|
|
@ -37,6 +36,10 @@ import java.io.Serializable;
|
|||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* Entity class for a blob object in the doc-repository. Instances of this class
|
||||
* will be persisted into the database.
|
||||
|
|
@ -46,6 +49,12 @@ import java.util.Objects;
|
|||
*/
|
||||
@Entity
|
||||
@Table(schema = "CCM_DOCREPO", name = "BLOB_OBJECTS")
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "BlobObject.findByUuid",
|
||||
query = "SELECT FROM BlobObject o WHERE o.uuid = :uuid"
|
||||
)
|
||||
} )
|
||||
public class BlobObject implements Identifiable, Serializable, Exportable {
|
||||
|
||||
private static final long serialVersionUID = -7468014879548796218L;
|
||||
|
|
|
|||
|
|
@ -21,12 +21,13 @@ package org.libreccm.docrepo;
|
|||
import org.libreccm.imexport.AbstractEntityImExporter;
|
||||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* Im/Exporter for importing and exporting {@code BlobObject}s from the system
|
||||
|
|
@ -55,11 +56,36 @@ public class BlobObjectImExporter extends AbstractEntityImExporter<BlobObject> {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected Optional<BlobObject> findExistingEntity(final String uuid) {
|
||||
return blobObjectRepository.findByUuid(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveImportedEntity(final BlobObject entity) {
|
||||
|
||||
blobObjectRepository.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExistingEntity(
|
||||
final BlobObject existingEntity,
|
||||
final BlobObject importedEntity
|
||||
) {
|
||||
if(!Arrays.equals(
|
||||
existingEntity.getContent(),
|
||||
importedEntity.getContent()
|
||||
)) {
|
||||
existingEntity.setContent(importedEntity.getContent());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getFile(),
|
||||
importedEntity.getFile()
|
||||
)) {
|
||||
existingEntity.setFile(importedEntity.getFile());
|
||||
}
|
||||
|
||||
blobObjectRepository.save(existingEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlobObject reloadEntity(final BlobObject entity) {
|
||||
|
|
|
|||
|
|
@ -20,9 +20,12 @@ package org.libreccm.docrepo;
|
|||
|
||||
import org.libreccm.auditing.AbstractAuditedEntityRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
|
||||
/**
|
||||
* Repository class for retrieving, storing and deleting {@code BlobObject}s.
|
||||
|
|
@ -67,4 +70,17 @@ public class BlobObjectRepository extends
|
|||
return entity.getBlobObjectId() == 0;
|
||||
}
|
||||
|
||||
public Optional<BlobObject> findByUuid(final String uuid) {
|
||||
try {
|
||||
return Optional.of(
|
||||
entityManager
|
||||
.createNamedQuery("BlobObject.findByUuid", BlobObject.class)
|
||||
.setParameter("uuid", uuid)
|
||||
.getSingleResult()
|
||||
);
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,18 +36,30 @@ import javax.persistence.Table;
|
|||
@Table(schema = "CCM_DOCREPO", name = "FILES")
|
||||
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "DocRepo.findFileByName",
|
||||
@NamedQuery(
|
||||
name = "DocRepo.findFileByUuid",
|
||||
query = "SELECT r FROM DocRepoFile r WHERE r.uuid = :uuid"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "DocRepo.findFileByName",
|
||||
query = "SELECT r FROM DocRepoFile r WHERE " +
|
||||
"r.name = :name"),
|
||||
@NamedQuery(name = "DocRepo.findFileByPath",
|
||||
"r.name = :name"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "DocRepo.findFileByPath",
|
||||
query = "SELECT r FROM DocRepoFile r WHERE " +
|
||||
"r.path = :pathName"),
|
||||
@NamedQuery(name = "DocRepo.findCreatedFileFromUser",
|
||||
"r.path = :pathName"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "DocRepo.findCreatedFileFromUser",
|
||||
query = "SELECT r FROM DocRepoFile r WHERE " +
|
||||
"r.creationUser = :user"),
|
||||
@NamedQuery(name = "DocRepo.findModifiedFileFromUser",
|
||||
"r.creationUser = :user"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "DocRepo.findModifiedFileFromUser",
|
||||
query = "SELECT r FROM DocRepoFile r WHERE " +
|
||||
"r.lastModifiedUser = :user")
|
||||
"r.lastModifiedUser = :user"
|
||||
)
|
||||
})
|
||||
public class File extends AbstractResource {
|
||||
|
||||
|
|
|
|||
|
|
@ -19,12 +19,10 @@
|
|||
package org.libreccm.docrepo;
|
||||
|
||||
import org.libreccm.imexport.AbstractEntityImExporter;
|
||||
import org.libreccm.imexport.Exportable;
|
||||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -58,11 +56,124 @@ public class FileImExporter extends AbstractEntityImExporter<File> {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected Optional<File> findExistingEntity(final String uuid) {
|
||||
return fileRepository.findByUuid(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveImportedEntity(final File portableObject) {
|
||||
fileRepository.save(portableObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExistingEntity(
|
||||
final File existingEntity,
|
||||
final File importedEntity
|
||||
) {
|
||||
if (!Objects.equals(
|
||||
existingEntity.getName(),
|
||||
importedEntity.getName()
|
||||
)) {
|
||||
existingEntity.setName(importedEntity.getName());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getDescription(),
|
||||
importedEntity.getDescription()
|
||||
)) {
|
||||
existingEntity.setDescription(importedEntity.getDescription());
|
||||
}
|
||||
|
||||
if(!Objects.equals(
|
||||
existingEntity.getPath(),
|
||||
importedEntity.getPath()
|
||||
)) {
|
||||
existingEntity.setPath(importedEntity.getPath());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getMimeType(),
|
||||
importedEntity.getMimeType()
|
||||
)) {
|
||||
existingEntity.setMimeType(importedEntity.getMimeType());
|
||||
}
|
||||
|
||||
if (existingEntity.getSize() != importedEntity.getSize()) {
|
||||
existingEntity.setSize(importedEntity.getSize());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getCreationDate(),
|
||||
importedEntity.getCreationDate()
|
||||
)) {
|
||||
existingEntity.setCreationDate(importedEntity.getCreationDate());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getLastModifiedDate(),
|
||||
importedEntity.getLastModifiedDate()
|
||||
)) {
|
||||
existingEntity.setLastModifiedDate(
|
||||
importedEntity.getLastModifiedDate()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getCreationIp(),
|
||||
importedEntity.getCreationIp()
|
||||
)) {
|
||||
existingEntity.setCreationIp(importedEntity.getCreationIp());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getLastModifiedIp(),
|
||||
importedEntity.getLastModifiedIp()
|
||||
)) {
|
||||
existingEntity.setLastModifiedIp(
|
||||
importedEntity.getLastModifiedIp()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getCreationUser(),
|
||||
importedEntity.getCreationUser()
|
||||
)) {
|
||||
existingEntity.setCreationUser(importedEntity.getCreationUser());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getLastModifiedUser(),
|
||||
importedEntity.getLastModifiedUser()
|
||||
)) {
|
||||
existingEntity.setLastModifiedUser(
|
||||
importedEntity.getLastModifiedUser()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getParent(),
|
||||
importedEntity.getParent()
|
||||
)) {
|
||||
existingEntity.setParent(importedEntity.getParent());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getRepository(),
|
||||
importedEntity.getRepository()
|
||||
)) {
|
||||
existingEntity.setRepository(importedEntity.getRepository());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getContent(),
|
||||
importedEntity.getContent()
|
||||
)) {
|
||||
existingEntity.setContent(importedEntity.getContent());
|
||||
}
|
||||
|
||||
fileRepository.save(existingEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected File reloadEntity(final File entity) {
|
||||
return fileRepository
|
||||
|
|
|
|||
|
|
@ -18,7 +18,10 @@
|
|||
*/
|
||||
package org.libreccm.docrepo;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
/**
|
||||
|
|
@ -44,6 +47,19 @@ public class FileRepository extends AbstractResourceRepository<File> {
|
|||
return entity.getObjectId();
|
||||
}
|
||||
|
||||
public Optional<File> findByUuid(final String uuid) {
|
||||
try {
|
||||
return Optional.of(
|
||||
entityManager
|
||||
.createNamedQuery("DocRepo.findFileByUuid", File.class)
|
||||
.setParameter("uuid", uuid)
|
||||
.getSingleResult()
|
||||
);
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedQuery<File> getFindByNameQuery() {
|
||||
return entityManager.createNamedQuery(
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* Entity class of a folder in the doc-repository. Instances will be persisted
|
||||
* into the database. Instance variables are inherited from {@link AbstractResource}.
|
||||
* into the database. Instance variables are inherited from
|
||||
* {@link AbstractResource}.
|
||||
*
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||
* @version 01/10/2015
|
||||
|
|
@ -36,18 +37,29 @@ import java.util.List;
|
|||
@Entity(name = "DocRepoFolder")
|
||||
@Table(schema = "CCM_DOCREPO", name = "FOLDERS")
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "DocRepo.findFolderByName",
|
||||
query = "SELECT r FROM DocRepoFolder r WHERE " +
|
||||
"r.name = :name"),
|
||||
@NamedQuery(name = "DocRepo.findFolderByPath",
|
||||
query = "SELECT r FROM DocRepoFolder r WHERE " +
|
||||
"r.path = :pathName"),
|
||||
@NamedQuery(name = "DocRepo.findCreatedFolderFromUser",
|
||||
query = "SELECT r FROM DocRepoFolder r WHERE " +
|
||||
"r.creationUser = :user"),
|
||||
@NamedQuery(name = "DocRepo.findModifiedFolderFromUser",
|
||||
query = "SELECT r FROM DocRepoFolder r WHERE " +
|
||||
"r.lastModifiedUser = :user")
|
||||
@NamedQuery(
|
||||
name = "DocRepo.findFolderByUuid",
|
||||
query = "SELECT r FROM DocRepoFolder r WHERE r.uuid = :uuid"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "DocRepo.findFolderByName",
|
||||
query = "SELECT r FROM DocRepoFolder r WHERE " + "r.name = :name"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "DocRepo.findFolderByPath",
|
||||
query = "SELECT r FROM DocRepoFolder r WHERE " + "r.path = :pathName"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "DocRepo.findCreatedFolderFromUser",
|
||||
query = "SELECT r FROM DocRepoFolder r WHERE " + "r.creationUser = :user"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "DocRepo.findModifiedFolderFromUser",
|
||||
query = "SELECT r FROM DocRepoFolder r WHERE "
|
||||
+ "r.lastModifiedUser = :user"
|
||||
)
|
||||
|
||||
|
||||
})
|
||||
public class Folder extends AbstractResource {
|
||||
|
||||
|
|
@ -66,14 +78,14 @@ public class Folder extends AbstractResource {
|
|||
private Repository rootAssignedRepository;
|
||||
|
||||
/**
|
||||
* Constructor calls the super-class-constructor of {@link AbstractResource}.
|
||||
* Constructor calls the super-class-constructor of
|
||||
* {@link AbstractResource}.
|
||||
*/
|
||||
public Folder() {
|
||||
super();
|
||||
}
|
||||
|
||||
//> Begin GETTER & SETTER
|
||||
|
||||
public List<AbstractResource> getImmediateChildren() {
|
||||
return immediateChildren;
|
||||
}
|
||||
|
|
@ -90,6 +102,5 @@ public class Folder extends AbstractResource {
|
|||
this.rootAssignedRepository = rootAssignedRepository;
|
||||
}
|
||||
|
||||
|
||||
//< End GETTER & SETTER
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ package org.libreccm.docrepo;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* Im/Exporter for importing and exporting {@link Folder}s from the system into
|
||||
|
|
@ -51,12 +51,127 @@ public class FolderImExporter extends AbstractResourceImExporter<Folder> {
|
|||
public Class<Folder> getEntityClass() {
|
||||
return Folder.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Folder> findExistingEntity(final String uuid) {
|
||||
return folderRepository.findByUuid(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void saveImportedEntity(final Folder entity) {
|
||||
folderRepository.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExistingEntity(
|
||||
final Folder existingEntity,
|
||||
final Folder importedEntity
|
||||
) {
|
||||
if (!Objects.equals(
|
||||
existingEntity.getName(),
|
||||
importedEntity.getName()
|
||||
)) {
|
||||
existingEntity.setName(importedEntity.getName());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getDescription(),
|
||||
importedEntity.getDescription()
|
||||
)) {
|
||||
existingEntity.setDescription(importedEntity.getDescription());
|
||||
}
|
||||
|
||||
if(!Objects.equals(
|
||||
existingEntity.getPath(),
|
||||
importedEntity.getPath()
|
||||
)) {
|
||||
existingEntity.setPath(importedEntity.getPath());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getMimeType(),
|
||||
importedEntity.getMimeType()
|
||||
)) {
|
||||
existingEntity.setMimeType(importedEntity.getMimeType());
|
||||
}
|
||||
|
||||
if (existingEntity.getSize() != importedEntity.getSize()) {
|
||||
existingEntity.setSize(importedEntity.getSize());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getCreationDate(),
|
||||
importedEntity.getCreationDate()
|
||||
)) {
|
||||
existingEntity.setCreationDate(importedEntity.getCreationDate());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getLastModifiedDate(),
|
||||
importedEntity.getLastModifiedDate()
|
||||
)) {
|
||||
existingEntity.setLastModifiedDate(
|
||||
importedEntity.getLastModifiedDate()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getCreationIp(),
|
||||
importedEntity.getCreationIp()
|
||||
)) {
|
||||
existingEntity.setCreationIp(importedEntity.getCreationIp());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getLastModifiedIp(),
|
||||
importedEntity.getLastModifiedIp()
|
||||
)) {
|
||||
existingEntity.setLastModifiedIp(
|
||||
importedEntity.getLastModifiedIp()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getCreationUser(),
|
||||
importedEntity.getCreationUser()
|
||||
)) {
|
||||
existingEntity.setCreationUser(importedEntity.getCreationUser());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getLastModifiedUser(),
|
||||
importedEntity.getLastModifiedUser()
|
||||
)) {
|
||||
existingEntity.setLastModifiedUser(
|
||||
importedEntity.getLastModifiedUser()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getParent(),
|
||||
importedEntity.getParent()
|
||||
)) {
|
||||
existingEntity.setParent(importedEntity.getParent());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getRepository(),
|
||||
importedEntity.getRepository()
|
||||
)) {
|
||||
existingEntity.setRepository(importedEntity.getRepository());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getRootAssignedRepository(),
|
||||
importedEntity.getRootAssignedRepository()
|
||||
)) {
|
||||
existingEntity.setRootAssignedRepository(
|
||||
importedEntity.getRootAssignedRepository()
|
||||
);
|
||||
}
|
||||
|
||||
folderRepository.save(importedEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Folder reloadEntity(final Folder entity) {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,10 @@
|
|||
*/
|
||||
package org.libreccm.docrepo;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
/**
|
||||
|
|
@ -28,6 +31,7 @@ import javax.persistence.TypedQuery;
|
|||
* @version 27.01.2016
|
||||
*/
|
||||
@RequestScoped
|
||||
@SuppressWarnings("serial")
|
||||
public class FolderRepository extends AbstractResourceRepository<Folder> {
|
||||
|
||||
public FolderRepository() {
|
||||
|
|
@ -38,12 +42,25 @@ public class FolderRepository extends AbstractResourceRepository<Folder> {
|
|||
public String getIdAttributeName() {
|
||||
return "objectId";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Long getIdOfEntity(final Folder entity) {
|
||||
return entity.getObjectId();
|
||||
}
|
||||
|
||||
public Optional<Folder> findByUuid(final String uuid) {
|
||||
try {
|
||||
return Optional.of(
|
||||
entityManager
|
||||
.createNamedQuery("DocRepo.findFolderByUuid", Folder.class)
|
||||
.setParameter("uuid", uuid)
|
||||
.getSingleResult()
|
||||
);
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedQuery<Folder> getFindByNameQuery() {
|
||||
return entityManager.createNamedQuery(
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.libreccm.docrepo;
|
||||
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
import org.libreccm.imexport.Exportable;
|
||||
import org.libreccm.security.User;
|
||||
import org.libreccm.web.CcmApplication;
|
||||
|
|
@ -34,6 +33,8 @@ import javax.persistence.Table;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* Entity class of a repository for documents. Instances will be persisted into
|
||||
* the database. Instance variables are inherited from {@link CcmApplication}.
|
||||
|
|
@ -44,8 +45,14 @@ import java.util.List;
|
|||
@Entity
|
||||
@Table(schema = "CCM_DOCREPO", name = "REPOSITORIES")
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "DocRepo.findRepositoriesForOwner",
|
||||
query = "SELECT r FROM Repository r WHERE r.owner = :owner")
|
||||
@NamedQuery(
|
||||
name = "DocRepo.findRepositoryByUuid",
|
||||
query = "SELECT r FROM Repository r WHERE r.uuid = :uuid"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "DocRepo.findRepositoriesForOwner",
|
||||
query = "SELECT r FROM Repository r WHERE r.owner = :owner"
|
||||
)
|
||||
})
|
||||
public class Repository extends CcmApplication implements Exportable {
|
||||
|
||||
|
|
@ -80,7 +87,6 @@ public class Repository extends CcmApplication implements Exportable {
|
|||
@OneToMany(mappedBy = "repository")
|
||||
private List<AbstractResource> abstractResources;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor calls the super-class-constructor of {@link CcmApplication}.
|
||||
*/
|
||||
|
|
@ -89,7 +95,6 @@ public class Repository extends CcmApplication implements Exportable {
|
|||
}
|
||||
|
||||
//> Begin GETTER & SETTER
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
@ -123,6 +128,4 @@ public class Repository extends CcmApplication implements Exportable {
|
|||
}
|
||||
|
||||
//< End GETTER & SETTER
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.libreccm.imexport.AbstractEntityImExporter;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -48,11 +49,90 @@ public class RepositoryImExporter extends AbstractEntityImExporter<Repository> {
|
|||
public Class<Repository> getEntityClass() {
|
||||
return Repository.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Repository> findExistingEntity(final String uuid) {
|
||||
return repositoryRepository.findByUuid(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveImportedEntity(final Repository portableObject) {
|
||||
repositoryRepository.save(portableObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExistingEntity(
|
||||
final Repository existingEntity,
|
||||
final Repository importedEntity
|
||||
) {
|
||||
if (!Objects.equals(
|
||||
existingEntity.getDisplayName(),
|
||||
importedEntity.getDisplayName()
|
||||
)) {
|
||||
existingEntity.setDisplayName(importedEntity.getDisplayName());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getTitle(),
|
||||
importedEntity.getTitle()
|
||||
)) {
|
||||
syncLocalizedStrings(
|
||||
importedEntity.getTitle(),
|
||||
existingEntity.getTitle()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getDescription(),
|
||||
importedEntity.getDescription()
|
||||
)) {
|
||||
syncLocalizedStrings(
|
||||
importedEntity.getDescription(),
|
||||
existingEntity.getDescription()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getApplicationType(),
|
||||
importedEntity.getApplicationType()
|
||||
)) {
|
||||
existingEntity.setApplicationType(
|
||||
importedEntity.getApplicationType()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getPrimaryUrl(),
|
||||
importedEntity.getPrimaryUrl()
|
||||
)) {
|
||||
existingEntity.setPrimaryUrl(
|
||||
importedEntity.getPrimaryUrl()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getName(),
|
||||
importedEntity.getName()
|
||||
)) {
|
||||
existingEntity.setName(importedEntity.getName());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getRootFolder(),
|
||||
importedEntity.getRootFolder()
|
||||
)) {
|
||||
existingEntity.setRootFolder(importedEntity.getRootFolder());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getOwner(),
|
||||
importedEntity.getOwner()
|
||||
)) {
|
||||
existingEntity.setOwner(importedEntity.getOwner());
|
||||
}
|
||||
|
||||
repositoryRepository.save(existingEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Repository reloadEntity(final Repository entity) {
|
||||
|
|
|
|||
|
|
@ -27,9 +27,13 @@ import javax.enterprise.context.RequestScoped;
|
|||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.NoResultException;
|
||||
|
||||
/**
|
||||
* Repository class for retrieving, storing and deleting {@code Repository}s.
|
||||
*
|
||||
|
|
@ -39,6 +43,8 @@ import java.util.stream.Collectors;
|
|||
public class RepositoryRepository
|
||||
extends AbstractAuditedEntityRepository<Long, Repository> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Inject
|
||||
private EntityManager entityManager;
|
||||
|
||||
|
|
@ -70,6 +76,22 @@ public class RepositoryRepository
|
|||
return entity.getObjectId() == 0;
|
||||
}
|
||||
|
||||
public Optional<Repository> findByUuid(final String uuid) {
|
||||
try {
|
||||
return Optional.of(
|
||||
entityManager
|
||||
.createNamedQuery(
|
||||
"DocRepo.findRepositoryByUuid",
|
||||
Repository.class
|
||||
)
|
||||
.setParameter("uuid", uuid)
|
||||
.getSingleResult()
|
||||
);
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current subject has permissions grating him the privilege
|
||||
* to read the requested {@link Repository}(s) and removes the ones he is
|
||||
|
|
|
|||
Loading…
Reference in New Issue