ImExporters from ccm-docrepo now implement new interface

deploy_packages_to_gitea
Jens Pelzetter 2023-01-12 20:39:25 +01:00
parent ef34c2b7f8
commit f7e8d2f957
13 changed files with 482 additions and 43 deletions

View File

@ -20,7 +20,6 @@ package org.libreccm.docrepo;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.hibernate.validator.constraints.NotBlank;
import org.libreccm.core.CcmObject; import org.libreccm.core.CcmObject;
import org.libreccm.imexport.Exportable; import org.libreccm.imexport.Exportable;
import org.libreccm.security.User; import org.libreccm.security.User;
@ -36,6 +35,8 @@ import javax.validation.constraints.NotNull;
import java.util.Date; import java.util.Date;
import javax.validation.constraints.NotBlank;
/** /**
* Abstract entity class of a resource. Instances will be persisted into the * Abstract entity class of a resource. Instances will be persisted into the
* database through the inheriting subclasses. * database through the inheriting subclasses.

View File

@ -19,7 +19,6 @@
package org.libreccm.docrepo; package org.libreccm.docrepo;
import org.hibernate.validator.constraints.NotEmpty;
import org.libreccm.core.Identifiable; import org.libreccm.core.Identifiable;
import org.libreccm.imexport.Exportable; import org.libreccm.imexport.Exportable;
@ -37,6 +36,10 @@ import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; 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 * Entity class for a blob object in the doc-repository. Instances of this class
* will be persisted into the database. * will be persisted into the database.
@ -46,6 +49,12 @@ import java.util.Objects;
*/ */
@Entity @Entity
@Table(schema = "CCM_DOCREPO", name = "BLOB_OBJECTS") @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 { public class BlobObject implements Identifiable, Serializable, Exportable {
private static final long serialVersionUID = -7468014879548796218L; private static final long serialVersionUID = -7468014879548796218L;

View File

@ -21,12 +21,13 @@ package org.libreccm.docrepo;
import org.libreccm.imexport.AbstractEntityImExporter; import org.libreccm.imexport.AbstractEntityImExporter;
import org.libreccm.imexport.Processes; import org.libreccm.imexport.Processes;
import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.transaction.Transactional;
/** /**
* Im/Exporter for importing and exporting {@code BlobObject}s from the system * Im/Exporter for importing and exporting {@code BlobObject}s from the system
@ -55,11 +56,36 @@ public class BlobObjectImExporter extends AbstractEntityImExporter<BlobObject> {
} }
@Override @Override
@Transactional(Transactional.TxType.REQUIRED) protected Optional<BlobObject> findExistingEntity(final String uuid) {
return blobObjectRepository.findByUuid(uuid);
}
@Override
protected void saveImportedEntity(final BlobObject entity) { protected void saveImportedEntity(final BlobObject entity) {
blobObjectRepository.save(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 @Override
protected BlobObject reloadEntity(final BlobObject entity) { protected BlobObject reloadEntity(final BlobObject entity) {

View File

@ -20,9 +20,12 @@ package org.libreccm.docrepo;
import org.libreccm.auditing.AbstractAuditedEntityRepository; import org.libreccm.auditing.AbstractAuditedEntityRepository;
import java.util.Optional;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
/** /**
* Repository class for retrieving, storing and deleting {@code BlobObject}s. * Repository class for retrieving, storing and deleting {@code BlobObject}s.
@ -67,4 +70,17 @@ public class BlobObjectRepository extends
return entity.getBlobObjectId() == 0; 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();
}
}
} }

View File

@ -36,18 +36,30 @@ import javax.persistence.Table;
@Table(schema = "CCM_DOCREPO", name = "FILES") @Table(schema = "CCM_DOCREPO", name = "FILES")
@NamedQueries({ @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 " + query = "SELECT r FROM DocRepoFile r WHERE " +
"r.name = :name"), "r.name = :name"
@NamedQuery(name = "DocRepo.findFileByPath", ),
@NamedQuery(
name = "DocRepo.findFileByPath",
query = "SELECT r FROM DocRepoFile r WHERE " + query = "SELECT r FROM DocRepoFile r WHERE " +
"r.path = :pathName"), "r.path = :pathName"
@NamedQuery(name = "DocRepo.findCreatedFileFromUser", ),
@NamedQuery(
name = "DocRepo.findCreatedFileFromUser",
query = "SELECT r FROM DocRepoFile r WHERE " + query = "SELECT r FROM DocRepoFile r WHERE " +
"r.creationUser = :user"), "r.creationUser = :user"
@NamedQuery(name = "DocRepo.findModifiedFileFromUser", ),
@NamedQuery(
name = "DocRepo.findModifiedFileFromUser",
query = "SELECT r FROM DocRepoFile r WHERE " + query = "SELECT r FROM DocRepoFile r WHERE " +
"r.lastModifiedUser = :user") "r.lastModifiedUser = :user"
)
}) })
public class File extends AbstractResource { public class File extends AbstractResource {

View File

@ -19,12 +19,10 @@
package org.libreccm.docrepo; package org.libreccm.docrepo;
import org.libreccm.imexport.AbstractEntityImExporter; import org.libreccm.imexport.AbstractEntityImExporter;
import org.libreccm.imexport.Exportable;
import org.libreccm.imexport.Processes; import org.libreccm.imexport.Processes;
import java.util.Collections;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Optional;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
@ -58,11 +56,124 @@ public class FileImExporter extends AbstractEntityImExporter<File> {
} }
@Override @Override
@Transactional(Transactional.TxType.REQUIRED) protected Optional<File> findExistingEntity(final String uuid) {
return fileRepository.findByUuid(uuid);
}
@Override
protected void saveImportedEntity(final File portableObject) { protected void saveImportedEntity(final File portableObject) {
fileRepository.save(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 @Override
protected File reloadEntity(final File entity) { protected File reloadEntity(final File entity) {
return fileRepository return fileRepository

View File

@ -18,7 +18,10 @@
*/ */
package org.libreccm.docrepo; package org.libreccm.docrepo;
import java.util.Optional;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
/** /**
@ -44,6 +47,19 @@ public class FileRepository extends AbstractResourceRepository<File> {
return entity.getObjectId(); 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 @Override
public TypedQuery<File> getFindByNameQuery() { public TypedQuery<File> getFindByNameQuery() {
return entityManager.createNamedQuery( return entityManager.createNamedQuery(

View File

@ -28,7 +28,8 @@ import java.util.List;
/** /**
* Entity class of a folder in the doc-repository. Instances will be persisted * 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> * @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
* @version 01/10/2015 * @version 01/10/2015
@ -36,18 +37,29 @@ import java.util.List;
@Entity(name = "DocRepoFolder") @Entity(name = "DocRepoFolder")
@Table(schema = "CCM_DOCREPO", name = "FOLDERS") @Table(schema = "CCM_DOCREPO", name = "FOLDERS")
@NamedQueries({ @NamedQueries({
@NamedQuery(name = "DocRepo.findFolderByName", @NamedQuery(
query = "SELECT r FROM DocRepoFolder r WHERE " + name = "DocRepo.findFolderByUuid",
"r.name = :name"), query = "SELECT r FROM DocRepoFolder r WHERE r.uuid = :uuid"
@NamedQuery(name = "DocRepo.findFolderByPath", ),
query = "SELECT r FROM DocRepoFolder r WHERE " + @NamedQuery(
"r.path = :pathName"), name = "DocRepo.findFolderByName",
@NamedQuery(name = "DocRepo.findCreatedFolderFromUser", query = "SELECT r FROM DocRepoFolder r WHERE " + "r.name = :name"
query = "SELECT r FROM DocRepoFolder r WHERE " + ),
"r.creationUser = :user"), @NamedQuery(
@NamedQuery(name = "DocRepo.findModifiedFolderFromUser", name = "DocRepo.findFolderByPath",
query = "SELECT r FROM DocRepoFolder r WHERE " + query = "SELECT r FROM DocRepoFolder r WHERE " + "r.path = :pathName"
"r.lastModifiedUser = :user") ),
@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 { public class Folder extends AbstractResource {
@ -66,14 +78,14 @@ public class Folder extends AbstractResource {
private Repository rootAssignedRepository; private Repository rootAssignedRepository;
/** /**
* Constructor calls the super-class-constructor of {@link AbstractResource}. * Constructor calls the super-class-constructor of
* {@link AbstractResource}.
*/ */
public Folder() { public Folder() {
super(); super();
} }
//> Begin GETTER & SETTER //> Begin GETTER & SETTER
public List<AbstractResource> getImmediateChildren() { public List<AbstractResource> getImmediateChildren() {
return immediateChildren; return immediateChildren;
} }
@ -90,6 +102,5 @@ public class Folder extends AbstractResource {
this.rootAssignedRepository = rootAssignedRepository; this.rootAssignedRepository = rootAssignedRepository;
} }
//< End GETTER & SETTER //< End GETTER & SETTER
} }

View File

@ -21,11 +21,11 @@ package org.libreccm.docrepo;
import org.libreccm.imexport.Processes; import org.libreccm.imexport.Processes;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.transaction.Transactional;
/** /**
* Im/Exporter for importing and exporting {@link Folder}s from the system into * 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() { public Class<Folder> getEntityClass() {
return Folder.class; return Folder.class;
} }
@Override
protected Optional<Folder> findExistingEntity(final String uuid) {
return folderRepository.findByUuid(uuid);
}
@Override @Override
@Transactional(Transactional.TxType.REQUIRED)
protected void saveImportedEntity(final Folder entity) { protected void saveImportedEntity(final Folder entity) {
folderRepository.save(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 @Override
protected Folder reloadEntity(final Folder entity) { protected Folder reloadEntity(final Folder entity) {

View File

@ -18,7 +18,10 @@
*/ */
package org.libreccm.docrepo; package org.libreccm.docrepo;
import java.util.Optional;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
/** /**
@ -28,6 +31,7 @@ import javax.persistence.TypedQuery;
* @version 27.01.2016 * @version 27.01.2016
*/ */
@RequestScoped @RequestScoped
@SuppressWarnings("serial")
public class FolderRepository extends AbstractResourceRepository<Folder> { public class FolderRepository extends AbstractResourceRepository<Folder> {
public FolderRepository() { public FolderRepository() {
@ -38,12 +42,25 @@ public class FolderRepository extends AbstractResourceRepository<Folder> {
public String getIdAttributeName() { public String getIdAttributeName() {
return "objectId"; return "objectId";
} }
@Override @Override
public Long getIdOfEntity(final Folder entity) { public Long getIdOfEntity(final Folder entity) {
return entity.getObjectId(); 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 @Override
public TypedQuery<Folder> getFindByNameQuery() { public TypedQuery<Folder> getFindByNameQuery() {
return entityManager.createNamedQuery( return entityManager.createNamedQuery(

View File

@ -18,7 +18,6 @@
*/ */
package org.libreccm.docrepo; package org.libreccm.docrepo;
import org.hibernate.validator.constraints.NotBlank;
import org.libreccm.imexport.Exportable; import org.libreccm.imexport.Exportable;
import org.libreccm.security.User; import org.libreccm.security.User;
import org.libreccm.web.CcmApplication; import org.libreccm.web.CcmApplication;
@ -34,6 +33,8 @@ import javax.persistence.Table;
import java.util.List; import java.util.List;
import javax.validation.constraints.NotBlank;
/** /**
* Entity class of a repository for documents. Instances will be persisted into * Entity class of a repository for documents. Instances will be persisted into
* the database. Instance variables are inherited from {@link CcmApplication}. * the database. Instance variables are inherited from {@link CcmApplication}.
@ -44,8 +45,14 @@ import java.util.List;
@Entity @Entity
@Table(schema = "CCM_DOCREPO", name = "REPOSITORIES") @Table(schema = "CCM_DOCREPO", name = "REPOSITORIES")
@NamedQueries({ @NamedQueries({
@NamedQuery(name = "DocRepo.findRepositoriesForOwner", @NamedQuery(
query = "SELECT r FROM Repository r WHERE r.owner = :owner") 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 { public class Repository extends CcmApplication implements Exportable {
@ -80,7 +87,6 @@ public class Repository extends CcmApplication implements Exportable {
@OneToMany(mappedBy = "repository") @OneToMany(mappedBy = "repository")
private List<AbstractResource> abstractResources; private List<AbstractResource> abstractResources;
/** /**
* Constructor calls the super-class-constructor of {@link CcmApplication}. * Constructor calls the super-class-constructor of {@link CcmApplication}.
*/ */
@ -89,7 +95,6 @@ public class Repository extends CcmApplication implements Exportable {
} }
//> Begin GETTER & SETTER //> Begin GETTER & SETTER
public String getName() { public String getName() {
return name; return name;
} }
@ -123,6 +128,4 @@ public class Repository extends CcmApplication implements Exportable {
} }
//< End GETTER & SETTER //< End GETTER & SETTER
} }

View File

@ -22,6 +22,7 @@ import org.libreccm.imexport.AbstractEntityImExporter;
import org.libreccm.imexport.Processes; import org.libreccm.imexport.Processes;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
@ -48,11 +49,90 @@ public class RepositoryImExporter extends AbstractEntityImExporter<Repository> {
public Class<Repository> getEntityClass() { public Class<Repository> getEntityClass() {
return Repository.class; return Repository.class;
} }
@Override
protected Optional<Repository> findExistingEntity(final String uuid) {
return repositoryRepository.findByUuid(uuid);
}
@Override @Override
protected void saveImportedEntity(final Repository portableObject) { protected void saveImportedEntity(final Repository portableObject) {
repositoryRepository.save(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 @Override
protected Repository reloadEntity(final Repository entity) { protected Repository reloadEntity(final Repository entity) {

View File

@ -27,9 +27,13 @@ import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.persistence.NoResultException;
/** /**
* Repository class for retrieving, storing and deleting {@code Repository}s. * Repository class for retrieving, storing and deleting {@code Repository}s.
* *
@ -39,6 +43,8 @@ import java.util.stream.Collectors;
public class RepositoryRepository public class RepositoryRepository
extends AbstractAuditedEntityRepository<Long, Repository> { extends AbstractAuditedEntityRepository<Long, Repository> {
private static final long serialVersionUID = 1L;
@Inject @Inject
private EntityManager entityManager; private EntityManager entityManager;
@ -70,6 +76,22 @@ public class RepositoryRepository
return entity.getObjectId() == 0; 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 * Checks if the current subject has permissions grating him the privilege
* to read the requested {@link Repository}(s) and removes the ones he is * to read the requested {@link Repository}(s) and removes the ones he is