2018-06-27 12:29:21 +02:00
|
|
|
package eu.eudat.logic.managers;
|
|
|
|
|
2019-02-06 12:10:44 +01:00
|
|
|
import eu.eudat.data.dao.entities.DatasetDao;
|
|
|
|
import eu.eudat.data.dao.entities.DatasetProfileDao;
|
2023-10-18 12:04:53 +02:00
|
|
|
import eu.eudat.data.old.DescriptionTemplate;
|
2023-10-05 13:12:39 +02:00
|
|
|
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
2019-02-25 17:50:43 +01:00
|
|
|
import eu.eudat.exceptions.datasetprofile.DatasetProfileWithDatasetsExeption;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.logic.builders.entity.DatasetProfileBuilder;
|
|
|
|
import eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.ViewStyleModel;
|
|
|
|
import eu.eudat.models.data.admin.composite.DatasetProfile;
|
|
|
|
import eu.eudat.logic.services.ApiContext;
|
|
|
|
import eu.eudat.logic.utilities.builders.ModelBuilder;
|
2023-10-20 18:13:57 +02:00
|
|
|
import eu.eudat.commons.types.xml.XmlBuilder;
|
2023-10-23 10:16:58 +02:00
|
|
|
import eu.eudat.service.descriptiontemplatetype.DescriptionTemplateTypeService;
|
2018-02-16 11:34:02 +01:00
|
|
|
import org.w3c.dom.Document;
|
|
|
|
import org.w3c.dom.Element;
|
2017-11-30 11:10:42 +01:00
|
|
|
|
2023-10-18 17:52:03 +02:00
|
|
|
import javax.management.InvalidApplicationException;
|
2018-02-16 11:34:02 +01:00
|
|
|
import java.util.Date;
|
2019-02-06 12:10:44 +01:00
|
|
|
import java.util.UUID;
|
2017-12-15 11:05:51 +01:00
|
|
|
|
2018-02-16 11:34:02 +01:00
|
|
|
public class AdminManager {
|
2018-02-16 08:45:18 +01:00
|
|
|
|
2023-10-05 13:12:39 +02:00
|
|
|
public static DescriptionTemplate generateViewStyleDefinition(DatasetProfile profile, ApiContext apiContext, DescriptionTemplateTypeService descriptionTemplateTypeService) throws Exception {
|
2018-02-16 08:45:18 +01:00
|
|
|
ViewStyleModel viewStyleModel = new ViewStyleModel();
|
2018-06-27 12:29:21 +02:00
|
|
|
viewStyleModel.setSections(new ModelBuilder().toViewStyleDefinition(profile.getSections(), eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Section.class));
|
|
|
|
viewStyleModel.setPages(new ModelBuilder().toViewStyleDefinition(profile.getPages(), eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Page.class));
|
2018-02-16 08:45:18 +01:00
|
|
|
Document viewStyleDoc = XmlBuilder.getDocument();
|
|
|
|
Element elementViewStyle = viewStyleModel.toXml(viewStyleDoc);
|
|
|
|
viewStyleDoc.appendChild(elementViewStyle);
|
|
|
|
String xml = XmlBuilder.generateXml(viewStyleDoc);
|
|
|
|
|
2020-06-17 11:30:54 +02:00
|
|
|
if (profile.getDescription() == null) {
|
|
|
|
profile.setDescription("");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (profile.getLanguage() == null) {
|
|
|
|
profile.setLanguage("en");
|
|
|
|
}
|
|
|
|
|
2023-10-05 13:12:39 +02:00
|
|
|
DescriptionTemplateTypeEntity type;
|
2023-10-02 09:14:14 +02:00
|
|
|
try {
|
2023-10-17 14:55:00 +02:00
|
|
|
//TODO: dtziotzios type = descriptionTemplateTypeService.getEntityByName(profile.getType());
|
2023-10-02 09:14:14 +02:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
throw new Exception("Description template type '" + profile.getType() + "' could not be found.");
|
|
|
|
}
|
|
|
|
|
2023-07-25 14:04:39 +02:00
|
|
|
DescriptionTemplate descriptionTemplate = apiContext.getOperationsContext().getBuilderFactory().getBuilder(DatasetProfileBuilder.class).definition(xml).label(profile.getLabel())
|
2020-06-03 11:13:31 +02:00
|
|
|
.status(profile.getStatus()).created(new Date()).description(profile.getDescription()).language(profile.getLanguage())
|
2023-10-17 14:55:00 +02:00
|
|
|
//TODO: dtziotzios .type(type)
|
2018-02-16 08:45:18 +01:00
|
|
|
.build();
|
|
|
|
|
2023-07-25 14:04:39 +02:00
|
|
|
if (descriptionTemplate.getGroupId() == null) {
|
|
|
|
descriptionTemplate.setGroupId(UUID.randomUUID());
|
2020-06-17 11:30:54 +02:00
|
|
|
}
|
|
|
|
|
2023-07-25 14:04:39 +02:00
|
|
|
if (descriptionTemplate.getVersion() == null) {
|
|
|
|
descriptionTemplate.setVersion((short)1);
|
2020-06-17 11:30:54 +02:00
|
|
|
}
|
|
|
|
|
2023-07-25 14:04:39 +02:00
|
|
|
return descriptionTemplate;
|
2018-02-16 08:45:18 +01:00
|
|
|
}
|
|
|
|
|
2023-07-25 14:04:39 +02:00
|
|
|
public static eu.eudat.models.data.admin.composite.DatasetProfile generateDatasetProfileModel(DescriptionTemplate profile) {
|
2018-02-16 08:45:18 +01:00
|
|
|
Document viewStyleDoc = XmlBuilder.fromXml(profile.getDefinition());
|
2018-02-16 11:34:02 +01:00
|
|
|
Element root = viewStyleDoc.getDocumentElement();
|
2018-06-27 12:29:21 +02:00
|
|
|
eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.ViewStyleModel viewstyle = new eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.ViewStyleModel().fromXml(root);
|
2018-02-16 08:45:18 +01:00
|
|
|
|
2018-06-27 12:29:21 +02:00
|
|
|
eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = new eu.eudat.models.data.admin.composite.DatasetProfile();
|
2018-02-16 08:45:18 +01:00
|
|
|
datasetprofile.buildProfile(viewstyle);
|
|
|
|
return datasetprofile;
|
|
|
|
}
|
2019-02-06 12:10:44 +01:00
|
|
|
|
|
|
|
|
2023-10-18 17:52:03 +02:00
|
|
|
public static DescriptionTemplate inactivate(DatasetProfileDao datasetProfileRepository, DatasetDao datasetDao, String id) throws InvalidApplicationException {
|
2019-02-06 12:10:44 +01:00
|
|
|
eu.eudat.data.dao.criteria.DatasetCriteria datasetsForThatDatasetProfile = new eu.eudat.data.dao.criteria.DatasetCriteria();
|
|
|
|
datasetsForThatDatasetProfile.setProfileDatasetId(UUID.fromString(id));
|
2019-02-25 17:50:43 +01:00
|
|
|
if (datasetDao.getWithCriteria(datasetsForThatDatasetProfile).count() == 0) {
|
2023-07-25 14:04:39 +02:00
|
|
|
DescriptionTemplate detasetProfile = datasetProfileRepository.find(UUID.fromString(id));
|
|
|
|
detasetProfile.setStatus(DescriptionTemplate.Status.DELETED.getValue());
|
2019-02-06 12:10:44 +01:00
|
|
|
detasetProfile = datasetProfileRepository.createOrUpdate(detasetProfile);
|
|
|
|
return detasetProfile;
|
2019-02-25 17:50:43 +01:00
|
|
|
} else {
|
|
|
|
throw new DatasetProfileWithDatasetsExeption("This profile can not deleted, because Datasets are associated with it");
|
2019-02-06 12:10:44 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-25 17:50:43 +01:00
|
|
|
}
|