Fetching dois for dmps for public API

This commit is contained in:
Thomas Georgios Giannos 2023-11-28 17:29:25 +02:00
parent d3d57e8838
commit b3bc801cd4
4 changed files with 16 additions and 44 deletions

View File

@ -1,6 +1,8 @@
package eu.eudat.model.mapper.publicapi; package eu.eudat.model.mapper.publicapi;
import eu.eudat.data.EntityDoiEntity;
import eu.eudat.model.Dmp; import eu.eudat.model.Dmp;
import eu.eudat.model.publicapi.doi.DoiPublicModel;
import eu.eudat.model.publicapi.grant.GrantPublicOverviewModel; import eu.eudat.model.publicapi.grant.GrantPublicOverviewModel;
import eu.eudat.model.publicapi.organisation.OrganizationPublicModel; import eu.eudat.model.publicapi.organisation.OrganizationPublicModel;
import eu.eudat.model.publicapi.overviewmodels.DataManagementPlanPublicModel; import eu.eudat.model.publicapi.overviewmodels.DataManagementPlanPublicModel;
@ -9,12 +11,13 @@ import eu.eudat.model.publicapi.user.UserInfoPublicModel;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.sql.Date; import java.sql.Date;
import java.util.List;
import java.util.Objects; import java.util.Objects;
@Component @Component
public class DmpToPublicApiDmpMapper { public class DmpToPublicApiDmpMapper {
public DataManagementPlanPublicModel toPublicModel(Dmp dmp) { public DataManagementPlanPublicModel toPublicModel(Dmp dmp, List<EntityDoiEntity> doiEntities) {
DataManagementPlanPublicModel model = new DataManagementPlanPublicModel(); DataManagementPlanPublicModel model = new DataManagementPlanPublicModel();
model.setId(dmp.getId().toString()); model.setId(dmp.getId().toString());
model.setLabel(dmp.getLabel()); model.setLabel(dmp.getLabel());
@ -26,6 +29,8 @@ public class DmpToPublicApiDmpMapper {
model.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::isNull).toList()); model.setResearchers(dmp.getDmpReferences().stream().map(ResearcherPublicModel::fromDmpReference).filter(Objects::isNull).toList());
model.setGrant(GrantPublicOverviewModel.fromDmpReferences(dmp.getDmpReferences())); model.setGrant(GrantPublicOverviewModel.fromDmpReferences(dmp.getDmpReferences()));
model.setOrganisations(dmp.getDmpReferences().stream().map(OrganizationPublicModel::fromDmpReference).filter(Objects::isNull).toList()); model.setOrganisations(dmp.getDmpReferences().stream().map(OrganizationPublicModel::fromDmpReference).filter(Objects::isNull).toList());
List<DoiPublicModel> dois = doiEntities.stream().map(DoiPublicModel::fromDataModel).toList();
model.setDois(dois);
model.setCreatedAt(Date.from(dmp.getCreatedAt())); model.setCreatedAt(Date.from(dmp.getCreatedAt()));
model.setModifiedAt(Date.from(dmp.getUpdatedAt())); model.setModifiedAt(Date.from(dmp.getUpdatedAt()));

View File

@ -30,26 +30,11 @@ public class DoiPublicModel {
this.doi = doi; this.doi = doi;
} }
public DoiPublicModel fromDataModel(EntityDoiEntity entity) { public static DoiPublicModel fromDataModel(EntityDoiEntity entity) {
this.id = entity.getId(); DoiPublicModel model = new DoiPublicModel();
this.repositoryId = entity.getRepositoryId(); model.setId(entity.getId());
this.doi = entity.getDoi(); model.setRepositoryId(entity.getRepositoryId());
return this; model.setDoi(entity.getDoi());
} return model;
public EntityDoiEntity toDataModel() throws Exception {
EntityDoiEntity entity = new EntityDoiEntity();
entity.setId(this.getId());
entity.setRepositoryId(this.getRepositoryId());
entity.setDoi(this.getDoi());
return entity;
}
public String generateLabel() {
return this.getDoi();
}
public String getHint() {
return null;
} }
} }

View File

@ -109,25 +109,4 @@ public class GrantPublicOverviewModel {
return null; return null;
} }
public GrantPublicOverviewModel fromDataModel(Grant entity) {
this.id = entity.getId();
this.label = entity.getLabel();
this.abbreviation = entity.getAbbreviation();
this.description = entity.getDescription();
this.startDate = entity.getStartdate();
this.endDate = entity.getEnddate();
this.uri = entity.getUri();
this.funder = new FunderPublicOverviewModel();
if (entity.getFunder() != null)
this.funder.fromDataModel(entity.getFunder());
return this;
}
public Grant toDataModel() throws Exception {
return null;
}
public String getHint() {
return null;
}
} }

View File

@ -11,10 +11,12 @@ import eu.eudat.model.*;
import eu.eudat.model.builder.DmpBuilder; import eu.eudat.model.builder.DmpBuilder;
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpListingMapper; import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpListingMapper;
import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpMapper; import eu.eudat.model.mapper.publicapi.DmpToPublicApiDmpMapper;
import eu.eudat.model.publicapi.doi.DoiPublicModel;
import eu.eudat.model.publicapi.listingmodels.DataManagementPlanPublicListingModel; import eu.eudat.model.publicapi.listingmodels.DataManagementPlanPublicListingModel;
import eu.eudat.model.publicapi.overviewmodels.DataManagementPlanPublicModel; import eu.eudat.model.publicapi.overviewmodels.DataManagementPlanPublicModel;
import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.query.DmpQuery; import eu.eudat.query.DmpQuery;
import eu.eudat.query.EntityDoiQuery;
import eu.eudat.query.lookup.DmpLookup; import eu.eudat.query.lookup.DmpLookup;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
@ -173,7 +175,8 @@ public class PublicDmpsDocumentation extends BaseController {
Dmp model = this.builderFactory.builder(DmpBuilder.class).build(fieldSet, query.firstAs(fieldSet)); Dmp model = this.builderFactory.builder(DmpBuilder.class).build(fieldSet, query.firstAs(fieldSet));
if (model == null) if (model == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale())); throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
DataManagementPlanPublicModel dataManagementPlan = this.dmpToPublicApiDmpMapper.toPublicModel(model); EntityDoiQuery entityDoiQuery = this.queryFactory.query(EntityDoiQuery.class).entityIds(UUID.fromString(id)).isActive(IsActive.Active);
DataManagementPlanPublicModel dataManagementPlan = this.dmpToPublicApiDmpMapper.toPublicModel(model, entityDoiQuery.collect());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
} }