When Exporting DMP to word/pdf sort it's Datasets based on creation date

This commit is contained in:
George Kalampokis 2022-06-07 10:56:44 +03:00
parent ea8407eece
commit 5cd79a6368
1 changed files with 9 additions and 7 deletions

View File

@ -97,7 +97,7 @@ import java.util.stream.Stream;
@Component @Component
public class DataManagementPlanManager { public class DataManagementPlanManager {
private static final Logger logger = LoggerFactory.getLogger(DataManagementPlanManager.class); private static final Logger logger = LoggerFactory.getLogger(DataManagementPlanManager.class);
private static final ObjectMapper objectMapper = new ObjectMapper(); private final ObjectMapper objectMapper;
private final Map<NotificationType, String> notificationPaths = Stream.of(new Object[][] { private final Map<NotificationType, String> notificationPaths = Stream.of(new Object[][] {
{NotificationType.DMP_MODIFIED, "/plans/edit"}, {NotificationType.DMP_MODIFIED, "/plans/edit"},
@ -125,6 +125,7 @@ public class DataManagementPlanManager {
this.userManager = userManager; this.userManager = userManager;
this.metricsManager = metricsManager; this.metricsManager = metricsManager;
this.configLoader = configLoader; this.configLoader = configLoader;
this.objectMapper = new ObjectMapper();
} }
/* /*
@ -1232,10 +1233,11 @@ public class DataManagementPlanManager {
.filter(item -> item.getStatus() != Dataset.Status.CANCELED.getValue()) .filter(item -> item.getStatus() != Dataset.Status.CANCELED.getValue())
.filter(item -> item.getStatus() != Dataset.Status.DELETED.getValue()) .filter(item -> item.getStatus() != Dataset.Status.DELETED.getValue())
.filter(item -> !isPublic && !isFinalized || item.getStatus() == Dataset.Status.FINALISED.getValue()) .filter(item -> !isPublic && !isFinalized || item.getStatus() == Dataset.Status.FINALISED.getValue())
.sorted(Comparator.comparing(Dataset::getCreated))
.forEach(datasetEntity -> { .forEach(datasetEntity -> {
Map<String, Object> properties = new HashMap<>(); Map<String, Object> properties = new HashMap<>();
if (datasetEntity.getProperties() != null) { if (datasetEntity.getProperties() != null) {
ObjectMapper objectMapper = new ObjectMapper(); //ObjectMapper objectMapper = new ObjectMapper();
try { try {
properties = objectMapper.readValue(datasetEntity.getProperties(), LinkedHashMap.class); properties = objectMapper.readValue(datasetEntity.getProperties(), LinkedHashMap.class);
} catch (IOException e) { } catch (IOException e) {
@ -1691,7 +1693,7 @@ public class DataManagementPlanManager {
dm.setAssociatedUsers(associatedUsers); // Sets associatedUsers property. dm.setAssociatedUsers(associatedUsers); // Sets associatedUsers property.
dm.setDynamicFields(dynamicFields); // Sets dynamicFields property. dm.setDynamicFields(dynamicFields); // Sets dynamicFields property.
dm.setDefinition(dmpProfile); dm.setDefinition(dmpProfile);
ObjectMapper mapper = new ObjectMapper(); //ObjectMapper mapper = new ObjectMapper();
Map<String, Object> extraPropertiesMap = new HashMap<>(); Map<String, Object> extraPropertiesMap = new HashMap<>();
if (dataManagementPlans.get(0).getLanguage() != null) { if (dataManagementPlans.get(0).getLanguage() != null) {
extraPropertiesMap.put("language", dataManagementPlans.get(0).getLanguage()); extraPropertiesMap.put("language", dataManagementPlans.get(0).getLanguage());
@ -1703,7 +1705,7 @@ public class DataManagementPlanManager {
extraPropertiesMap.put("publicDate", dataManagementPlans.get(0).getPublicDate()); extraPropertiesMap.put("publicDate", dataManagementPlans.get(0).getPublicDate());
} }
if (dataManagementPlans.get(0).getCosts() != null && !dataManagementPlans.get(0).getCosts().isEmpty()) { if (dataManagementPlans.get(0).getCosts() != null && !dataManagementPlans.get(0).getCosts().isEmpty()) {
extraPropertiesMap.put("costs", mapper.readValue(dataManagementPlans.get(0).getCosts(), ArrayList.class)); extraPropertiesMap.put("costs", objectMapper.readValue(dataManagementPlans.get(0).getCosts(), ArrayList.class));
} }
dm.setExtraProperties(extraPropertiesMap); dm.setExtraProperties(extraPropertiesMap);
@ -1734,7 +1736,7 @@ public class DataManagementPlanManager {
} catch (Exception ignored) { } catch (Exception ignored) {
dataset.setProfile(databaseRepository.getDatasetProfileDao().find(associatedProfiles.get(0).getId())); dataset.setProfile(databaseRepository.getDatasetProfileDao().find(associatedProfiles.get(0).getId()));
} }
dataset.setProperties(new ObjectMapper().writeValueAsString(das.getFieldImportModels())); dataset.setProperties(objectMapper.writeValueAsString(das.getFieldImportModels()));
dataset.setStatus((short) 0); dataset.setStatus((short) 0);
dataset.setRegistries(new HashSet<>()); dataset.setRegistries(new HashSet<>());
dataset.setDatasetDataRepositories(new HashSet<>()); dataset.setDatasetDataRepositories(new HashSet<>());
@ -2162,8 +2164,8 @@ public class DataManagementPlanManager {
} }
return finalDoi; return finalDoi;
} catch (HttpClientErrorException | HttpServerErrorException ex) { } catch (HttpClientErrorException | HttpServerErrorException ex) {
ObjectMapper ob = new ObjectMapper(); //ObjectMapper ob = new ObjectMapper();
Map<String, String> parsedException = ob.readValue(ex.getResponseBodyAsString(), HashMap.class); Map<String, String> parsedException = objectMapper.readValue(ex.getResponseBodyAsString(), HashMap.class);
throw new IOException(parsedException.get("message"), ex); throw new IOException(parsedException.get("message"), ex);
} }
} }