description template migration

This commit is contained in:
Efstratios Giannopoulos 2023-11-06 17:16:55 +02:00
parent d8b1211a12
commit 87e22040c5
12 changed files with 174 additions and 288 deletions

View File

@ -50,7 +50,8 @@ public class AuditableAction {
public static final EventId DescriptionTemplate_PersistNewVersion = new EventId(8005, "DescriptionTemplate_PersistNewVersion"); public static final EventId DescriptionTemplate_PersistNewVersion = new EventId(8005, "DescriptionTemplate_PersistNewVersion");
public static final EventId DescriptionTemplate_GetXml = new EventId(8006, "DescriptionTemplate_GetXml"); public static final EventId DescriptionTemplate_GetXml = new EventId(8006, "DescriptionTemplate_GetXml");
public static final EventId DescriptionTemplate_Import = new EventId(8007, "DescriptionTemplate_Import"); public static final EventId DescriptionTemplate_Import = new EventId(8007, "DescriptionTemplate_Import");
public static final EventId DescriptionTemplate_GetSemantics = new EventId(8007, "DescriptionTemplate_GetSemantics");
public static final EventId SupportiveMaterial_Query = new EventId(9000, "SupportiveMaterial_Query"); public static final EventId SupportiveMaterial_Query = new EventId(9000, "SupportiveMaterial_Query");
public static final EventId SupportiveMaterial_Lookup = new EventId(9001, "SupportiveMaterial_Lookup"); public static final EventId SupportiveMaterial_Lookup = new EventId(9001, "SupportiveMaterial_Lookup");
public static final EventId SupportiveMaterial_Persist = new EventId(9002, "SupportiveMaterial_Persist"); public static final EventId SupportiveMaterial_Persist = new EventId(9002, "SupportiveMaterial_Persist");

View File

@ -0,0 +1,10 @@
package eu.eudat.commons.config.filepath;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableConfigurationProperties(FilePathsProperties.class)
public class FilePathsConfiguration {
}

View File

@ -0,0 +1,54 @@
package eu.eudat.commons.config.filepath;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "file-paths")
public class FilePathsProperties {
private String externalUrls;
private String semantics;
private String h2020template;
private String h2020DatasetTemplate;
private String pidLinks;
public String getExternalUrls() {
return externalUrls;
}
public void setExternalUrls(String externalUrls) {
this.externalUrls = externalUrls;
}
public String getSemantics() {
return semantics;
}
public void setSemantics(String semantics) {
this.semantics = semantics;
}
public String getH2020template() {
return h2020template;
}
public void setH2020template(String h2020template) {
this.h2020template = h2020template;
}
public String getH2020DatasetTemplate() {
return h2020DatasetTemplate;
}
public void setH2020DatasetTemplate(String h2020DatasetTemplate) {
this.h2020DatasetTemplate = h2020DatasetTemplate;
}
public String getPidLinks() {
return pidLinks;
}
public void setPidLinks(String pidLinks) {
this.pidLinks = pidLinks;
}
}

View File

@ -17,6 +17,7 @@ import javax.management.InvalidApplicationException;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerException;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public interface DescriptionTemplateService { public interface DescriptionTemplateService {
@ -27,4 +28,8 @@ public interface DescriptionTemplateService {
DescriptionTemplate createNewVersion(NewVersionDescriptionTemplatePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException; DescriptionTemplate createNewVersion(NewVersionDescriptionTemplatePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException;
DescriptionTemplate importXml(byte[] bytes, UUID id, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException; DescriptionTemplate importXml(byte[] bytes, UUID id, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException;
ResponseEntity<byte[]> exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException, InvalidApplicationException; ResponseEntity<byte[]> exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException, InvalidApplicationException;
List<String> getSemantics(String query) throws IOException;
List<Semantic> getSemantics() throws IOException;
} }

View File

@ -3,7 +3,9 @@ package eu.eudat.service.descriptiontemplate;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission; import eu.eudat.authorization.Permission;
import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.config.filepath.FilePathsProperties;
import eu.eudat.commons.enums.DescriptionTemplateStatus; import eu.eudat.commons.enums.DescriptionTemplateStatus;
import eu.eudat.commons.enums.FieldType; import eu.eudat.commons.enums.FieldType;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
@ -11,7 +13,6 @@ import eu.eudat.commons.enums.UserDescriptionTemplateRole;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.types.descriptiontemplate.*; import eu.eudat.commons.types.descriptiontemplate.*;
import eu.eudat.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity;
import eu.eudat.commons.types.descriptiontemplate.fielddata.FieldDataHelper;
import eu.eudat.commons.types.descriptiontemplate.importexport.*; import eu.eudat.commons.types.descriptiontemplate.importexport.*;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.DescriptionTemplateEntity;
@ -62,13 +63,15 @@ import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.w3c.dom.Element;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
@ -79,6 +82,7 @@ import java.util.stream.Collectors;
@Service @Service
public class DescriptionTemplateServiceImpl implements DescriptionTemplateService { public class DescriptionTemplateServiceImpl implements DescriptionTemplateService {
private List<Semantic> semantics = null;
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateServiceImpl.class)); private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionTemplateServiceImpl.class));
@ -100,6 +104,8 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
private final MailService mailService; private final MailService mailService;
private final Environment environment; private final Environment environment;
private final ResponseUtilsService responseUtilsService; private final ResponseUtilsService responseUtilsService;
private final FilePathsProperties filePathsProperties;
private final JsonHandlingService jsonHandlingService;
@Autowired @Autowired
public DescriptionTemplateServiceImpl( public DescriptionTemplateServiceImpl(
@ -110,7 +116,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
ConventionService conventionService, ConventionService conventionService,
MessageSource messageSource, MessageSource messageSource,
XmlHandlingService xmlHandlingService, XmlHandlingService xmlHandlingService,
FieldDataHelperServiceProvider fieldDataHelperServiceProvider, QueryFactory queryFactory, ErrorThesaurusProperties errors, ValidationService validationService, MailService mailService, Environment environment, ResponseUtilsService responseUtilsService) { FieldDataHelperServiceProvider fieldDataHelperServiceProvider, QueryFactory queryFactory, ErrorThesaurusProperties errors, ValidationService validationService, MailService mailService, Environment environment, ResponseUtilsService responseUtilsService, FilePathsProperties filePathsProperties, JsonHandlingService jsonHandlingService) {
this.entityManager = entityManager; this.entityManager = entityManager;
this.userScope = userScope; this.userScope = userScope;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
@ -126,6 +132,8 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
this.mailService = mailService; this.mailService = mailService;
this.environment = environment; this.environment = environment;
this.responseUtilsService = responseUtilsService; this.responseUtilsService = responseUtilsService;
this.filePathsProperties = filePathsProperties;
this.jsonHandlingService = jsonHandlingService;
} }
//region Persist //region Persist
@ -648,6 +656,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
//region Export //region Export
@Override
public ResponseEntity<byte[]> exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException, InvalidApplicationException { public ResponseEntity<byte[]> exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException, InvalidApplicationException {
logger.debug(new MapLogEntry("persisting data").And("id", id)); logger.debug(new MapLogEntry("persisting data").And("id", id));
@ -660,7 +669,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return this.responseUtilsService.buildResponseFileFromText(xml, data.getLabel() + ".xml"); return this.responseUtilsService.buildResponseFileFromText(xml, data.getLabel() + ".xml");
} }
public DescriptionTemplateImportExport definitionXmlToExport(DescriptionTemplateEntity data, DefinitionEntity entity){ private DescriptionTemplateImportExport definitionXmlToExport(DescriptionTemplateEntity data, DefinitionEntity entity){
DescriptionTemplateImportExport xml = new DescriptionTemplateImportExport(); DescriptionTemplateImportExport xml = new DescriptionTemplateImportExport();
xml.setType(data.getType()); xml.setType(data.getType());
xml.setLanguage(data.getLanguage()); xml.setLanguage(data.getLanguage());
@ -674,7 +683,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return xml; return xml;
} }
public PageImportExport pageXmlToExport(PageEntity entity, List<SectionEntity> sectionEntities){ private PageImportExport pageXmlToExport(PageEntity entity, List<SectionEntity> sectionEntities){
PageImportExport xml = new PageImportExport(); PageImportExport xml = new PageImportExport();
xml.setId(entity.getId()); xml.setId(entity.getId());
xml.setOrdinal(entity.getOrdinal()); xml.setOrdinal(entity.getOrdinal());
@ -692,7 +701,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return xml; return xml;
} }
public SectionImportExport sectionXmlToExport(SectionEntity entity) { private SectionImportExport sectionXmlToExport(SectionEntity entity) {
SectionImportExport xml = new SectionImportExport(); SectionImportExport xml = new SectionImportExport();
List<SectionImportExport> sectionsListEntity = new LinkedList<>(); List<SectionImportExport> sectionsListEntity = new LinkedList<>();
@ -721,7 +730,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
} }
public FieldSetImportExport fieldSetXmlToExport(FieldSetEntity entity) { private FieldSetImportExport fieldSetXmlToExport(FieldSetEntity entity) {
FieldSetImportExport fieldSet1Entity = new FieldSetImportExport(); FieldSetImportExport fieldSet1Entity = new FieldSetImportExport();
fieldSet1Entity.setId(entity.getId()); fieldSet1Entity.setId(entity.getId());
fieldSet1Entity.setOrdinal(entity.getOrdinal()); fieldSet1Entity.setOrdinal(entity.getOrdinal());
@ -743,7 +752,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
} }
public FieldImportExport fieldXmlToExport(FieldEntity entity) { private FieldImportExport fieldXmlToExport(FieldEntity entity) {
FieldImportExport xml = new FieldImportExport(); FieldImportExport xml = new FieldImportExport();
xml.setId(entity.getId()); xml.setId(entity.getId());
xml.setOrdinal(entity.getOrdinal()); xml.setOrdinal(entity.getOrdinal());
@ -766,7 +775,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
return xml; return xml;
} }
public RuleImportExport toRuleModel(RuleEntity entity){ private RuleImportExport toRuleModel(RuleEntity entity){
RuleImportExport xml = new RuleImportExport(); RuleImportExport xml = new RuleImportExport();
xml.setTarget(entity.getTarget()); xml.setTarget(entity.getTarget());
xml.setValue(entity.getValue()); xml.setValue(entity.getValue());
@ -774,7 +783,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
} }
public MultiplicityImportXml multiplicityXmlToExport(MultiplicityEntity entity) { private MultiplicityImportXml multiplicityXmlToExport(MultiplicityEntity entity) {
MultiplicityImportXml xml = new MultiplicityImportXml(); MultiplicityImportXml xml = new MultiplicityImportXml();
xml.setMax(entity.getMax()); xml.setMax(entity.getMax());
xml.setMin(entity.getMin()); xml.setMin(entity.getMin());
@ -784,5 +793,58 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
} }
//endregion //endregion
//region
@Override
public List<String> getSemantics(String query) throws IOException {
List<Semantic> semantics = this.getSemantics();
List<String> filteredSemantics = semantics.stream().map(Semantic::getName).collect(Collectors.toList());
if(query != null && !query.isEmpty()){
filteredSemantics = semantics.stream().filter(x -> x.getCategory().contains(query) || x.getName().contains(query)).map(Semantic::getName).collect(Collectors.toList());
}
return filteredSemantics;
}
@Override
public List<Semantic> getSemantics() throws IOException {
this.authorizationService.authorizeForce(Permission.BrowseDescriptionTemplate);
if (semantics == null) {
semantics = new ArrayList<>();
this.loadSemantics();
}
return semantics;
}
private void loadSemantics() throws IOException {
String filePath = this.filePathsProperties.getSemantics();
logger.info("Loaded also config file: " + filePath);
if (filePath != null) {
InputStream stream = null;
try {
stream = getStreamFromPath(filePath);
String json = new String(getStreamFromPath(filePath).readAllBytes(), StandardCharsets.UTF_8);
semantics = List.of(jsonHandlingService.fromJson(Semantic[].class, json));
}
catch (IOException e) {
logger.error(e.getMessage(), e);
}
finally {
if (stream != null) stream.close();
}
}
}
private InputStream getStreamFromPath(String filePath) {
try {
return new FileInputStream(filePath);
} catch (FileNotFoundException e) {
logger.info("loading from classpath");
return getClass().getClassLoader().getResourceAsStream(filePath);
}
}
//endregion
} }

View File

@ -1,4 +1,4 @@
package eu.eudat.logic.proxy.config; package eu.eudat.service.descriptiontemplate;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;

View File

@ -1,225 +0,0 @@
package eu.eudat.controllers;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.logic.managers.DatasetProfileManager;
import eu.eudat.logic.managers.MetricsManager;
import eu.eudat.logic.managers.UserManager;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.query.DescriptionTemplateTypeQuery;
import eu.eudat.service.descriptiontemplatetype.DescriptionTemplateTypeService;
import eu.eudat.service.fielddatahelper.FieldDataHelperService;
import eu.eudat.types.ApiMessageCode;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.QueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import jakarta.transaction.Transactional;
import javax.management.InvalidApplicationException;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/admin/"})
public class Admin extends BaseController {
private DatasetProfileManager datasetProfileManager;
private UserManager userManager;
private ConfigLoader configLoader;
private final MetricsManager metricsManager;
private final AuthorizationService authorizationService;
private final UserScope userScope;
private final QueryFactory queryFactory;
private final DescriptionTemplateTypeService descriptionTemplateTypeService;
private final FieldDataHelperService fieldDataHelperService;
@Autowired
public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, UserManager userManager/*, Logger logger*/, ConfigLoader configLoader, MetricsManager metricsManager, AuthorizationService authorizationService, UserScope userScope, QueryFactory queryFactory, DescriptionTemplateTypeService descriptionTemplateTypeService, FieldDataHelperService fieldDataHelperService) {
super(apiContext);
this.datasetProfileManager = datasetProfileManager;
this.userManager = userManager;
this.configLoader = configLoader;
this.metricsManager = metricsManager;
this.authorizationService = authorizationService;
this.userScope = userScope;
this.queryFactory = queryFactory;
this.descriptionTemplateTypeService = descriptionTemplateTypeService;
this.fieldDataHelperService = fieldDataHelperService;
}
// @Transactional
// @RequestMapping(method = RequestMethod.POST, value = {"/addDmp"}, consumes = "application/json", produces = "application/json")
// public ResponseEntity<Object> addDmp(@Valid @RequestBody DatasetProfile profile) throws Exception {
// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole);
//
// //this.getLoggerService().info(principal, "Admin Added Dataset Profile");
// DatasetProfile shortenProfile = profile.toShort();
// DescriptionTemplateEntity modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext(), descriptionTemplateTypeService);
//// modelDefinition.setType(getApiContext().getOperationsContext().getDatabaseRepository().getDescriptionTemplateTypeDao().findFromName(profile.getType()));
////TODO: dtziotzios modelDefinition.setType(descriptionTemplateTypeService.getEntityByName(profile.getType()));
// modelDefinition.setGroupId(UUID.randomUUID());
// modelDefinition.setVersion((short) 0);
//
// DescriptionTemplateEntity descriptionTemplateEntity = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
// UserDescriptionTemplateEntity userDatasetProfile = new UserDescriptionTemplateEntity();
// userDatasetProfile.setDescriptionTemplate(descriptionTemplateEntity.getId());
// UserInfo userInfo = getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId());
// userDatasetProfile.setUser(userInfo.getId());
// userDatasetProfile.setRole(UserDescriptionTemplateRole.Owner);
// getApiContext().getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile);
// datasetProfileManager.storeDatasetProfileUsers(descriptionTemplateEntity, profile);
//
// metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricsManager.datasetTemplateStatus.get(descriptionTemplateEntity.getStatus()) );
// return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId());
// }
// @Transactional
// @RequestMapping(method = RequestMethod.POST, value = {"/addDmp/{id}"}, consumes = "application/json", produces = "application/json")
// public ResponseEntity<ResponseItem<UUID>> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile) throws Exception {
// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole);
//
// DatasetProfile shortenProfile = profile.toShort();
// DescriptionTemplateEntity modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext(), descriptionTemplateTypeService);
// DescriptionTemplateEntity datasetprofile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
// datasetprofile.setDefinition(modelDefinition.getDefinition());
// DescriptionTemplateStatus oldStatus = datasetprofile.getStatus();
// datasetprofile.setStatus(modelDefinition.getStatus());
// datasetprofile.setLabel(modelDefinition.getLabel());
// datasetprofile.setDescription(modelDefinition.getDescription());
// datasetprofile.setLanguage(modelDefinition.getLanguage());
// DescriptionTemplateEntity descriptionTemplateEntity = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile);
// datasetProfileManager.storeDatasetProfileUsers(descriptionTemplateEntity, profile);
// if (DescriptionTemplateStatus.Finalized.equals(descriptionTemplateEntity.getStatus()) && DescriptionTemplateStatus.Draft.equals(oldStatus)) {
// metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricNames.ACTIVE);
// }
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.NO_MESSAGE));
// }
// @Transactional
// @RequestMapping(method = RequestMethod.POST, value = {"/newVersion/{id}"}, produces = "application/json")
// public ResponseEntity newVersionDatasetProfile(@PathVariable String id, @RequestBody DatasetProfile profile) throws Exception {
// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole);
//
// try {
// DescriptionTemplateEntity modelDefinition = this.datasetProfileManager.createNewVersionDatasetProfile(id, profile);
// return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId());
// } catch (DatasetProfileNewVersionException exception) {
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
// }
// }
// @RequestMapping(method = RequestMethod.GET, value = {"/get/{id}"}, produces = "application/json")
// @Transactional
// public ResponseEntity<ResponseItem<DatasetProfile>> get(@PathVariable String id) throws InvalidApplicationException {
// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole);
//
// eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = this.datasetProfileManager.getDatasetProfile(id);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetProfile>().status(ApiMessageCode.NO_MESSAGE).payload(datasetprofile));
// }
// @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofiles/getPaged"}, produces = "application/json")
// public @ResponseBody
// ResponseEntity<ResponseItem<DataTableData<DatasetProfileListingModel>>> getPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception {
// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole);
//
// DataTableData<DatasetProfileListingModel> datasetProfileTableData = this.datasetProfileManager.getPaged(datasetProfileTableRequestItem);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData));
// }
// @RequestMapping(method = RequestMethod.POST, value = {"/preview"}, consumes = "application/json", produces = "application/json")
// public ResponseEntity<ResponseItem<PagedDatasetProfile>> getPreview(@RequestBody DatasetProfile profile) throws Exception {
// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole);
//
// DescriptionTemplateEntity modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext(), descriptionTemplateTypeService);
// eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = userManager.generateDatasetProfileModel(modelDefinition);
// PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
// pagedDatasetProfile.buildPagedDatasetProfile(datasetProfile);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<PagedDatasetProfile>().status(ApiMessageCode.NO_MESSAGE).payload(pagedDatasetProfile));
// }
// @Transactional
// @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/clone/{id}"}, consumes = "application/json", produces = "application/json")
// public ResponseEntity<ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>> clone(@PathVariable String id) throws InvalidApplicationException {
// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole);
//
// eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = this.datasetProfileManager.getDatasetProfile(id);
// datasetprofile.setLabel(datasetprofile.getLabel() + " new ");
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().payload(datasetprofile));
// }
// @Transactional
// @RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
// public @ResponseBody
// ResponseEntity<ResponseItem<DatasetProfile>> inactivate(@PathVariable String id) {
// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole);
//
// try {
// DescriptionTemplateEntity ret = AdminManager.inactivate(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.SUCCESS_MESSAGE));
// } catch (DatasetProfileWithDatasetsExeption | InvalidApplicationException exception) {
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.UNSUCCESS_DELETE).message(exception.getMessage()));
// }
// }
// @Transactional
// @RequestMapping(method = RequestMethod.GET, value = {"/getXml/{id}"}, produces = "application/json")
// public ResponseEntity getDatasetProfileXml(@PathVariable String id, @RequestHeader("Content-Type") String contentType) throws IllegalAccessException, IOException, InstantiationException, InvalidApplicationException {
// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole);
//
// if (contentType.equals("application/xml")) {
// DescriptionTemplateEntity profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
// eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = userManager.generateDatasetProfileModel(profile);
// datasetProfile.setStatus(profile.getStatus().getValue());
// datasetProfile.setDescription(profile.getDescription());
// datasetProfile.setLanguage(profile.getLanguage());
// datasetProfile.setType(this.queryFactory.query(DescriptionTemplateTypeQuery.class).ids(profile.getType()).first().getName());
// return this.datasetProfileManager.getDocument(datasetProfile, profile.getLabel());
// } else {
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.ERROR_MESSAGE).message("NOT AUTHORIZE"));
// }
// }
// @RequestMapping(method = RequestMethod.POST, value = {"/upload", "/upload/{id}"})
// public ResponseEntity<Object> setDatasetProfileXml(@RequestParam("file") MultipartFile file,
// @PathVariable(value = "id", required = false) String id) throws Exception {
// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole);
//
// DescriptionTemplateImportXml descriptionTemplateImportXmlModel = this.datasetProfileManager.createDatasetProfileFromXml(file);
// eu.eudat.models.data.admin.composite.DatasetProfile datasetProfileEntity = descriptionTemplateImportXmlModel.toPersistModel(file.getOriginalFilename(), this.fieldDataHelperService);
// DescriptionTemplateEntity modelDefinition;
// if (id == null) {
// modelDefinition = AdminManager.generateViewStyleDefinition(datasetProfileEntity, getApiContext(), descriptionTemplateTypeService);
// DescriptionTemplateEntity descriptionTemplateEntity = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
// UserDescriptionTemplateEntity userDatasetProfile = new UserDescriptionTemplateEntity();
// userDatasetProfile.setDescriptionTemplate(descriptionTemplateEntity.getId());
// UserInfo userInfo = getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userScope.getUserId());
// userDatasetProfile.setUser(userInfo.getId());
// userDatasetProfile.setRole(UserDescriptionTemplateRole.Owner);
// getApiContext().getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile);
// } else {
// modelDefinition = datasetProfileManager.createNewVersionDatasetProfile(id, datasetProfileEntity);
// }
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DescriptionTemplateEntity>>()
// .status(ApiMessageCode.SUCCESS_MESSAGE).message(""));
// }
@RequestMapping(method = RequestMethod.GET, value = {"/getSemantics"}, produces = "application/json")
public ResponseEntity<ResponseItem<List<String>>> getSemantics(@RequestParam(value = "query", required = false) String query) {
this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole);
List<String> semantics = this.datasetProfileManager.getSemantics(query);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<String>>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(semantics));
}
}

View File

@ -204,4 +204,18 @@ public class DescriptionTemplateController {
return model; return model;
} }
@RequestMapping(method = RequestMethod.GET, value = {"/get-semantics"}, produces = "application/json")
public List<String> getSemantics(@RequestParam(value = "query", required = false) String query) throws IOException {
logger.debug(new MapLogEntry("import" + DescriptionTemplate.class.getSimpleName()).And("query", query));
List<String> semantics = this.descriptionTemplateTypeService.getSemantics(query);
this.auditService.track(AuditableAction.DescriptionTemplate_GetSemantics, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("query", query)
));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return semantics;
}
} }

View File

@ -1,6 +1,5 @@
package eu.eudat.logic.managers; package eu.eudat.logic.managers;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.types.descriptiontemplate.FieldEntity; import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
import eu.eudat.commons.types.descriptiontemplate.fielddata.AutoCompleteDataEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.AutoCompleteDataEntity;
import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.commons.types.xml.XmlBuilder;
@ -12,14 +11,10 @@ import eu.eudat.logic.proxy.fetching.RemoteFetcher;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.logic.services.operations.DatabaseRepository;
import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel; import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
import eu.eudat.service.descriptiontemplatetype.DescriptionTemplateTypeService; import eu.eudat.service.descriptiontemplate.Semantic;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
import org.slf4j.Logger; import org.slf4j.Logger;
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.core.env.Environment;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -219,15 +214,6 @@ public class DatasetProfileManager {
return item != null ? item.toString() : null; return item != null ? item.toString() : null;
} }
public List<String> getSemantics(String query) {
List<Semantic> semantics = configLoader.getSemantics();
List<String> filteredSemantics = semantics.stream().map(Semantic::getName).collect(Collectors.toList());
if(query != null && !query.isEmpty()){
filteredSemantics = semantics.stream().filter(x -> x.getCategory().contains(query) || x.getName().contains(query)).map(Semantic::getName).collect(Collectors.toList());
}
return filteredSemantics;
}
public void addSemanticsInDatasetProfiles() throws XPathExpressionException, InvalidApplicationException { public void addSemanticsInDatasetProfiles() throws XPathExpressionException, InvalidApplicationException {
List<DescriptionTemplateEntity> ids = this.databaseRepository.getDatasetProfileDao().getAllIds(); List<DescriptionTemplateEntity> ids = this.databaseRepository.getDatasetProfileDao().getAllIds();
for(DescriptionTemplateEntity dp: ids){ for(DescriptionTemplateEntity dp: ids){

View File

@ -1,7 +1,7 @@
package eu.eudat.logic.proxy.config.configloaders; package eu.eudat.logic.proxy.config.configloaders;
import eu.eudat.logic.proxy.config.ExternalUrls; import eu.eudat.logic.proxy.config.ExternalUrls;
import eu.eudat.logic.proxy.config.Semantic; import eu.eudat.service.descriptiontemplate.Semantic;
import eu.eudat.models.data.pid.PidLinks; import eu.eudat.models.data.pid.PidLinks;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
@ -10,7 +10,6 @@ import java.util.Map;
public interface ConfigLoader { public interface ConfigLoader {
ExternalUrls getExternalUrls(); ExternalUrls getExternalUrls();
List<Semantic> getSemantics();
XWPFDocument getDocument(); XWPFDocument getDocument();
XWPFDocument getDatasetDocument(); XWPFDocument getDatasetDocument();
PidLinks getPidLinks(); PidLinks getPidLinks();

View File

@ -1,16 +1,15 @@
package eu.eudat.logic.proxy.config.configloaders; package eu.eudat.logic.proxy.config.configloaders;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.commons.config.filepath.FilePathsProperties;
import eu.eudat.logic.proxy.config.ExternalUrls; import eu.eudat.logic.proxy.config.ExternalUrls;
import eu.eudat.logic.proxy.config.Semantic; import eu.eudat.service.descriptiontemplate.Semantic;
import eu.eudat.models.data.pid.PidLinks; import eu.eudat.models.data.pid.PidLinks;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.slf4j.Logger; import org.slf4j.Logger;
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.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
@ -37,17 +36,17 @@ public class DefaultConfigLoader implements ConfigLoader {
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private ExternalUrls externalUrls; private ExternalUrls externalUrls;
private List<Semantic> semantics;
private XWPFDocument document; private XWPFDocument document;
private XWPFDocument datasetDocument; private XWPFDocument datasetDocument;
private PidLinks pidLinks; private PidLinks pidLinks;
private Map<String, String> keyToSourceMap; private Map<String, String> keyToSourceMap;
@Autowired @Autowired
private Environment environment; private FilePathsProperties config;
private void setExternalUrls() { private void setExternalUrls() {
String fileUrl = this.environment.getProperty("configuration.externalUrls"); String fileUrl = this.config.getExternalUrls();
logger.info("Loaded also config file: " + fileUrl); logger.info("Loaded also config file: " + fileUrl);
InputStream is = null; InputStream is = null;
try { try {
@ -66,21 +65,8 @@ public class DefaultConfigLoader implements ConfigLoader {
} }
} }
private void setSemantics() {
String filePath = environment.getProperty("configuration.semantics");
logger.info("Loaded also config file: " + filePath);
if (filePath != null) {
try {
semantics = mapper.readValue(getStreamFromPath(filePath), new TypeReference<List<Semantic>>(){});
}
catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
private void setDocument() { private void setDocument() {
String filePath = environment.getProperty("configuration.h2020template"); String filePath = this.config.getH2020template();
logger.info("Loaded also config file: " + filePath); logger.info("Loaded also config file: " + filePath);
InputStream is = null; InputStream is = null;
try { try {
@ -98,7 +84,7 @@ public class DefaultConfigLoader implements ConfigLoader {
} }
private void setDatasetDocument() { private void setDatasetDocument() {
String filePath = environment.getProperty("configuration.h2020datasettemplate"); String filePath = this.config.getH2020DatasetTemplate();
logger.info("Loaded also config file: " + filePath); logger.info("Loaded also config file: " + filePath);
InputStream is = null; InputStream is = null;
try { try {
@ -116,7 +102,7 @@ public class DefaultConfigLoader implements ConfigLoader {
} }
private void setPidLinks() { private void setPidLinks() {
String filePath = environment.getProperty("configuration.pid_links"); String filePath = this.config.getPidLinks();
logger.info("Loaded also config file: " + filePath); logger.info("Loaded also config file: " + filePath);
InputStream is = null; InputStream is = null;
try { try {
@ -135,7 +121,7 @@ public class DefaultConfigLoader implements ConfigLoader {
} }
private void setKeyToSourceMap() { private void setKeyToSourceMap() {
String filePath = this.environment.getProperty("configuration.externalUrls"); String filePath = this.config.getExternalUrls();
logger.info("Loaded also config file: " + filePath); logger.info("Loaded also config file: " + filePath);
Document doc = getXmlDocumentFromFilePath(filePath); Document doc = getXmlDocumentFromFilePath(filePath);
if (doc == null) { if (doc == null) {
@ -166,13 +152,7 @@ public class DefaultConfigLoader implements ConfigLoader {
return externalUrls; return externalUrls;
} }
public List<Semantic> getSemantics() {
if (semantics == null) {
semantics = new ArrayList<>();
this.setSemantics();
}
return semantics;
}
public XWPFDocument getDocument() { public XWPFDocument getDocument() {
this.setDocument(); this.setDocument();

View File

@ -1,9 +1,9 @@
configuration: file-paths:
externalUrls: externalUrls/ExternalUrls.xml externalUrls: externalUrls/ExternalUrls.xml
semantics: Semantics.json semantics: Semantics.json
h2020template: documents/h2020.docx h2020template: documents/h2020.docx
h2020datasettemplate: documents/h2020_dataset.docx h2020DatasetTemplate: documents/h2020_dataset.docx
pid_links: pidLinks.json pidLinks: pidLinks.json
userguide: userguide:
path: dmp-backend/web/src/main/resources/material/user-guide path: dmp-backend/web/src/main/resources/material/user-guide