Skip to content
Snippets Groups Projects

refactor[AOU-1855]: remove licence info

@@ -95,6 +95,7 @@ import ch.unige.aou.model.publication.PublicationStructure;
import ch.unige.aou.model.publication.PublicationSubSubtype;
import ch.unige.aou.model.publication.PublicationSubtype;
import ch.unige.aou.model.publication.PublicationUserRole;
import ch.unige.aou.model.publication.DocumentFile.AccessLevel;
import ch.unige.aou.model.rest.PersonDTO;
import ch.unige.aou.model.rest.PublicationImportDTO;
import ch.unige.aou.model.security.User;
@@ -147,11 +148,14 @@ public class PublicationService extends AouResourceService<Publication> {
private final boolean generateAgreement;
public PublicationService(AouProperties aouProperties, PublicationSubtypeService publicationSubtypeService,
PublicationSubSubtypeService publicationSubSubtypeService, PersonService personService, MetadataService metadataService,
@Lazy EventService eventService, StructureService structureService, LabeledLanguageService labeledLanguageService,
ContributorService contributorService, @Lazy DocumentFileService documentFileService, ResearchGroupService researchGroupService,
@Lazy MetadataImportWorkFlowService metadataImportFlowService, PdfDocumentCreator pdfDocumentCreator, HistoryService historyService,
UserService userService, IndexClientService indexService) {
PublicationSubSubtypeService publicationSubSubtypeService, PersonService personService,
MetadataService metadataService,
@Lazy EventService eventService, StructureService structureService, LabeledLanguageService labeledLanguageService,
ContributorService contributorService, @Lazy DocumentFileService documentFileService,
ResearchGroupService researchGroupService,
@Lazy MetadataImportWorkFlowService metadataImportFlowService, PdfDocumentCreator pdfDocumentCreator,
HistoryService historyService,
UserService userService, IndexClientService indexService) {
this.publicationSubtypeService = publicationSubtypeService;
this.publicationSubSubtypeService = publicationSubSubtypeService;
this.personService = personService;
@@ -195,16 +199,20 @@ public class PublicationService extends AouResourceService<Publication> {
return ((PublicationRepository) this.itemRepository).findByArchiveId(archiveId);
}
public Page<Publication> findMyPublications(Publication filterItem, String personId, String cnIndividu, Pageable pageable, String fullName) {
// Use a specification specifically made to find the publications that has the same creator OR the same cnIndividu
PublicationContributorOrCreatorSpecification specification = new PublicationContributorOrCreatorSpecification(filterItem, personId,
cnIndividu);
public Page<Publication> findMyPublications(Publication filterItem, String personId, String cnIndividu,
Pageable pageable, String fullName) {
// Use a specification specifically made to find the publications that has the
// same creator OR the same cnIndividu
PublicationContributorOrCreatorSpecification specification = new PublicationContributorOrCreatorSpecification(
filterItem, personId,
cnIndividu);
specification.setFullName(fullName);
return this.findAll(specification, pageable);
}
/**
* Returns a list of publications to which the person is a contributor and which have been modified after the given date.
* Returns a list of publications to which the person is a contributor and which
* have been modified after the given date.
*
* @param person
* @param lastUpdatedAfter
@@ -215,8 +223,9 @@ public class PublicationService extends AouResourceService<Publication> {
for (User user : person.getUsers()) {
Publication filterItem = new Publication();
filterItem.setStatus(PublicationStatus.COMPLETED);
PublicationContributorOrCreatorSpecification specification = new PublicationContributorOrCreatorSpecification(filterItem, null,
StringTool.substringBefore(user.getExternalUid(), "@"));
PublicationContributorOrCreatorSpecification specification = new PublicationContributorOrCreatorSpecification(
filterItem, null,
StringTool.substringBefore(user.getExternalUid(), "@"));
specification.setLastUpdatedAfter(lastUpdatedAfter);
Page<Publication> publicationsPage = this.findAll(specification, Pageable.unpaged());
publications.addAll(publicationsPage.getContent());
@@ -224,18 +233,23 @@ public class PublicationService extends AouResourceService<Publication> {
return publications;
}
public Page<Publication> findValidablePublications(String personId, Publication filterItem, Pageable pageable, String fullName) {
public Page<Publication> findValidablePublications(String personId, Publication filterItem, Pageable pageable,
String fullName) {
Map<String, List<String>> structuresPublicationsTypesMap = this.personService.getValidablePublicationSubtypesByStructure(personId);
Map<String, List<String>> structuresPublicationsTypesMap = this.personService
.getValidablePublicationSubtypesByStructure(personId);
// Use a specification specifically made to find the publications that can be validated
ValidablePublicationSpecification specification = new ValidablePublicationSpecification(filterItem, structuresPublicationsTypesMap);
// Use a specification specifically made to find the publications that can be
// validated
ValidablePublicationSpecification specification = new ValidablePublicationSpecification(filterItem,
structuresPublicationsTypesMap);
specification.setFullName(fullName);
return this.findAll(specification, pageable);
}
public Page<Publication> findPublicationByStatusAndLastUpdate(Publication.PublicationStatus status, OffsetDateTime lastUpdatedBefore,
Pageable pageable) {
public Page<Publication> findPublicationByStatusAndLastUpdate(Publication.PublicationStatus status,
OffsetDateTime lastUpdatedBefore,
Pageable pageable) {
Publication filterItem = new Publication();
filterItem.setStatus(status);
PublicationSpecification specification = this.getSpecification(filterItem);
@@ -288,9 +302,12 @@ public class PublicationService extends AouResourceService<Publication> {
}
/**
* Check if a publication status can be manually updated to the new given status, according to the
* publications's management workflow. Some status transitions (e.g. from SUBMITTED to CANONICAL and from
* CANONICAL to COMPLETED) are considered here as invalid, because even if they exist in the workflow,
* Check if a publication status can be manually updated to the new given
* status, according to the
* publications's management workflow. Some status transitions (e.g. from
* SUBMITTED to CANONICAL and from
* CANONICAL to COMPLETED) are considered here as invalid, because even if they
* exist in the workflow,
* they are automatically done, and should not be forced manually.
*
* @param publication The publication to check
@@ -307,28 +324,28 @@ public class PublicationService extends AouResourceService<Publication> {
case IN_VALIDATION:
return newStatus == PublicationStatus.IN_PROGRESS || newStatus == PublicationStatus.SUBMITTED
|| newStatus == PublicationStatus.REJECTED || newStatus == PublicationStatus.FEEDBACK_REQUIRED;
|| newStatus == PublicationStatus.REJECTED || newStatus == PublicationStatus.FEEDBACK_REQUIRED;
case IN_ERROR:
case REJECTED:
case COMPLETED:
return newStatus == PublicationStatus.IN_PROGRESS || newStatus == PublicationStatus.DELETED
|| newStatus == PublicationStatus.CANONICAL || newStatus == PublicationStatus.IN_EDITION;
|| newStatus == PublicationStatus.CANONICAL || newStatus == PublicationStatus.IN_EDITION;
case FEEDBACK_REQUIRED:
return newStatus == PublicationStatus.IN_PROGRESS || newStatus == PublicationStatus.IN_VALIDATION
|| newStatus == PublicationStatus.IN_EDITION || newStatus == PublicationStatus.UPDATES_VALIDATION;
|| newStatus == PublicationStatus.IN_EDITION || newStatus == PublicationStatus.UPDATES_VALIDATION;
case CANONICAL:
return newStatus == PublicationStatus.COMPLETED;
case IN_EDITION:
return newStatus == PublicationStatus.COMPLETED || newStatus == PublicationStatus.UPDATES_VALIDATION
|| newStatus == PublicationStatus.CANCEL_EDITION;
|| newStatus == PublicationStatus.CANCEL_EDITION;
case UPDATES_VALIDATION:
return newStatus == PublicationStatus.SUBMITTED || newStatus == PublicationStatus.FEEDBACK_REQUIRED
|| newStatus == PublicationStatus.CANCEL_EDITION;
|| newStatus == PublicationStatus.CANCEL_EDITION;
case SUBMITTED:
default:
return false;
@@ -336,7 +353,8 @@ public class PublicationService extends AouResourceService<Publication> {
}
/**
* When reediting a publication, we need to back up the property metadata to metadata_backup
* When reediting a publication, we need to back up the property metadata to
* metadata_backup
*
* @param publication
* @param newStatus
@@ -357,10 +375,12 @@ public class PublicationService extends AouResourceService<Publication> {
AouMetadataVersion currentVersion = publication.getMetadataVersion();
if (this.upgradeMetadataIfFormatIsPreviousVersion(publication)) {
// (re)generate Json form data from XML metadata to ensure they are synchronized
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(AouMetadataVersion.getDefaultVersion());
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(AouMetadataVersion.getDefaultVersion());
metadataExtractor.setFormDataFromMetadata(publication);
log.info("Publication '{}' is returned with an upgraded version of its metadata (from version {} to {})", publication.getResId(),
currentVersion, publication.getMetadataVersion());
log.info("Publication '{}' is returned with an upgraded version of its metadata (from version {} to {})",
publication.getResId(),
currentVersion, publication.getMetadataVersion());
}
this.setChangeInfoFullName(publication);
@@ -373,7 +393,7 @@ public class PublicationService extends AouResourceService<Publication> {
// Set email for publication editor
if (publication.getLastUpdate() != null && !StringTool.isNullOrEmpty(publication.getLastUpdate().getWho())
&& this.userService.existsByExternalUid(publication.getLastUpdate().getWho())) {
&& this.userService.existsByExternalUid(publication.getLastUpdate().getWho())) {
User editor = this.userService.findByExternalUid(publication.getLastUpdate().getWho());
publication.setLastEditor(new PersonDTO(editor.getFirstName(), editor.getLastName(), editor.getEmail()));
}
@@ -384,13 +404,14 @@ public class PublicationService extends AouResourceService<Publication> {
@Override
protected void beforeValidate(Publication publication) {
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(AouMetadataVersion.getDefaultVersion());
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(AouMetadataVersion.getDefaultVersion());
/*
* (Re)generate:
* Json form data from XML metadata if they have been updated
* or
* XML metadata from Json form data if they have been updated
* Json form data from XML metadata if they have been updated
* or
* XML metadata from Json form data if they have been updated
*/
boolean xmlMetadataUpdated = publication.isMetadataDirty() && !StringTool.isNullOrEmpty(publication.getMetadata());
boolean jsonMetadataUpdated = publication.isFormDataDirty() && !StringTool.isNullOrEmpty(publication.getFormData());
@@ -401,8 +422,9 @@ public class PublicationService extends AouResourceService<Publication> {
// metadata are saved as XML
AouMetadataVersion currentVersion = publication.getMetadataVersion();
if (this.upgradeMetadataIfFormatIsPreviousVersion(publication)) {
log.info("Publication '{}' will be stored with an upgraded version of its metadata (from version {} to {})", publication.getResId(),
currentVersion, publication.getMetadataVersion());
log.info("Publication '{}' will be stored with an upgraded version of its metadata (from version {} to {})",
publication.getResId(),
currentVersion, publication.getMetadataVersion());
}
} else {
// metadata are saved as Json --> generate XML metadata
@@ -425,7 +447,8 @@ public class PublicationService extends AouResourceService<Publication> {
metadataExtractor.setFormDataFromMetadata(publication);
} else if (publication.getMetadataValidationType() == null) {
// if metadata hasn't been updated and the validation type is null, do not validate anything
// if metadata hasn't been updated and the validation type is null, do not
// validate anything
publication.setMetadataValidationType(Publication.MetadataValidationType.NONE);
}
@@ -442,19 +465,28 @@ public class PublicationService extends AouResourceService<Publication> {
metadataExtractor.setFormDataFromMetadata(publication);
}
// Set publications properties that are in metadata and must be saved in database
// Set publications properties that are in metadata and must be saved in
// database
if (!StringTool.isNullOrEmpty(publication.getMetadata())) {
metadataExtractor.setPropertiesFromMetadata(publication);
}
if (publication.getSubtype() != null && publication.getSubtype().getResId() != null
&& ((publication.getSubtype().getResId().equals(AouConstants.DEPOSIT_SUBTYPE_THESE_ID)
&& ((publication.getSubtype().getResId().equals(AouConstants.DEPOSIT_SUBTYPE_THESE_ID)
|| publication.getSubtype().getResId().equals(AouConstants.DEPOSIT_SUBTYPE_THESE_DOCTORAL_PROFESSIONAL_ID))
&& !this.metadataService.isBefore2010orBeforeAuthorJoiningUnige(publication))
&& (!this.historyService.hasBeenUpdatingMetadata(publication.getResId())
&& (!this.historyService.hasBeenUpdatingMetadata(publication.getResId())
&& !publication.getStatus().equals(PublicationStatus.IN_EDITION))) {
this.generateThesisAgreement(publication);
}
if (!publication.getDocumentFiles().isEmpty()) {
publication.getDocumentFiles().stream().forEach(d -> {
if (d.getAccessLevel().equals(AccessLevel.RESTRICTED) || d.getAccessLevel().equals(AccessLevel.PRIVATE)) {
d.setLicense(null); // set license to null if the access level is private or restricted
}
});
}
}
@Override
@@ -468,11 +500,13 @@ public class PublicationService extends AouResourceService<Publication> {
/*
* Validate metadata content
*/
final MetadataValidator metadataValidator = this.metadataService.getMetadataValidator(publication.getMetadataVersion());
final MetadataValidator metadataValidator = this.metadataService
.getMetadataValidator(publication.getMetadataVersion());
metadataValidator.validate(publication, errors);
if (!hasErrorBefore && errors.hasErrors()) {
// throw a custom Exception to be caught specifically in order to not log full stacktrace
// throw a custom Exception to be caught specifically in order to not log full
// stacktrace
throw new AouMetadataValidationException(new ValidationError(errors));
}
}
@@ -484,10 +518,12 @@ public class PublicationService extends AouResourceService<Publication> {
/*
* Set publications relations that are in metadata and must be saved in database
* The method is called after the validation step as it may create new Contributors which are thus validated first.
* The method is called after the validation step as it may create new
* Contributors which are thus validated first.
*/
if (!StringTool.isNullOrEmpty(publication.getMetadata())) {
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(publication.getMetadataVersion());
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(publication.getMetadataVersion());
metadataExtractor.setRelationsFromMetadata(publication);
}
@@ -522,8 +558,10 @@ public class PublicationService extends AouResourceService<Publication> {
@Override
public Publication save(Publication publication) {
// list contributors before the publication is saved to check after saving if some of them are now orphan and can be deleted
List<String> currentContributorsIds = publication.getContributors().stream().map(Contributor::getResId).collect(Collectors.toList());
// list contributors before the publication is saved to check after saving if
// some of them are now orphan and can be deleted
List<String> currentContributorsIds = publication.getContributors().stream().map(Contributor::getResId)
.collect(Collectors.toList());
final Publication result = super.save(publication);
@@ -556,7 +594,8 @@ public class PublicationService extends AouResourceService<Publication> {
}
/**
* Save a publication by calling the repository save() method only (methods beforeValidate(), validate() and beforeSave() are not called)
* Save a publication by calling the repository save() method only (methods
* beforeValidate(), validate() and beforeSave() are not called)
*
* @param publication
* @return
@@ -568,14 +607,17 @@ public class PublicationService extends AouResourceService<Publication> {
@Override
public void delete(String publicationId) {
// list contributors before the publication is deleted to check after deletion if some of them are now orphan and can be deleted
// list contributors before the publication is deleted to check after deletion
// if some of them are now orphan and can be deleted
List<String> currentContributorsIds = new ArrayList<>();
Publication publication = this.findOne(publicationId);
if (publication != null) {
currentContributorsIds = publication.getContributors().stream().map(Contributor::getResId).collect(Collectors.toList());
currentContributorsIds = publication.getContributors().stream().map(Contributor::getResId)
.collect(Collectors.toList());
}
// get the publication files path before deleting the publication to be able to delete its files from disk after the deletion
// get the publication files path before deleting the publication to be able to
// delete its files from disk after the deletion
final Path publicationFilesFolderPath = this.getPublicationFilesFolderPath(publicationId);
super.delete(publicationId);
@@ -599,7 +641,8 @@ public class PublicationService extends AouResourceService<Publication> {
Publication publicationCopy = new Publication(originalPublication);
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(publicationCopy.getMetadataVersion());
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(publicationCopy.getMetadataVersion());
// clean metadata values from identifiers
metadataExtractor.cleanMetadataToClone(publicationCopy);
@@ -621,7 +664,8 @@ public class PublicationService extends AouResourceService<Publication> {
this.validateSubSubtype(publication, errors);
this.validateFiles(publication, errors);
final MetadataValidator metadataValidator = this.metadataService.getMetadataValidator(publication.getMetadataVersion());
final MetadataValidator metadataValidator = this.metadataService
.getMetadataValidator(publication.getMetadataVersion());
metadataValidator.validate(publication, errors);
if (errors.hasErrors()) {
@@ -638,11 +682,13 @@ public class PublicationService extends AouResourceService<Publication> {
private void validateSubSubtype(Publication publication, BindingResult errors) {
if (publication.getSubSubtype() != null && publication.getSubSubtype().getResId() != null) {
List<PublicationSubSubtype> subtypesPossibles = this.publicationSubSubtypeService
.findByPublicationSubtypes(publication.getSubtype().getResId());
if (subtypesPossibles.stream().noneMatch(psst -> psst.getResId().equals(publication.getSubSubtype().getResId()))) {
.findByPublicationSubtypes(publication.getSubtype().getResId());
if (subtypesPossibles.stream()
.noneMatch(psst -> psst.getResId().equals(publication.getSubSubtype().getResId()))) {
errors.addError(
new FieldError(publication.getClass().getSimpleName(), "subSubtype", this.messageService.get(SUB_SUBTYPE_NOT_PERMITTED,
new Object[] { publication.getSubSubtype().getResId(), publication.getSubtype().getResId() })));
new FieldError(publication.getClass().getSimpleName(), "subSubtype",
this.messageService.get(SUB_SUBTYPE_NOT_PERMITTED,
new Object[] { publication.getSubSubtype().getResId(), publication.getSubtype().getResId() })));
}
}
}
@@ -651,17 +697,20 @@ public class PublicationService extends AouResourceService<Publication> {
if (publication.getMetadataValidationType() != null) {
if (publication.getMetadataValidationType().equals(Publication.MetadataValidationType.GLOBAL) ||
publication.getMetadataValidationType().equals(Publication.MetadataValidationType.GLOBAL_WITH_RULES_FOR_FINAL_VALIDATION) ||
(publication.getMetadataValidationType().equals(Publication.MetadataValidationType.CURRENT_STEP)
&& publication.getFormStep().equals(Publication.DepositFormStep.FILES))
) {
publication.getMetadataValidationType()
.equals(Publication.MetadataValidationType.GLOBAL_WITH_RULES_FOR_FINAL_VALIDATION)
||
(publication.getMetadataValidationType().equals(Publication.MetadataValidationType.CURRENT_STEP)
&& publication.getFormStep().equals(Publication.DepositFormStep.FILES))) {
for (int i = 0; i < publication.getDocumentFiles().size(); i++) {
if (publication.getDocumentFiles().get(i).getStatus().equals(DocumentFile.DocumentFileStatus.IN_ERROR)) {
errors.addError(new FieldError(publication.getClass().getSimpleName(), "documentFiles", this.messageService.get(FILES_IN_ERROR)));
errors.addError(new FieldError(publication.getClass().getSimpleName(), "documentFiles",
this.messageService.get(FILES_IN_ERROR)));
}
if (publication.getDocumentFiles().get(i).getStatus().equals(DocumentFile.DocumentFileStatus.IMPOSSIBLE_TO_DOWNLOAD)) {
if (publication.getDocumentFiles().get(i).getStatus()
.equals(DocumentFile.DocumentFileStatus.IMPOSSIBLE_TO_DOWNLOAD)) {
errors.addError(new FieldError(publication.getClass().getSimpleName(), "documentFiles",
this.messageService.get(FILES_IMPOSSIBLE_TO_DOWNLOADABLE)));
this.messageService.get(FILES_IMPOSSIBLE_TO_DOWNLOADABLE)));
}
}
@@ -674,18 +723,21 @@ public class PublicationService extends AouResourceService<Publication> {
private void validateDuplicatedFiles(Publication publication, BindingResult errors) {
if (this.hasDuplicateFiles(publication)) {
errors.addError(new FieldError(publication.getClass().getSimpleName(), "documentFiles", this.messageService.get(DUPLICATES_FILES)));
errors.addError(new FieldError(publication.getClass().getSimpleName(), "documentFiles",
this.messageService.get(DUPLICATES_FILES)));
}
}
/******************************************************************************************************/
public String convertDefaultProfileDataToJson(Person person) {
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(AouMetadataVersion.getDefaultVersion());
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(AouMetadataVersion.getDefaultVersion());
JSONObject jsonObject = new JSONObject();
if (!person.getStructures().isEmpty()) {
JSONArray structuresToJson = metadataExtractor.transformAcademicStructuresToJson(new ArrayList<>(person.getStructures()));
JSONArray structuresToJson = metadataExtractor
.transformAcademicStructuresToJson(new ArrayList<>(person.getStructures()));
jsonObject.put("academicStructures", structuresToJson);
}
@@ -714,15 +766,17 @@ public class PublicationService extends AouResourceService<Publication> {
} catch (final IOException e) {
log.error("Problem creating publication directory", e);
throw new SolidifyProcessingException(
this.messageService
.get("publication.error.path_not_found", new Object[] { publication.getResId(), this.publicationsFolder }));
this.messageService
.get("publication.error.path_not_found",
new Object[] { publication.getResId(), this.publicationsFolder }));
}
}
return publicationFilesFolderPath;
}
/**
* Create relations of type VALIDATION between the given publication id and all the given structure ids
* Create relations of type VALIDATION between the given publication id and all
* the given structure ids
*
* @param publicationId
* @param structureIds
@@ -731,8 +785,9 @@ public class PublicationService extends AouResourceService<Publication> {
final Publication publication = this.findOne(publicationId);
List<PublicationStructure> existingValidationStructures = publication.getPublicationStructures().stream()
.filter(pubStruct -> pubStruct.getLinkType().equals(
PublicationStructure.LinkType.VALIDATION)).collect(Collectors.toList());
.filter(pubStruct -> pubStruct.getLinkType().equals(
PublicationStructure.LinkType.VALIDATION))
.collect(Collectors.toList());
// remove validation structures not it given structure ids
List<PublicationStructure> publicationStructuresToRemove = new ArrayList<>();
@@ -745,7 +800,8 @@ public class PublicationService extends AouResourceService<Publication> {
// add relations to validation structure that do not exist yet
for (String structureId : structureIds) {
if (existingValidationStructures.stream().noneMatch(pubStruct -> structureId.equals(pubStruct.getStructure().getResId()))) {
if (existingValidationStructures.stream()
.noneMatch(pubStruct -> structureId.equals(pubStruct.getStructure().getResId()))) {
final Structure structure = this.structureService.findOne(structureId);
PublicationStructure publicationStructure = new PublicationStructure();
publicationStructure.setStructure(structure);
@@ -808,8 +864,9 @@ public class PublicationService extends AouResourceService<Publication> {
Optional<String> cnIndividuOpt = this.personService.getAuthenticatedUserUnigeCnIndividu();
SolidifySpecification<Publication> specification = new PublicationContributorOrCreatorSpecification(criteria, personId,
cnIndividuOpt.orElse(null));
SolidifySpecification<Publication> specification = new PublicationContributorOrCreatorSpecification(criteria,
personId,
cnIndividuOpt.orElse(null));
specification.setFilterOnRootResId(true);
final Pageable pageable = PageRequest.of(0, RestCollectionPage.DEFAULT_SIZE_PAGE);
return !this.findAll(specification, pageable).isEmpty();
@@ -825,10 +882,12 @@ public class PublicationService extends AouResourceService<Publication> {
public List<PublicationUserRole> listPublicationUserRoles(String publicationId) {
Publication publication = this.findOne(publicationId);
String authenticatedPersonId = this.personService.getLinkedPersonId(SecurityContextHolder.getContext().getAuthentication());
String authenticatedPersonId = this.personService
.getLinkedPersonId(SecurityContextHolder.getContext().getAuthentication());
List<PublicationUserRole> publicationUsersRoles = new ArrayList<>();
if (this.authenticatedUserHasPriviledgedRole() || this.personService.isAllowedToValidate(authenticatedPersonId, publication)) {
if (this.authenticatedUserHasPriviledgedRole()
|| this.personService.isAllowedToValidate(authenticatedPersonId, publication)) {
publicationUsersRoles.add(PublicationUserRole.VALIDATOR);
}
@@ -845,13 +904,15 @@ public class PublicationService extends AouResourceService<Publication> {
public boolean isCnIndividuInContributorsMetadata(String publicationId, String cnIndividu) {
final Publication publication = this.findOne(publicationId);
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(publication.getMetadataVersion());
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(publication.getMetadataVersion());
return metadataExtractor.isCnIndividuInContributors(publication, cnIndividu);
}
public Publication unlinkContributor(String publicationId, String cnIndividu) {
final Publication publication = this.findOne(publicationId);
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(publication.getMetadataVersion());
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(publication.getMetadataVersion());
metadataExtractor.removeCnIndividuFromContributors(publication, cnIndividu);
publication.setMetadataValidationType(Publication.MetadataValidationType.NONE);
return this.save(publication);
@@ -867,7 +928,8 @@ public class PublicationService extends AouResourceService<Publication> {
if (publication == null) {
return false;
}
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(publication.getMetadataVersion());
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(publication.getMetadataVersion());
metadataExtractor.addResearchGroup(researchGroup, publication);
publication.setMetadataValidationType(Publication.MetadataValidationType.NONE);
this.save(publication);
@@ -881,7 +943,7 @@ public class PublicationService extends AouResourceService<Publication> {
* @param publication
*/
private boolean upgradeMetadataIfFormatIsPreviousVersion(Publication publication) {
//First check metadata format version in XML
// First check metadata format version in XML
AouMetadataVersion version = this.metadataService.detectVersionFromXmlMetadata(publication.getMetadata());
if (version != AouMetadataVersion.getDefaultVersion()) {
// metadata are in an obsolete metadata format --> upgrade to the current format
@@ -894,11 +956,13 @@ public class PublicationService extends AouResourceService<Publication> {
}
/**
* Get the list of all Publications whose metadata version is not the current one and send a JMS message
* Get the list of all Publications whose metadata version is not the current
* one and send a JMS message
* to upgrade them asynchronously.
*/
public int startUpgradingAllPublicationsMetadataVersion() {
List<Publication> publicationsToUpgrade = ((PublicationRepository) this.itemRepository).findPublicationByMetadataVersionIsNot(
List<Publication> publicationsToUpgrade = ((PublicationRepository) this.itemRepository)
.findPublicationByMetadataVersionIsNot(
AouMetadataVersion.getDefaultVersion());
log.info("{} publications will have their metadata version upgraded", publicationsToUpgrade.size());
for (Publication publication : publicationsToUpgrade) {
@@ -912,10 +976,12 @@ public class PublicationService extends AouResourceService<Publication> {
if (publication.getDocumentFiles().size() > 1) {
for (int i = 0; i < publication.getDocumentFiles().size(); i++) {
if (!publication.getDocumentFiles().get(i).getStatus().equals(DocumentFile.DocumentFileStatus.IN_ERROR) &&
!publication.getDocumentFiles().get(i).getStatus().equals(DocumentFile.DocumentFileStatus.IMPOSSIBLE_TO_DOWNLOAD)) {
!publication.getDocumentFiles().get(i).getStatus()
.equals(DocumentFile.DocumentFileStatus.IMPOSSIBLE_TO_DOWNLOAD)) {
String checksumToVerify = publication.getDocumentFiles().get(i).getChecksum();
for (int j = i + 1; j < publication.getDocumentFiles().size(); j++) {
if (!StringTool.isNullOrEmpty(checksumToVerify) && checksumToVerify.equals(publication.getDocumentFiles().get(j).getChecksum())) {
if (!StringTool.isNullOrEmpty(checksumToVerify)
&& checksumToVerify.equals(publication.getDocumentFiles().get(j).getChecksum())) {
publication.getDocumentFiles().get(i).setStatus(DocumentFile.DocumentFileStatus.DUPLICATE);
publication.getDocumentFiles().get(j).setStatus(DocumentFile.DocumentFileStatus.DUPLICATE);
this.documentFileService.save(publication.getDocumentFiles().get(i));
@@ -936,7 +1002,8 @@ public class PublicationService extends AouResourceService<Publication> {
Publication publication = this.findOne(publicationId);
// Add structure
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(publication.getMetadataVersion());
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(publication.getMetadataVersion());
metadataExtractor.addStructure(structure, publication);
// Then check if some structure must be removed from hierarchy
@@ -966,7 +1033,8 @@ public class PublicationService extends AouResourceService<Publication> {
if (publication == null) {
return false;
}
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(publication.getMetadataVersion());
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(publication.getMetadataVersion());
metadataExtractor.addLanguage(labeledLanguage, publication);
publication.setMetadataValidationType(Publication.MetadataValidationType.NONE);
this.save(publication);
@@ -974,7 +1042,8 @@ public class PublicationService extends AouResourceService<Publication> {
return true;
}
public boolean linkPublicationsWithContributorOtherName(String[] publicationIds, String cnIndividu, String lastname, String firstname) {
public boolean linkPublicationsWithContributorOtherName(String[] publicationIds, String cnIndividu, String lastname,
String firstname) {
Contributor contributor = this.contributorService.findByCnIndividu(cnIndividu);
if (contributor == null) {
throw new NoSuchElementException("No contributor with cnIndividu " + cnIndividu);
@@ -982,7 +1051,8 @@ public class PublicationService extends AouResourceService<Publication> {
ContributorOtherName otherNameToLink = null;
if (!contributor.getLastName().equals(lastname) || !Objects.equals(contributor.getFirstName(), firstname)) {
// Name is different from the main contributor name --> a ContributorOtherName must be linked to Publication
// Name is different from the main contributor name --> a ContributorOtherName
// must be linked to Publication
// Check if contributor has already an identical other name
for (ContributorOtherName otherName : contributor.getOtherNames()) {
if (otherName.getLastName().equals(lastname) && Objects.equals(otherName.getFirstName(), firstname)) {
@@ -1008,17 +1078,20 @@ public class PublicationService extends AouResourceService<Publication> {
// First discard eventual existing relation between publication and contributor
List<ContributorOtherName> filteredContributorsOtherNames = publication.getContributorOtherNames().stream()
.filter(on -> !on.getContributor().getCnIndividu().equals(cnIndividu)).collect(
Collectors.toList());
.filter(on -> !on.getContributor().getCnIndividu().equals(cnIndividu)).collect(
Collectors.toList());
publication.getContributorOtherNames().clear();
publication.getContributorOtherNames().addAll(filteredContributorsOtherNames);
// Then add the new other name to link if necessary or clean contributor name in metadata
// Then add the new other name to link if necessary or clean contributor name in
// metadata
if (otherNameToLink != null) {
publication.getContributorOtherNames().add(otherNameToLink);
} else {
// A link to ContributorOtherName is not necessary, but it is necessary to manage the case of resetting the main contributor name
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(publication.getMetadataVersion());
// A link to ContributorOtherName is not necessary, but it is necessary to
// manage the case of resetting the main contributor name
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(publication.getMetadataVersion());
metadataExtractor.resetUnigeContributorsDisplayName(publication);
// Do not validate to not block update if metadata already contains errors
publication.setMetadataValidationType(Publication.MetadataValidationType.NONE);
@@ -1028,14 +1101,17 @@ public class PublicationService extends AouResourceService<Publication> {
return true;
}
public boolean updatePublicationListWithContributorDisplayName(String cnIndividu, String lastname, String firstname, String[] publicationIds) {
public boolean updatePublicationListWithContributorDisplayName(String cnIndividu, String lastname, String firstname,
String[] publicationIds) {
for (String resId : publicationIds) {
Publication publication = this.findOne(resId);
if (publication == null) {
return false;
}
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(publication.getMetadataVersion());
metadataExtractor.updatePublicationListWithContributorDisplayName(publication, cnIndividu, lastname, firstname, publicationIds);
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(publication.getMetadataVersion());
metadataExtractor.updatePublicationListWithContributorDisplayName(publication, cnIndividu, lastname, firstname,
publicationIds);
publication.setMetadataValidationType(Publication.MetadataValidationType.NONE);
this.save(publication);
}
@@ -1045,24 +1121,30 @@ public class PublicationService extends AouResourceService<Publication> {
private void generateThesisAgreement(Publication publication) {
if (this.generateAgreement && publication.getDocumentFiles() != null && !publication.getDocumentFiles().isEmpty()) {
List<DocumentFile> thesisFilesList = publication.getDocumentFiles().stream()
.filter(documentFile -> documentFile.getDocumentFileType().getValue().equals(AouConstants.DOCUMENT_FILE_TYPE_THESIS))
.collect(Collectors.toList());
.filter(documentFile -> documentFile.getDocumentFileType().getValue()
.equals(AouConstants.DOCUMENT_FILE_TYPE_THESIS))
.collect(Collectors.toList());
List<DocumentFile> agreementFilesList = publication.getDocumentFiles().stream()
.filter(documentFile -> documentFile.getDocumentFileType().getValue().equals(AouConstants.DOCUMENT_FILE_TYPE_AGREEMENT_VALUE))
.collect(Collectors.toList());
.filter(documentFile -> documentFile.getDocumentFileType().getValue()
.equals(AouConstants.DOCUMENT_FILE_TYPE_AGREEMENT_VALUE))
.collect(Collectors.toList());
if (!thesisFilesList.isEmpty() && agreementFilesList.isEmpty()) {
// Check if there is already an author
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(publication.getMetadataVersion());
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(publication.getMetadataVersion());
final Object depositDoc = metadataExtractor.createDepositDocObjectFromXml(publication.getMetadata());
if (metadataExtractor.getFirstAuthor(depositDoc).isPresent() && !StringTool.isNullOrEmpty(metadataExtractor.getDoctorEmail(depositDoc))
&& !StringTool.isNullOrEmpty(metadataExtractor.getDoctorAddress(depositDoc))) {
log.debug("Generating Agreement document for Publication {} : {}", publication.getResId(), thesisFilesList.get(0).getFileName());
if (metadataExtractor.getFirstAuthor(depositDoc).isPresent()
&& !StringTool.isNullOrEmpty(metadataExtractor.getDoctorEmail(depositDoc))
&& !StringTool.isNullOrEmpty(metadataExtractor.getDoctorAddress(depositDoc))) {
log.debug("Generating Agreement document for Publication {} : {}", publication.getResId(),
thesisFilesList.get(0).getFileName());
// save the agreement PDF
this.documentFileService.save(this.pdfDocumentCreator.generateAgreementPdf(publication, thesisFilesList.get(0)));
this.documentFileService
.save(this.pdfDocumentCreator.generateAgreementPdf(publication, thesisFilesList.get(0)));
}
}
}
@@ -1097,7 +1179,8 @@ public class PublicationService extends AouResourceService<Publication> {
return this.createFromXmlMetadataAndImportFiles(xmlMetadata, creator, Publication.ImportSource.PMID);
}
private Publication createFromXmlMetadataAndImportFiles(String xmlMetadata, Person creator, Publication.ImportSource importSource) {
private Publication createFromXmlMetadataAndImportFiles(String xmlMetadata, Person creator,
Publication.ImportSource importSource) {
Publication savedPublication = this.createPublicationFromXmlMetadata(xmlMetadata, creator, importSource);
try {
this.metadataImportFlowService.importFilesFromServices(savedPublication);
@@ -1107,17 +1190,20 @@ public class PublicationService extends AouResourceService<Publication> {
return savedPublication;
}
public Publication createPublicationFromXmlMetadata(String xmlMetadata, Person creator, Publication.ImportSource importSource,
String archiveId, PublicationStatus status) {
public Publication createPublicationFromXmlMetadata(String xmlMetadata, Person creator,
Publication.ImportSource importSource,
String archiveId, PublicationStatus status) {
return this.save(this.getPublicationFromXmlMetadata(xmlMetadata, creator, importSource, archiveId, status));
}
public Publication createPublicationFromXmlMetadata(String xmlMetadata, Person creator, Publication.ImportSource importSource) {
public Publication createPublicationFromXmlMetadata(String xmlMetadata, Person creator,
Publication.ImportSource importSource) {
return this.createPublicationFromXmlMetadata(xmlMetadata, creator, importSource, null, null);
}
public Publication getPublicationFromXmlMetadata(String xmlMetadata, Person creator, Publication.ImportSource importSource, String archiveId,
PublicationStatus status) {
public Publication getPublicationFromXmlMetadata(String xmlMetadata, Person creator,
Publication.ImportSource importSource, String archiveId,
PublicationStatus status) {
Publication publication = new Publication();
publication.setMetadata(xmlMetadata);
publication.setCreator(creator);
@@ -1141,8 +1227,8 @@ public class PublicationService extends AouResourceService<Publication> {
*/
public boolean isAllowedToDownload(String personId, String documentFileId, String publicationId) {
if (this.authenticatedUserHasPriviledgedRole()
|| this.isPersonCreatorOrAuthenticatedUserBelongsToContributors(personId, publicationId)
|| this.personService.isAllowedToValidate(personId, this.findOne(publicationId))) {
|| this.isPersonCreatorOrAuthenticatedUserBelongsToContributors(personId, publicationId)
|| this.personService.isAllowedToValidate(personId, this.findOne(publicationId))) {
// download permission is not related to document file access level
return true;
} else {
@@ -1154,7 +1240,8 @@ public class PublicationService extends AouResourceService<Publication> {
// final access private --> never allowed
return false;
} else {
if (documentFile.getEmbargoAccessLevel() == null || documentFile.getEmbargoEndDate().isBefore(LocalDate.now())) {
if (documentFile.getEmbargoAccessLevel() == null
|| documentFile.getEmbargoEndDate().isBefore(LocalDate.now())) {
// no embargo or embargo is over --> allowed
return true;
} else {
@@ -1166,7 +1253,8 @@ public class PublicationService extends AouResourceService<Publication> {
}
/**
* A SavePublicationMessage can be published to make the Publication saved again. This allows to update publication's metadata
* A SavePublicationMessage can be published to make the Publication saved
* again. This allows to update publication's metadata
* when entities that are present in metadata are updated
*
* @param savePublicationMessage
@@ -1181,7 +1269,8 @@ public class PublicationService extends AouResourceService<Publication> {
}
public void changePublicationCreator(Person creatorToKeep, Person creatorToUpdate) {
List<Publication> publicationList = ((PublicationRepository) this.itemRepository).findByCreatorResId(creatorToUpdate.getResId());
List<Publication> publicationList = ((PublicationRepository) this.itemRepository)
.findByCreatorResId(creatorToUpdate.getResId());
for (Publication publication : publicationList) {
publication.setMetadataValidationType(Publication.MetadataValidationType.NONE);
publication.setCreator(creatorToKeep);
@@ -1190,12 +1279,14 @@ public class PublicationService extends AouResourceService<Publication> {
}
/**
* Method to check metadata and backupMetadata and see if there any differences between files
* Method to check metadata and backupMetadata and see if there any differences
* between files
*
* @param publication
*/
public boolean areThereChangesInDocumentFiles(Publication publication) {
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(publication.getMetadataVersion());
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(publication.getMetadataVersion());
final Object depositDocBefore = metadataExtractor.createDepositDocObjectFromXml(publication.getMetadataBackup());
List<MetadataFile> filesBefore = metadataExtractor.getFiles(depositDocBefore);
@@ -1206,12 +1297,14 @@ public class PublicationService extends AouResourceService<Publication> {
}
public List<MetadataFile> getMetadataFiles(Publication publication, String metadata) {
final MetadataExtractor metadataExtractor = this.metadataService.getMetadataExtractor(publication.getMetadataVersion());
final MetadataExtractor metadataExtractor = this.metadataService
.getMetadataExtractor(publication.getMetadataVersion());
final Object depositDoc = metadataExtractor.createDepositDocObjectFromXml(metadata);
return metadataExtractor.getFiles(depositDoc);
}
public Map<String, Map<String, List<MetadataDifference>>> checkDifferencesInUpdate(Publication publication, boolean simplifiedVersion) {
public Map<String, Map<String, List<MetadataDifference>>> checkDifferencesInUpdate(Publication publication,
boolean simplifiedVersion) {
final MetadataComparator metadataComparator = this.metadataService.getMetadataComparator(publication);
return metadataComparator.getPendingUpdates(publication, simplifiedVersion);
}
@@ -1254,7 +1347,8 @@ public class PublicationService extends AouResourceService<Publication> {
}
return total;
} else {
// reindex publications already existing in publication in progress index, included in query results
// reindex publications already existing in publication in progress index,
// included in query results
List<String> publicationIds = this.indexService.findPublicationIds(query);
long total = publicationIds.size();
if (maxNumber != null && total > maxNumber) {
Loading