2020-03-20 17:20:22 +01:00
|
|
|
package eu.eudat.logic.managers;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import eu.eudat.data.entities.DMP;
|
|
|
|
import eu.eudat.models.rda.Dmp;
|
|
|
|
import eu.eudat.models.rda.RDAModel;
|
|
|
|
import eu.eudat.models.rda.mapper.DmpRDAMapper;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import javax.transaction.Transactional;
|
2020-03-26 17:39:25 +01:00
|
|
|
import java.io.IOException;
|
2020-03-20 17:20:22 +01:00
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
|
|
@Component
|
|
|
|
public class RDAManager {
|
|
|
|
|
|
|
|
private DmpRDAMapper dmpRDAMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
public RDAManager(DmpRDAMapper dmpRDAMapper) {
|
|
|
|
this.dmpRDAMapper = dmpRDAMapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
public String convertToRDA(DMP dmp) throws JsonProcessingException {
|
|
|
|
String result = "";
|
|
|
|
|
|
|
|
Dmp rdaDmp = dmpRDAMapper.toRDA(dmp);
|
|
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
2020-03-24 10:26:17 +01:00
|
|
|
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss Z"));
|
2020-03-20 17:20:22 +01:00
|
|
|
|
|
|
|
result = mapper.writeValueAsString(rdaDmp);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2020-03-26 17:39:25 +01:00
|
|
|
|
|
|
|
public DMP convertToEntity(String json) throws IOException {
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss Z"));
|
|
|
|
|
|
|
|
Dmp rda = mapper.readValue(json, Dmp.class);
|
|
|
|
return dmpRDAMapper.toEntity(rda);
|
|
|
|
}
|
2020-03-20 17:20:22 +01:00
|
|
|
}
|