changes in dmp deposit model
This commit is contained in:
parent
969df0357a
commit
376bb2ca53
|
@ -1,29 +1,45 @@
|
||||||
package eu.eudat.logic.security.repositorydeposit.mapper;
|
package eu.eudat.logic.security.repositorydeposit.mapper;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.data.entities.*;
|
import eu.eudat.data.entities.*;
|
||||||
import eu.eudat.depositinterface.models.*;
|
import eu.eudat.depositinterface.models.*;
|
||||||
import org.springframework.http.ResponseEntity;
|
import eu.eudat.logic.utilities.builders.XmlBuilder;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
import javax.xml.xpath.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DMPToDepositMapper {
|
public class DMPToDepositMapper {
|
||||||
|
|
||||||
public static DMPDepositModel fromDMP(DMP entity, File pdfFile, String fileName, ResponseEntity<byte[]> jsonFile, File supportingFilesZip, String previousDOI) {
|
private static final Logger logger = LoggerFactory.getLogger(DMPToDepositMapper.class);
|
||||||
|
private static final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
|
public static DMPDepositModel fromDMP(DMP entity, FileEnvelope pdfFile, FileEnvelope jsonFile, File supportingFilesZip, String previousDOI) {
|
||||||
DMPDepositModel deposit = new DMPDepositModel();
|
DMPDepositModel deposit = new DMPDepositModel();
|
||||||
deposit.setId(entity.getId());
|
deposit.setId(entity.getId());
|
||||||
deposit.setVersion(entity.getVersion());
|
deposit.setVersion(entity.getVersion());
|
||||||
deposit.setLabel(entity.getLabel());
|
deposit.setLabel(entity.getLabel());
|
||||||
deposit.setDescription(entity.getDescription());
|
deposit.setDescription(entity.getDescription());
|
||||||
deposit.setPublic(entity.isPublic());
|
deposit.setPublic(entity.isPublic());
|
||||||
|
deposit.setDatasets(entity.getDataset().stream().map(DMPToDepositMapper::fromDataset).collect(Collectors.toList()));
|
||||||
deposit.setUsers(entity.getUsers().stream().map(DMPToDepositMapper::fromUserDMP).collect(Collectors.toSet()));
|
deposit.setUsers(entity.getUsers().stream().map(DMPToDepositMapper::fromUserDMP).collect(Collectors.toSet()));
|
||||||
deposit.setOrganisations(entity.getOrganisations().stream().map(DMPToDepositMapper::fromOrganisation).collect(Collectors.toSet()));
|
deposit.setOrganisations(entity.getOrganisations().stream().map(DMPToDepositMapper::fromOrganisation).collect(Collectors.toSet()));
|
||||||
deposit.setResearchers(entity.getResearchers().stream().map(DMPToDepositMapper::fromResearcher).collect(Collectors.toSet()));
|
deposit.setResearchers(entity.getResearchers().stream().map(DMPToDepositMapper::fromResearcher).collect(Collectors.toSet()));
|
||||||
deposit.setGrant(fromGrant(entity.getGrant()));
|
deposit.setGrant(fromGrant(entity.getGrant()));
|
||||||
|
|
||||||
deposit.setPdfFile(pdfFile);
|
deposit.setPdfFile(pdfFile);
|
||||||
deposit.setPdfFileName(fileName);
|
deposit.setRdaJsonFile(jsonFile);
|
||||||
deposit.setRdaJson(jsonFile);
|
|
||||||
deposit.setSupportingFilesZip(supportingFilesZip);
|
deposit.setSupportingFilesZip(supportingFilesZip);
|
||||||
deposit.setPreviousDOI(previousDOI);
|
deposit.setPreviousDOI(previousDOI);
|
||||||
|
|
||||||
|
@ -31,6 +47,54 @@ public class DMPToDepositMapper {
|
||||||
return deposit;
|
return deposit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static DatasetDepositModel fromDataset(Dataset entity){
|
||||||
|
DatasetDepositModel deposit = new DatasetDepositModel();
|
||||||
|
deposit.setLabel(entity.getLabel());
|
||||||
|
deposit.setDescription(entity.getDescription());
|
||||||
|
deposit.setProfileDefinition(entity.getProfile().getDefinition());
|
||||||
|
deposit.setProperties(entity.getProperties());
|
||||||
|
deposit.setFields(fromDefinitionAndProperties(deposit.getProfileDefinition(), deposit.getProperties()));
|
||||||
|
return deposit;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<DatasetFieldsDepositModel> fromDefinitionAndProperties(String definition, String properties){
|
||||||
|
List<DatasetFieldsDepositModel> deposit = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
|
||||||
|
Map<String, Object> datasetAnswers = mapper.readValue(properties, HashMap.class);
|
||||||
|
|
||||||
|
Document document = XmlBuilder.fromXml(definition);
|
||||||
|
XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||||
|
XPath xpath = xpathFactory.newXPath();
|
||||||
|
XPathExpression expr = xpath.compile("//schematics");
|
||||||
|
NodeList schematics = (NodeList) expr.evaluate(document, XPathConstants.NODESET);
|
||||||
|
for (int i = 0; i < schematics.getLength(); i++) {
|
||||||
|
Node schematicsNode = schematics.item(i);
|
||||||
|
NodeList schematicsList = schematicsNode.getChildNodes();
|
||||||
|
DatasetFieldsDepositModel fieldDeposit = new DatasetFieldsDepositModel();
|
||||||
|
List<String> schematicsDeposit = new ArrayList<>();
|
||||||
|
if(schematicsList != null){
|
||||||
|
for(int j = 0; j < schematicsList.getLength(); j++){
|
||||||
|
Node schematic = schematicsList.item(j);
|
||||||
|
if(schematic.getTextContent().matches(".*\\w+.*")) {
|
||||||
|
schematicsDeposit.add(schematic.getTextContent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldDeposit.setSchematics(schematicsDeposit);
|
||||||
|
String fieldId = schematicsNode.getParentNode().getAttributes().getNamedItem("id").getNodeValue();
|
||||||
|
String value = (String) datasetAnswers.get(fieldId);
|
||||||
|
fieldDeposit.setValue(value);
|
||||||
|
deposit.add(fieldDeposit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (XPathExpressionException | JsonProcessingException ex){
|
||||||
|
logger.error(ex.getMessage(), ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return deposit;
|
||||||
|
}
|
||||||
|
|
||||||
private static UserDMPDepositModel fromUserDMP(UserDMP entity){
|
private static UserDMPDepositModel fromUserDMP(UserDMP entity){
|
||||||
UserDMPDepositModel deposit = new UserDMPDepositModel();
|
UserDMPDepositModel deposit = new UserDMPDepositModel();
|
||||||
deposit.setUser(fromUserInfo(entity.getUser()));
|
deposit.setUser(fromUserInfo(entity.getUser()));
|
||||||
|
|
Loading…
Reference in New Issue