common models changes
This commit is contained in:
parent
c592226e77
commit
e3ac2394c2
|
@ -50,7 +50,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>gr.cite.opendmp</groupId>
|
<groupId>gr.cite.opendmp</groupId>
|
||||||
<artifactId>common-models</artifactId>
|
<artifactId>common-models</artifactId>
|
||||||
<version>0.0.2</version>
|
<version>0.0.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>gr.cite.opendmp</groupId>
|
<groupId>gr.cite.opendmp</groupId>
|
||||||
|
|
|
@ -64,6 +64,13 @@ public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder<Descri
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean useSharedStorage;
|
||||||
|
public DescriptionCommonModelBuilder useSharedStorage(boolean useSharedStorage) {
|
||||||
|
this.useSharedStorage = useSharedStorage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<CommonModelBuilderItemResponse<DescriptionModel, DescriptionEntity>> buildInternal(List<DescriptionEntity> data) throws MyApplicationException {
|
protected List<CommonModelBuilderItemResponse<DescriptionModel, DescriptionEntity>> buildInternal(List<DescriptionEntity> data) throws MyApplicationException {
|
||||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
|
@ -95,7 +102,7 @@ public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder<Descri
|
||||||
if (d.getProperties() != null){
|
if (d.getProperties() != null){
|
||||||
//TODO Update with the new logic of property definition
|
//TODO Update with the new logic of property definition
|
||||||
PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties());
|
PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties());
|
||||||
m.setProperties(this.builderFactory.builder(PropertyDefinitionCommonModelBuilder.class).withDefinition(definitionEntityMap != null ? definitionEntityMap.getOrDefault(d.getDescriptionTemplateId(), null) : null).authorize(this.authorize).build(propertyDefinition));
|
m.setProperties(this.builderFactory.builder(PropertyDefinitionCommonModelBuilder.class).useSharedStorage(useSharedStorage).withDefinition(definitionEntityMap != null ? definitionEntityMap.getOrDefault(d.getDescriptionTemplateId(), null) : null).authorize(this.authorize).build(propertyDefinition));
|
||||||
}
|
}
|
||||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||||
}
|
}
|
||||||
|
@ -143,7 +150,7 @@ public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder<Descri
|
||||||
|
|
||||||
Map<UUID, DmpModel> itemMap;
|
Map<UUID, DmpModel> itemMap;
|
||||||
DmpQuery q = this.queryFactory.query(DmpQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDmpId).distinct().collect(Collectors.toList()));
|
DmpQuery q = this.queryFactory.query(DmpQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDmpId).distinct().collect(Collectors.toList()));
|
||||||
itemMap = this.builderFactory.builder(DmpCommonModelBuilder.class).setDisableDescriptions(true).authorize(this.authorize).asForeignKey(q, DmpEntity::getId);
|
itemMap = this.builderFactory.builder(DmpCommonModelBuilder.class).useSharedStorage(useSharedStorage).setDisableDescriptions(true).authorize(this.authorize).asForeignKey(q, DmpEntity::getId);
|
||||||
|
|
||||||
return itemMap;
|
return itemMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,42 @@
|
||||||
package eu.eudat.model.builder.commonmodels.description;
|
package eu.eudat.model.builder.commonmodels.description;
|
||||||
|
|
||||||
import eu.eudat.authorization.AuthorizationFlags;
|
import eu.eudat.authorization.AuthorizationFlags;
|
||||||
|
import eu.eudat.commonmodels.models.FileEnvelopeModel;
|
||||||
import eu.eudat.commonmodels.models.description.FieldModel;
|
import eu.eudat.commonmodels.models.description.FieldModel;
|
||||||
import eu.eudat.commonmodels.models.reference.ReferenceModel;
|
import eu.eudat.commonmodels.models.reference.ReferenceModel;
|
||||||
import eu.eudat.commons.enums.FieldType;
|
import eu.eudat.commons.enums.FieldType;
|
||||||
|
import eu.eudat.commons.enums.StorageType;
|
||||||
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
import eu.eudat.commons.types.description.FieldEntity;
|
import eu.eudat.commons.types.description.FieldEntity;
|
||||||
import eu.eudat.convention.ConventionService;
|
import eu.eudat.convention.ConventionService;
|
||||||
import eu.eudat.data.ReferenceEntity;
|
import eu.eudat.data.ReferenceEntity;
|
||||||
|
import eu.eudat.data.StorageFileEntity;
|
||||||
import eu.eudat.model.Reference;
|
import eu.eudat.model.Reference;
|
||||||
|
import eu.eudat.model.StorageFile;
|
||||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||||
import eu.eudat.model.builder.commonmodels.reference.ReferenceCommonModelBuilder;
|
import eu.eudat.model.builder.commonmodels.reference.ReferenceCommonModelBuilder;
|
||||||
|
import eu.eudat.model.persist.StorageFilePersist;
|
||||||
import eu.eudat.query.ReferenceQuery;
|
import eu.eudat.query.ReferenceQuery;
|
||||||
|
import eu.eudat.query.StorageFileQuery;
|
||||||
|
import eu.eudat.service.storage.StorageFileProperties;
|
||||||
|
import eu.eudat.service.storage.StorageFileService;
|
||||||
import gr.cite.tools.data.builder.BuilderFactory;
|
import gr.cite.tools.data.builder.BuilderFactory;
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
import gr.cite.tools.exception.MyApplicationException;
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
|
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
|
import gr.cite.tools.validation.ValidatorFactory;
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -32,24 +47,38 @@ public class FieldCommonModelBuilder extends BaseCommonModelBuilder<FieldModel,
|
||||||
private final QueryFactory queryFactory;
|
private final QueryFactory queryFactory;
|
||||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||||
private eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity;
|
private eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity;
|
||||||
|
private final StorageFileService storageFileService;
|
||||||
|
private final UserScope userScope;
|
||||||
|
private final ValidatorFactory validatorFactory;
|
||||||
|
private final StorageFileProperties storageFileProperties;
|
||||||
@Autowired
|
@Autowired
|
||||||
public FieldCommonModelBuilder(
|
public FieldCommonModelBuilder(
|
||||||
ConventionService conventionService, BuilderFactory builderFactory, QueryFactory queryFactory
|
ConventionService conventionService, BuilderFactory builderFactory, QueryFactory queryFactory, StorageFileService storageFileService, UserScope userScope, ValidatorFactory validatorFactory, StorageFileProperties storageFileProperties
|
||||||
) {
|
) {
|
||||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldCommonModelBuilder.class)));
|
super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldCommonModelBuilder.class)));
|
||||||
this.builderFactory = builderFactory;
|
this.builderFactory = builderFactory;
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
|
this.storageFileService = storageFileService;
|
||||||
|
this.userScope = userScope;
|
||||||
|
this.validatorFactory = validatorFactory;
|
||||||
|
this.storageFileProperties = storageFileProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FieldCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
public FieldCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||||
this.authorize = values;
|
this.authorize = values;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FieldCommonModelBuilder withFieldEntity(eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity) {
|
public FieldCommonModelBuilder withFieldEntity(eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity) {
|
||||||
this.fieldEntity = fieldEntity;
|
this.fieldEntity = fieldEntity;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean useSharedStorage;
|
||||||
|
public FieldCommonModelBuilder useSharedStorage(boolean useSharedStorage) {
|
||||||
|
this.useSharedStorage = useSharedStorage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
protected List<CommonModelBuilderItemResponse<FieldModel, FieldEntity>> buildInternal(List<FieldEntity> data) throws MyApplicationException {
|
protected List<CommonModelBuilderItemResponse<FieldModel, FieldEntity>> buildInternal(List<FieldEntity> data) throws MyApplicationException {
|
||||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
|
@ -72,6 +101,24 @@ public class FieldCommonModelBuilder extends BaseCommonModelBuilder<FieldModel,
|
||||||
if (referenceItemsMap.containsKey(referenceId)) m.getReferences().add(referenceItemsMap.get(referenceId));
|
if (referenceItemsMap.containsKey(referenceId)) m.getReferences().add(referenceItemsMap.get(referenceId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (FieldType.UPLOAD.equals(fieldType) && d.getTextValue() != null && !d.getTextValue().isEmpty()) {
|
||||||
|
try {
|
||||||
|
byte[] bytes = this.storageFileService.readAsBytesSafe(UUID.fromString(d.getTextValue()));
|
||||||
|
FileEnvelopeModel fileEnvelopeModel = new FileEnvelopeModel();
|
||||||
|
StorageFileEntity storageFile = this.queryFactory.query(StorageFileQuery.class).ids(UUID.fromString(d.getTextValue())).first();
|
||||||
|
fileEnvelopeModel.setFile(bytes);
|
||||||
|
fileEnvelopeModel.setFilename(storageFile.getName() + (storageFile.getExtension().startsWith(".") ? "" : ".") + storageFile.getExtension());
|
||||||
|
fileEnvelopeModel.setMimeType(storageFile.getMimeType());
|
||||||
|
if (!useSharedStorage){
|
||||||
|
fileEnvelopeModel.setFile(bytes);
|
||||||
|
} else {
|
||||||
|
fileEnvelopeModel.setFileRef(this.addFileToSharedStorage(bytes, storageFile));
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
if (d.getExternalIdentifier() != null && FieldType.isExternalIdentifierType(fieldType)) m.setExternalIdentifier(this.builderFactory.builder(ExternalIdentifierCommonModelBuilder.class).authorize(this.authorize).build(d.getExternalIdentifier()));
|
if (d.getExternalIdentifier() != null && FieldType.isExternalIdentifierType(fieldType)) m.setExternalIdentifier(this.builderFactory.builder(ExternalIdentifierCommonModelBuilder.class).authorize(this.authorize).build(d.getExternalIdentifier()));
|
||||||
|
|
||||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||||
|
@ -82,6 +129,19 @@ public class FieldCommonModelBuilder extends BaseCommonModelBuilder<FieldModel,
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String addFileToSharedStorage(byte[] bytes, StorageFileEntity storageFile) throws IOException {
|
||||||
|
StorageFilePersist storageFilePersist = new StorageFilePersist();
|
||||||
|
storageFilePersist.setName(FilenameUtils.removeExtension(storageFile.getName()));
|
||||||
|
storageFilePersist.setExtension(FilenameUtils.getExtension(storageFile.getExtension()));
|
||||||
|
storageFilePersist.setMimeType(URLConnection.guessContentTypeFromName(storageFile.getName() + (storageFile.getExtension().startsWith(".") ? "" : ".") + storageFile.getExtension()));
|
||||||
|
storageFilePersist.setOwnerId(this.userScope.getUserIdSafe());
|
||||||
|
storageFilePersist.setStorageType(StorageType.Temp);
|
||||||
|
storageFilePersist.setLifetime(Duration.ofSeconds(this.storageFileProperties.getTempStoreLifetimeSeconds())); //TODO
|
||||||
|
this.validatorFactory.validator(StorageFilePersist.StorageFilePersistValidator.class).validateForce(storageFilePersist);
|
||||||
|
StorageFile persisted = this.storageFileService.persistBytes(storageFilePersist, bytes, new BaseFieldSet(StorageFile._id, StorageFile._fileRef));
|
||||||
|
return persisted.getFileRef();
|
||||||
|
}
|
||||||
|
|
||||||
private Map<UUID, ReferenceModel> collectReferences(List<FieldEntity> data) throws MyApplicationException {
|
private Map<UUID, ReferenceModel> collectReferences(List<FieldEntity> data) throws MyApplicationException {
|
||||||
if (data.isEmpty())
|
if (data.isEmpty())
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -42,6 +42,13 @@ public class PropertyDefinitionCommonModelBuilder extends BaseCommonModelBuilder
|
||||||
this.definition = definition;
|
this.definition = definition;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean useSharedStorage;
|
||||||
|
public PropertyDefinitionCommonModelBuilder useSharedStorage(boolean useSharedStorage) {
|
||||||
|
this.useSharedStorage = useSharedStorage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
protected List<CommonModelBuilderItemResponse<PropertyDefinitionModel, PropertyDefinitionEntity>> buildInternal(List<PropertyDefinitionEntity> data) throws MyApplicationException {
|
protected List<CommonModelBuilderItemResponse<PropertyDefinitionModel, PropertyDefinitionEntity>> buildInternal(List<PropertyDefinitionEntity> data) throws MyApplicationException {
|
||||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
|
@ -53,7 +60,7 @@ public class PropertyDefinitionCommonModelBuilder extends BaseCommonModelBuilder
|
||||||
m.setFieldSets(new HashMap<>());
|
m.setFieldSets(new HashMap<>());
|
||||||
for (String key : d.getFieldSets().keySet()){
|
for (String key : d.getFieldSets().keySet()){
|
||||||
FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById(key).stream().findFirst().orElse(null) : null;
|
FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById(key).stream().findFirst().orElse(null) : null;
|
||||||
m.getFieldSets().put(key, this.builderFactory.builder(PropertyDefinitionFieldSetCommonModelBuilder.class).authorize(this.authorize).withFieldSetEntity(fieldSetEntity).build(d.getFieldSets().get(key)));
|
m.getFieldSets().put(key, this.builderFactory.builder(PropertyDefinitionFieldSetCommonModelBuilder.class).useSharedStorage(useSharedStorage).authorize(this.authorize).withFieldSetEntity(fieldSetEntity).build(d.getFieldSets().get(key)));
|
||||||
}
|
}
|
||||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,13 @@ public class PropertyDefinitionFieldSetCommonModelBuilder extends BaseCommonMode
|
||||||
this.fieldSetEntity = fieldSetEntity;
|
this.fieldSetEntity = fieldSetEntity;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean useSharedStorage;
|
||||||
|
public PropertyDefinitionFieldSetCommonModelBuilder useSharedStorage(boolean useSharedStorage) {
|
||||||
|
this.useSharedStorage = useSharedStorage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
protected List<CommonModelBuilderItemResponse<PropertyDefinitionFieldSetModel, PropertyDefinitionFieldSetEntity>> buildInternal(List<PropertyDefinitionFieldSetEntity> data) throws MyApplicationException {
|
protected List<CommonModelBuilderItemResponse<PropertyDefinitionFieldSetModel, PropertyDefinitionFieldSetEntity>> buildInternal(List<PropertyDefinitionFieldSetEntity> data) throws MyApplicationException {
|
||||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
|
@ -50,7 +57,7 @@ public class PropertyDefinitionFieldSetCommonModelBuilder extends BaseCommonMode
|
||||||
List<CommonModelBuilderItemResponse<PropertyDefinitionFieldSetModel, PropertyDefinitionFieldSetEntity>> models = new ArrayList<>();
|
List<CommonModelBuilderItemResponse<PropertyDefinitionFieldSetModel, PropertyDefinitionFieldSetEntity>> models = new ArrayList<>();
|
||||||
for (PropertyDefinitionFieldSetEntity d : data) {
|
for (PropertyDefinitionFieldSetEntity d : data) {
|
||||||
PropertyDefinitionFieldSetModel m = new PropertyDefinitionFieldSetModel();
|
PropertyDefinitionFieldSetModel m = new PropertyDefinitionFieldSetModel();
|
||||||
if (d.getItems() != null) m.setItems(this.builderFactory.builder(PropertyDefinitionFieldSetItemModelCommonModelBuilder.class).withFieldSetEntity(this.fieldSetEntity).authorize(this.authorize).build(d.getItems()));
|
if (d.getItems() != null) m.setItems(this.builderFactory.builder(PropertyDefinitionFieldSetItemModelCommonModelBuilder.class).useSharedStorage(useSharedStorage).withFieldSetEntity(this.fieldSetEntity).authorize(this.authorize).build(d.getItems()));
|
||||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,13 @@ public class PropertyDefinitionFieldSetItemModelCommonModelBuilder extends BaseC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean useSharedStorage;
|
||||||
|
public PropertyDefinitionFieldSetItemModelCommonModelBuilder useSharedStorage(boolean useSharedStorage) {
|
||||||
|
this.useSharedStorage = useSharedStorage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<CommonModelBuilderItemResponse<PropertyDefinitionFieldSetItemModel, PropertyDefinitionFieldSetItemEntity>> buildInternal(List<PropertyDefinitionFieldSetItemEntity> data) throws MyApplicationException {
|
protected List<CommonModelBuilderItemResponse<PropertyDefinitionFieldSetItemModel, PropertyDefinitionFieldSetItemEntity>> buildInternal(List<PropertyDefinitionFieldSetItemEntity> data) throws MyApplicationException {
|
||||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
|
@ -60,7 +67,7 @@ public class PropertyDefinitionFieldSetItemModelCommonModelBuilder extends BaseC
|
||||||
m.setFields(new HashMap<>());
|
m.setFields(new HashMap<>());
|
||||||
for (String key : d.getFields().keySet()){
|
for (String key : d.getFields().keySet()){
|
||||||
FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getAllField().stream().findFirst().orElse(null) : null;
|
FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getAllField().stream().findFirst().orElse(null) : null;
|
||||||
m.getFields().put(key, this.builderFactory.builder(FieldCommonModelBuilder.class).authorize(this.authorize).withFieldEntity(fieldEntity).build(d.getFields().get(key)));
|
m.getFields().put(key, this.builderFactory.builder(FieldCommonModelBuilder.class).useSharedStorage(useSharedStorage).authorize(this.authorize).withFieldEntity(fieldEntity).build(d.getFields().get(key)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||||
|
|
|
@ -11,7 +11,6 @@ import eu.eudat.commonmodels.models.description.DescriptionModel;
|
||||||
import eu.eudat.commonmodels.models.dmp.DmpModel;
|
import eu.eudat.commonmodels.models.dmp.DmpModel;
|
||||||
import eu.eudat.commonmodels.models.dmpblueprint.DmpBlueprintModel;
|
import eu.eudat.commonmodels.models.dmpblueprint.DmpBlueprintModel;
|
||||||
import eu.eudat.commonmodels.models.dmpreference.DmpReferenceModel;
|
import eu.eudat.commonmodels.models.dmpreference.DmpReferenceModel;
|
||||||
import eu.eudat.commonmodels.models.reference.ReferenceModel;
|
|
||||||
import eu.eudat.commons.JsonHandlingService;
|
import eu.eudat.commons.JsonHandlingService;
|
||||||
import eu.eudat.commons.enums.IsActive;
|
import eu.eudat.commons.enums.IsActive;
|
||||||
import eu.eudat.commons.types.dmp.DmpPropertiesEntity;
|
import eu.eudat.commons.types.dmp.DmpPropertiesEntity;
|
||||||
|
@ -22,7 +21,6 @@ import eu.eudat.model.builder.commonmodels.*;
|
||||||
import eu.eudat.model.builder.commonmodels.description.DescriptionCommonModelBuilder;
|
import eu.eudat.model.builder.commonmodels.description.DescriptionCommonModelBuilder;
|
||||||
import eu.eudat.model.builder.commonmodels.dmpblueprint.DmpBlueprintCommonModelBuilder;
|
import eu.eudat.model.builder.commonmodels.dmpblueprint.DmpBlueprintCommonModelBuilder;
|
||||||
import eu.eudat.model.builder.commonmodels.dmpreference.DmpReferenceCommonModelBuilder;
|
import eu.eudat.model.builder.commonmodels.dmpreference.DmpReferenceCommonModelBuilder;
|
||||||
import eu.eudat.model.builder.commonmodels.reference.ReferenceCommonModelBuilder;
|
|
||||||
import eu.eudat.query.*;
|
import eu.eudat.query.*;
|
||||||
import gr.cite.tools.data.builder.BuilderFactory;
|
import gr.cite.tools.data.builder.BuilderFactory;
|
||||||
import gr.cite.tools.data.query.Ordering;
|
import gr.cite.tools.data.query.Ordering;
|
||||||
|
@ -88,6 +86,13 @@ public class DmpCommonModelBuilder extends BaseCommonModelBuilder<DmpModel, DmpE
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean useSharedStorage;
|
||||||
|
public DmpCommonModelBuilder useSharedStorage(boolean useSharedStorage) {
|
||||||
|
this.useSharedStorage = useSharedStorage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<CommonModelBuilderItemResponse<DmpModel, DmpEntity>> buildInternal(List<DmpEntity> data) throws MyApplicationException {
|
protected List<CommonModelBuilderItemResponse<DmpModel, DmpEntity>> buildInternal(List<DmpEntity> data) throws MyApplicationException {
|
||||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
|
@ -190,7 +195,7 @@ public class DmpCommonModelBuilder extends BaseCommonModelBuilder<DmpModel, DmpE
|
||||||
|
|
||||||
Map<UUID, List<DescriptionModel>> itemMap;
|
Map<UUID, List<DescriptionModel>> itemMap;
|
||||||
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList()));
|
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList()));
|
||||||
itemMap = this.builderFactory.builder(DescriptionCommonModelBuilder.class).authorize(this.authorize).asMasterKey(query, DescriptionEntity::getDmpId);
|
itemMap = this.builderFactory.builder(DescriptionCommonModelBuilder.class).useSharedStorage(useSharedStorage).authorize(this.authorize).asMasterKey(query, DescriptionEntity::getDmpId);
|
||||||
|
|
||||||
return itemMap;
|
return itemMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,9 @@ public class DepositServiceImpl implements DepositService {
|
||||||
FileEnvelopeModel jsonEnvelope = new FileEnvelopeModel();
|
FileEnvelopeModel jsonEnvelope = new FileEnvelopeModel();
|
||||||
|
|
||||||
pdfEnvelope.setFilename(pdfFile.getFilename());
|
pdfEnvelope.setFilename(pdfFile.getFilename());
|
||||||
|
jsonEnvelope.setMimeType("application/pdf");
|
||||||
jsonEnvelope.setFilename(rda.getFilename());
|
jsonEnvelope.setFilename(rda.getFilename());
|
||||||
|
jsonEnvelope.setMimeType("application/json");
|
||||||
if (!depositClient.getConfiguration().isUseSharedStorage()){
|
if (!depositClient.getConfiguration().isUseSharedStorage()){
|
||||||
pdfEnvelope.setFile(pdfFile.getFile());
|
pdfEnvelope.setFile(pdfFile.getFile());
|
||||||
jsonEnvelope.setFile(rda.getFile());
|
jsonEnvelope.setFile(rda.getFile());
|
||||||
|
@ -180,28 +182,9 @@ public class DepositServiceImpl implements DepositService {
|
||||||
}
|
}
|
||||||
|
|
||||||
//GK: Fifth Transform them to the DepositModel
|
//GK: Fifth Transform them to the DepositModel
|
||||||
DmpModel depositModel = this.builderFactory.builder(DmpCommonModelBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic)
|
DmpModel depositModel = this.builderFactory.builder(DmpCommonModelBuilder.class).useSharedStorage(depositClient.getConfiguration().isUseSharedStorage()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic)
|
||||||
.setRepositoryId(dmpDepositModel.getRepositoryId()).setPdfFile(pdfEnvelope).setRdaJsonFile(jsonEnvelope).build(dmpEntity);
|
.setRepositoryId(dmpDepositModel.getRepositoryId()).setPdfFile(pdfEnvelope).setRdaJsonFile(jsonEnvelope).build(dmpEntity);
|
||||||
|
|
||||||
//TODO
|
|
||||||
// if (depositModel != null && !this.conventionService.isListNullOrEmpty(depositModel.getDescriptions())){
|
|
||||||
// for (DescriptionModel descriptionModel :depositModel.getDescriptions()){
|
|
||||||
// DescriptionTemplateEntity descriptionTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionModel.getDescriptionTemplate().getId()).firstAs(new BaseFieldSet().ensure(DescriptionTemplate._definition));
|
|
||||||
// if (descriptionTemplate == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionModel.getDescriptionTemplate().getId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
|
||||||
//
|
|
||||||
// if (descriptionModel.getProperties() != null && descriptionModel.getProperties().getFieldSets() != null){
|
|
||||||
// for(PropertyDefinitionFieldSetItemModel propertyDefinitionFieldSetItemModel : descriptionModel.getProperties().getFieldSets().values().stream().filter(x-> x.getItems() != null).map(PropertyDefinitionFieldSetModel::getItems).flatMap(Collection::stream).toList()){
|
|
||||||
// if (propertyDefinitionFieldSetItemModel.getFields() != null){
|
|
||||||
// for(Map.Entry<String, FieldModel> entrySet : propertyDefinitionFieldSetItemModel.getFields().entrySet()){
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
//GK: Sixth Perform the deposit
|
//GK: Sixth Perform the deposit
|
||||||
String doi = depositClient.deposit(depositModel, dmpDepositModel.getAccessToken());
|
String doi = depositClient.deposit(depositModel, dmpDepositModel.getAccessToken());
|
||||||
|
|
|
@ -197,17 +197,8 @@ public class StorageFileProperties {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StaticFilesConfig{
|
public static class StaticFilesConfig{
|
||||||
private String externalUrls;
|
|
||||||
private String semantics;
|
private String semantics;
|
||||||
|
|
||||||
public String getExternalUrls() {
|
|
||||||
return externalUrls;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExternalUrls(String externalUrls) {
|
|
||||||
this.externalUrls = externalUrls;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSemantics() {
|
public String getSemantics() {
|
||||||
return semantics;
|
return semantics;
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ public class FileTransformerServiceImpl implements FileTransformerService {
|
||||||
if (repository == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{repositoryId, TransformerRepository.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
if (repository == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{repositoryId, TransformerRepository.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
//GK: Second get the Target Data Management Plan
|
//GK: Second get the Target Data Management Plan
|
||||||
DmpQuery query = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(dmpId);
|
DmpQuery query = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(dmpId);
|
||||||
DmpModel dmpFileTransformerModel = this.builderFactory.builder(DmpCommonModelBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first());
|
DmpModel dmpFileTransformerModel = this.builderFactory.builder(DmpCommonModelBuilder.class).useSharedStorage(repository.getConfiguration().isUseSharedStorage()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first());
|
||||||
if (dmpFileTransformerModel == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{dmpId, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
if (dmpFileTransformerModel == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{dmpId, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
|
|
||||||
FileEnvelopeModel fileEnvelope = repository.exportDmp(dmpFileTransformerModel, format);
|
FileEnvelopeModel fileEnvelope = repository.exportDmp(dmpFileTransformerModel, format);
|
||||||
|
@ -156,7 +156,7 @@ public class FileTransformerServiceImpl implements FileTransformerService {
|
||||||
|
|
||||||
//GK: Second get the Target Data Management Plan
|
//GK: Second get the Target Data Management Plan
|
||||||
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(descriptionId);
|
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(descriptionId);
|
||||||
DescriptionModel descriptionFileTransformerModel = this.builderFactory.builder(DescriptionCommonModelBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first());
|
DescriptionModel descriptionFileTransformerModel = this.builderFactory.builder(DescriptionCommonModelBuilder.class).useSharedStorage(repository.getConfiguration().isUseSharedStorage()).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first());
|
||||||
if (descriptionFileTransformerModel == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionId, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
if (descriptionFileTransformerModel == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionId, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
|
|
||||||
FileEnvelopeModel fileEnvelope = repository.exportDescription(descriptionFileTransformerModel, format);
|
FileEnvelopeModel fileEnvelope = repository.exportDescription(descriptionFileTransformerModel, format);
|
||||||
|
|
|
@ -11,7 +11,6 @@ storage:
|
||||||
- type: Deposit
|
- type: Deposit
|
||||||
basePath: ${FILE_STORAGE}/deposit
|
basePath: ${FILE_STORAGE}/deposit
|
||||||
static-files:
|
static-files:
|
||||||
externalUrls: dmp-backend/web/src/main/resources/externalUrls/ExternalUrls.xml
|
|
||||||
semantics: dmp-backend/web/src/main/resources/Semantics.json
|
semantics: dmp-backend/web/src/main/resources/Semantics.json
|
||||||
material-files:
|
material-files:
|
||||||
userGuide: dmp-backend/web/src/main/resources/material/user-guide/
|
userGuide: dmp-backend/web/src/main/resources/material/user-guide/
|
||||||
|
|
Loading…
Reference in New Issue