|
|
|
@ -1,10 +1,14 @@
|
|
|
|
|
package eu.eudat.models.rda.mapper;
|
|
|
|
|
|
|
|
|
|
import eu.eudat.data.dao.criteria.GrantCriteria;
|
|
|
|
|
import eu.eudat.data.entities.Funder;
|
|
|
|
|
import eu.eudat.data.entities.Grant;
|
|
|
|
|
import eu.eudat.logic.services.ApiContext;
|
|
|
|
|
import eu.eudat.models.rda.Funding;
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
public class FundingRDAMapper {
|
|
|
|
|
|
|
|
|
|
public static Funding toRDA(Grant grant) {
|
|
|
|
@ -27,6 +31,29 @@ public class FundingRDAMapper {
|
|
|
|
|
public static Grant toEntity(Funding rda, ApiContext apiContext) {
|
|
|
|
|
GrantCriteria criteria = new GrantCriteria();
|
|
|
|
|
criteria.setReference(rda.getGrantId().getIdentifier());
|
|
|
|
|
return apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getWithCriteria(criteria).getSingle();
|
|
|
|
|
Grant grant;
|
|
|
|
|
try {
|
|
|
|
|
grant = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getWithCriteria(criteria).getSingle();
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
grant = new Grant();
|
|
|
|
|
grant.setId(UUID.randomUUID());
|
|
|
|
|
grant.setLabel(rda.getGrantId().getIdentifier());
|
|
|
|
|
grant.setStatus((short)1);
|
|
|
|
|
grant.setCreated(new Date());
|
|
|
|
|
grant.setModified(new Date());
|
|
|
|
|
grant.setType(0);
|
|
|
|
|
grant.setFunder(new Funder());
|
|
|
|
|
grant.getFunder().setId(UUID.randomUUID());
|
|
|
|
|
grant.getFunder().setLabel(rda.getFunderId().getIdentifier());
|
|
|
|
|
grant.getFunder().setStatus((short)1);
|
|
|
|
|
grant.getFunder().setCreated(new Date());
|
|
|
|
|
grant.getFunder().setModified(new Date());
|
|
|
|
|
grant.getFunder().setType(0);
|
|
|
|
|
grant.getFunder().setReference(rda.getFunderId().getType().toString()+"::"+rda.getFunderId().getIdentifier());
|
|
|
|
|
grant.setReference(rda.getGrantId().getType().toString()+"::"+rda.getGrantId().getIdentifier());
|
|
|
|
|
Funder funder = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().createOrUpdate(grant.getFunder());
|
|
|
|
|
grant = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(grant);
|
|
|
|
|
}
|
|
|
|
|
return grant;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|