add more to external reference controller, service
This commit is contained in:
parent
079382556f
commit
7df098a010
|
@ -36,4 +36,9 @@ public class AuditableAction {
|
|||
public static final EventId Description_Persist = new EventId(6002, "Description_Persist");
|
||||
public static final EventId Description_Delete = new EventId(6003, "Description_Delete");
|
||||
|
||||
public static final EventId External_Reference_Query = new EventId(7000, "External_Reference_Query");
|
||||
public static final EventId External_Reference_Lookup = new EventId(7001, "External_Reference_Lookup");
|
||||
public static final EventId External_Reference_Persist = new EventId(7002, "External_Reference_Persist");
|
||||
public static final EventId External_Reference_Delete = new EventId(7003, "External_Reference_Delete");
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import jakarta.persistence.Table;
|
|||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
@Table(name = "\"ExternalReference\"")
|
||||
@Table(name = "\"DmpExternalReference\"")
|
||||
public class DmpExternalReferenceEntity {
|
||||
|
||||
@Id
|
||||
|
|
|
@ -5,6 +5,7 @@ import eu.eudat.commons.enums.IsActive;
|
|||
import eu.eudat.commons.enums.SourceType;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ExternalReference {
|
||||
|
@ -48,6 +49,9 @@ public class ExternalReference {
|
|||
//private UserInfo createdBy; ToDo
|
||||
//public static final String _createdBy = "createdBy";
|
||||
|
||||
private List<DmpExternalReference> dmpExternalReferences;
|
||||
public static final String _dmpExternalReferences = "dmpExternalReferences";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -144,4 +148,11 @@ public class ExternalReference {
|
|||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
public List<DmpExternalReference> getDmpExternalReferences() {
|
||||
return dmpExternalReferences;
|
||||
}
|
||||
|
||||
public void setDmpExternalReferences(List<DmpExternalReference> dmpExternalReferences) {
|
||||
this.dmpExternalReferences = dmpExternalReferences;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,13 @@ package eu.eudat.model.builder;
|
|||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.ExternalReferenceEntity;
|
||||
import eu.eudat.model.DmpExternalReference;
|
||||
import eu.eudat.model.ExternalReference;
|
||||
import eu.eudat.query.DmpExternalReferenceQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import gr.cite.tools.logging.DataLogEntry;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
|
@ -16,20 +20,23 @@ import org.springframework.context.annotation.Scope;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class ExternalReferenceBuilder extends BaseBuilder<ExternalReference, ExternalReferenceEntity>{
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final QueryFactory queryFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public ExternalReferenceBuilder(
|
||||
ConventionService conventionService,
|
||||
BuilderFactory builderFactory) {
|
||||
BuilderFactory builderFactory, QueryFactory queryFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ExternalReferenceBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
public ExternalReferenceBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
|
@ -43,7 +50,11 @@ public class ExternalReferenceBuilder extends BaseBuilder<ExternalReference, Ext
|
|||
this.logger.trace(new DataLogEntry("requested fields", fields));
|
||||
if (fields == null || data == null || fields.isEmpty())
|
||||
return new ArrayList<>();
|
||||
// FieldSet userInfoFields = fields.extractPrefixed(this.asPrefix(ExternalReference._createdBy));
|
||||
|
||||
//FieldSet userInfoFields = fields.extractPrefixed(this.asPrefix(ExternalReference._createdBy));
|
||||
|
||||
FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asPrefix(ExternalReference._dmpExternalReferences));
|
||||
Map<UUID, List<DmpExternalReference>> dmpExternalReferenceMap = this.collectDmpExternalReferences(dmpExternalReferencesFields, data);
|
||||
|
||||
List<ExternalReference> models = new ArrayList<>();
|
||||
for (ExternalReferenceEntity d : data) {
|
||||
|
@ -60,13 +71,31 @@ public class ExternalReferenceBuilder extends BaseBuilder<ExternalReference, Ext
|
|||
if (fields.hasField(this.asIndexer(ExternalReference._source))) m.setSource(d.getSource());
|
||||
if (fields.hasField(this.asIndexer(ExternalReference._sourceType))) m.setSourceType(d.getSourceType());
|
||||
if (fields.hasField(this.asIndexer(ExternalReference._type))) m.setType(d.getType());
|
||||
|
||||
// if (!userInfoFields.isEmpty() && d.getCreatedBy() != null){
|
||||
// //Todo
|
||||
// //ToDo
|
||||
// }
|
||||
if (!dmpExternalReferenceMap.isEmpty() && dmpExternalReferenceMap != null && dmpExternalReferenceMap.containsKey(d.getId())) m.setDmpExternalReferences(dmpExternalReferenceMap.get(d.getId()));
|
||||
models.add(m);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, List<DmpExternalReference>> collectDmpExternalReferences(FieldSet fields, List<ExternalReferenceEntity> datas) throws MyApplicationException {
|
||||
if (fields.isEmpty() || datas.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", DmpExternalReference.class.getSimpleName());
|
||||
|
||||
Map<UUID, List<DmpExternalReference>> itemMap = null;
|
||||
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DmpExternalReference._externalReference, ExternalReference._id));
|
||||
DmpExternalReferenceQuery query = this.queryFactory.query(DmpExternalReferenceQuery.class).authorize(this.authorize).referenceIds(datas.stream().map(x -> x.getId()).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(DmpExternalReferenceBuilder.class).authorize(this.authorize).authorize(this.authorize).asMasterKey(query, clone, x -> x.getExternalReference().getId());
|
||||
|
||||
if (!fields.hasField(this.asIndexer(DmpExternalReference._externalReference, ExternalReference._id))) {
|
||||
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getExternalReference() != null).map(x -> {
|
||||
x.getExternalReference().setId(null);
|
||||
return x;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
return itemMap;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,7 @@ package eu.eudat.model.censorship;
|
|||
|
||||
import eu.eudat.authorization.Permission;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.DmpBlueprint;
|
||||
import eu.eudat.model.ExternalReference;
|
||||
import eu.eudat.model.censorship.dmpblueprintdefinition.DefinitionCensor;
|
||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||
import gr.cite.tools.data.censor.CensorFactory;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
|
@ -40,6 +38,8 @@ public class ExternalReferenceCensor extends BaseCensor {
|
|||
return;
|
||||
|
||||
this.authService.authorizeForce(Permission.BrowseExternalReference);
|
||||
FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(ExternalReference._dmpExternalReferences));
|
||||
this.censorFactory.censor(DmpExternalReferenceCensor.class).censor(dmpExternalReferencesFields, userId);
|
||||
//ToDo
|
||||
//FieldSet definitionFields = fields.extractPrefixed(this.asIndexerPrefix(ExternalReference._createdBy));
|
||||
//this.censorFactory.censor(UserInfo.class).censor(definitionFields, userId);
|
||||
|
|
|
@ -156,7 +156,9 @@ public class ExternalReferenceQuery extends QueryBase<ExternalReferenceEntity> {
|
|||
predicates.add(inClause);
|
||||
}
|
||||
if (this.like != null && !this.like.isEmpty()) {
|
||||
predicates.add(queryContext.CriteriaBuilder.like(queryContext.Root.get(ExternalReferenceEntity._label), this.like));
|
||||
predicates.add(queryContext.CriteriaBuilder.or(queryContext.CriteriaBuilder.like(queryContext.Root.get(ExternalReferenceEntity._label), this.like),
|
||||
queryContext.CriteriaBuilder.like(queryContext.Root.get(ExternalReferenceEntity._description), this.like)
|
||||
));
|
||||
}
|
||||
if (this.isActives != null) {
|
||||
CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._isActive));
|
||||
|
@ -177,7 +179,7 @@ public class ExternalReferenceQuery extends QueryBase<ExternalReferenceEntity> {
|
|||
predicates.add(inClause);
|
||||
}
|
||||
if (this.excludedIds != null) {
|
||||
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpBlueprintEntity._id));
|
||||
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._id));
|
||||
for (UUID item : this.excludedIds)
|
||||
notInClause.value(item);
|
||||
predicates.add(notInClause.not());
|
||||
|
@ -205,7 +207,7 @@ public class ExternalReferenceQuery extends QueryBase<ExternalReferenceEntity> {
|
|||
item.setSource(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._source, String.class));
|
||||
item.setSourceType(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._sourceType, SourceType.class));
|
||||
item.setType(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._type, ExternalReferencesType.class));
|
||||
//item.setCreatedBy(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._createdBy, UUID.class));
|
||||
item.setCreatedBy(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._createdBy, UUID.class));
|
||||
return item;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,171 @@
|
|||
package eu.eudat.controllers.v2;
|
||||
|
||||
import eu.eudat.audit.AuditableAction;
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.authorization.Permission;
|
||||
import eu.eudat.commons.enums.ExternalReferencesType;
|
||||
import eu.eudat.controllers.BaseController;
|
||||
import eu.eudat.data.ExternalReferenceEntity;
|
||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.externalreferences.ExternalReferenceService;
|
||||
import eu.eudat.model.ExternalReference;
|
||||
import eu.eudat.model.builder.ExternalReferenceBuilder;
|
||||
import eu.eudat.model.censorship.ExternalReferenceCensor;
|
||||
import eu.eudat.model.result.QueryResult;
|
||||
import eu.eudat.models.data.FetcherExternalReference;
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
import eu.eudat.query.ExternalReferenceQuery;
|
||||
import eu.eudat.query.lookup.ExternalReferenceLookup;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||
import gr.cite.tools.auditing.AuditService;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.censor.CensorFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.exception.MyForbiddenException;
|
||||
import gr.cite.tools.exception.MyNotFoundException;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import gr.cite.tools.logging.MapLogEntry;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.management.InvalidApplicationException;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(path = {"api/external-references"})
|
||||
public class ExternalReferenceController extends BaseController {
|
||||
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalReferenceController.class));
|
||||
private final BuilderFactory builderFactory;
|
||||
private final AuditService auditService;
|
||||
private final ExternalReferenceService externalReferenceService;
|
||||
private final CensorFactory censorFactory;
|
||||
private final QueryFactory queryFactory;
|
||||
private final MessageSource messageSource;
|
||||
private final AuthorizationService authorizationService;
|
||||
|
||||
@Autowired
|
||||
public ExternalReferenceController(
|
||||
ApiContext apiContext,
|
||||
BuilderFactory builderFactory,
|
||||
ExternalReferenceService externalReferenceService,
|
||||
AuditService auditService,
|
||||
CensorFactory censorFactory,
|
||||
QueryFactory queryFactory,
|
||||
MessageSource messageSource, AuthorizationService authorizationService) {
|
||||
super(apiContext);
|
||||
this.builderFactory = builderFactory;
|
||||
this.externalReferenceService = externalReferenceService;
|
||||
this.auditService = auditService;
|
||||
this.censorFactory = censorFactory;
|
||||
this.queryFactory = queryFactory;
|
||||
this.messageSource = messageSource;
|
||||
this.authorizationService = authorizationService;
|
||||
}
|
||||
|
||||
@PostMapping("query")
|
||||
public QueryResult<ExternalReference> query(@RequestBody ExternalReferenceLookup lookup) throws MyApplicationException, MyForbiddenException {
|
||||
logger.debug("querying {}", ExternalReference.class.getSimpleName());
|
||||
|
||||
this.censorFactory.censor(ExternalReferenceCensor.class).censor(lookup.getProject(), null);
|
||||
|
||||
ExternalReferenceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission);
|
||||
List<ExternalReferenceEntity> datas = query.collectAs(lookup.getProject());
|
||||
List<ExternalReference> models = this.builderFactory.builder(ExternalReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), datas);
|
||||
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
|
||||
|
||||
this.auditService.track(AuditableAction.External_Reference_Query, "lookup", lookup);
|
||||
|
||||
return new QueryResult(models, count);
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
public ExternalReference get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
|
||||
logger.debug(new MapLogEntry("retrieving" + eu.eudat.model.ExternalReference.class.getSimpleName()).And("id", id).And("fields", fieldSet));
|
||||
|
||||
this.censorFactory.censor(ExternalReferenceCensor.class).censor(fieldSet, null);
|
||||
|
||||
ExternalReferenceQuery query = this.queryFactory.query(ExternalReferenceQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id);
|
||||
ExternalReference model = this.builderFactory.builder(ExternalReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet));
|
||||
if (model == null)
|
||||
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, eu.eudat.model.ExternalReference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
|
||||
this.auditService.track(AuditableAction.External_Reference_Lookup, Map.ofEntries(
|
||||
new AbstractMap.SimpleEntry<String, Object>("id", id),
|
||||
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
|
||||
));
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@GetMapping(path = {"search/{externalType}"}, produces = "application/json")
|
||||
public @ResponseBody ResponseEntity<ResponseItem<List<FetcherExternalReference>>> searchExternalReference(@PathVariable(value = "externalType") int externalType,
|
||||
@RequestParam(value = "query", required = false) String query,
|
||||
@RequestParam(value = "type", required = false) String type
|
||||
) throws HugeResultSet, NoURLFound, InvalidApplicationException {
|
||||
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
||||
ExternalReferencesType externalReferencesType = ExternalReferencesType.of((short) externalType);
|
||||
|
||||
List<FetcherExternalReference> fetcherExternalReferences = this.externalReferenceService.searchExternalReference(externalReferencesType, query, type);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<FetcherExternalReference>>().status(ApiMessageCode.NO_MESSAGE).payload(fetcherExternalReferences));
|
||||
}
|
||||
|
||||
@DeleteMapping("{id}")
|
||||
@Transactional
|
||||
public void delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException {
|
||||
logger.debug(new MapLogEntry("retrieving" + ExternalReference.class.getSimpleName()).And("id", id));
|
||||
|
||||
this.externalReferenceService.deleteAndSave(id);
|
||||
|
||||
this.auditService.track(AuditableAction.External_Reference_Delete, "id", id);
|
||||
}
|
||||
|
||||
|
||||
// @Transactional
|
||||
// @PostMapping(path = {"persist"}, consumes = "application/json", produces = "application/json")
|
||||
// public @ResponseBody
|
||||
// ResponseEntity<ResponseItem<ExternalReference>> createExternalReferecnes(@RequestBody ExternalReference externalReference) throws Exception {
|
||||
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
||||
//
|
||||
// ExternalReference newExternalReference = this.externalReferencesService.createDataRepo(externalReference);
|
||||
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
// @GetMapping(path = {"{externalType}"}, produces = "application/json")
|
||||
// public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference2>>> listExternalReferecnes2(@RequestParam(value = "externalType") String externalType, @RequestParam(value = "query", required = false) String query,
|
||||
// @RequestParam(value = "type", required = false) String type
|
||||
// ) throws HugeResultSet, NoURLFound, InvalidApplicationException {
|
||||
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
||||
//
|
||||
// List<ExternalReference2> externalReferences = this.externalReferencesService.getExternalReference2(externalType, query, type);
|
||||
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalReference2>>().status(ApiMessageCode.NO_MESSAGE).payload(externalReferences));
|
||||
// }
|
||||
//
|
||||
// @Transactional
|
||||
// @PostMapping(value = {"{externalType}/persist"}, consumes = "application/json", produces = "application/json")
|
||||
// public @ResponseBody
|
||||
// ResponseEntity<ResponseItem<ExternalReference2>> create(@RequestBody ExternalReference2 externalReference) throws Exception {
|
||||
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
||||
//
|
||||
// ExternalReference2 newExternalReference = this.externalReferencesService.create(externalReference);
|
||||
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference2>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||
// }
|
||||
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
package eu.eudat.controllers.v2;
|
||||
|
||||
import eu.eudat.authorization.Permission;
|
||||
import eu.eudat.commons.enums.ExternalReferencesType;
|
||||
import eu.eudat.controllers.BaseController;
|
||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.externalreferences.ExternalReferencesService;
|
||||
import eu.eudat.logic.services.externalreferences.FunderService;
|
||||
import eu.eudat.logic.services.externalreferences.ProjectService;
|
||||
import eu.eudat.models.data.ExternalReference;
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.management.InvalidApplicationException;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(path = {"api/external-references"})
|
||||
public class ExternalReferencesController extends BaseController {
|
||||
|
||||
private final FunderService funderService;
|
||||
private final ExternalReferencesService externalReferencesService;
|
||||
private final ProjectService projectService;
|
||||
private final AuthorizationService authorizationService;
|
||||
|
||||
@Autowired
|
||||
public ExternalReferencesController(
|
||||
ApiContext apiContext,
|
||||
FunderService funderService,
|
||||
ExternalReferencesService externalReferencesService,
|
||||
ProjectService projectService,
|
||||
AuthorizationService authorizationService) {
|
||||
super(apiContext);
|
||||
this.funderService = funderService;
|
||||
this.externalReferencesService = externalReferencesService;
|
||||
this.projectService = projectService;
|
||||
this.authorizationService = authorizationService;
|
||||
}
|
||||
|
||||
// @PostMapping(path = {"funders"}, consumes = "application/json", produces = "application/json")
|
||||
// public @ResponseBody ResponseEntity<ResponseItem<List<Funder>>> getWithExternal(@RequestBody FunderCriteriaRequest funderCriteria) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException, InvalidApplicationException {
|
||||
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
||||
//
|
||||
// List<Funder> dataTable = this.funderService.getCriteriaWithExternal(funderCriteria);
|
||||
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Funder>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
||||
// }
|
||||
//
|
||||
// @PostMapping(path = {"projects"}, consumes = "application/json", produces = "application/json")
|
||||
// public @ResponseBody
|
||||
// ResponseEntity<ResponseItem<List<Project>>> getWithExternal(@RequestBody ProjectCriteriaRequest projectCriteria) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException, InvalidApplicationException {
|
||||
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
||||
//
|
||||
// List<Project> dataTable = this.projectService.getCriteriaWithExternal(projectCriteria);
|
||||
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@GetMapping(path = {"{externalType}"}, produces = "application/json")
|
||||
public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference>>> listExternalReferecnes(@PathVariable(value = "externalType") int externalType,
|
||||
@RequestParam(value = "query", required = false) String query,
|
||||
@RequestParam(value = "type", required = false) String type
|
||||
) throws HugeResultSet, NoURLFound, InvalidApplicationException {
|
||||
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
||||
ExternalReferencesType externalReferencesType = ExternalReferencesType.of((short) externalType);
|
||||
|
||||
List<ExternalReference> externalReferences = this.externalReferencesService.getExternalReference(externalReferencesType, query, type);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalReference>>().status(ApiMessageCode.NO_MESSAGE).payload(externalReferences));
|
||||
}
|
||||
|
||||
// @Transactional
|
||||
// @PostMapping(path = {"data-repo/persist"}, consumes = "application/json", produces = "application/json")
|
||||
// public @ResponseBody
|
||||
// ResponseEntity<ResponseItem<ExternalReference>> createExternalReferecnes(@RequestBody ExternalReference externalReference) throws Exception {
|
||||
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
||||
//
|
||||
// ExternalReference newExternalReference = this.externalReferencesService.createDataRepo(externalReference);
|
||||
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
// @GetMapping(path = {"{externalType}"}, produces = "application/json")
|
||||
// public @ResponseBody ResponseEntity<ResponseItem<List<ExternalReference2>>> listExternalReferecnes2(@RequestParam(value = "externalType") String externalType, @RequestParam(value = "query", required = false) String query,
|
||||
// @RequestParam(value = "type", required = false) String type
|
||||
// ) throws HugeResultSet, NoURLFound, InvalidApplicationException {
|
||||
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
||||
//
|
||||
// List<ExternalReference2> externalReferences = this.externalReferencesService.getExternalReference2(externalType, query, type);
|
||||
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalReference2>>().status(ApiMessageCode.NO_MESSAGE).payload(externalReferences));
|
||||
// }
|
||||
//
|
||||
// @Transactional
|
||||
// @PostMapping(value = {"{externalType}/persist"}, consumes = "application/json", produces = "application/json")
|
||||
// public @ResponseBody
|
||||
// ResponseEntity<ResponseItem<ExternalReference2>> create(@RequestBody ExternalReference2 externalReference) throws Exception {
|
||||
// this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
|
||||
//
|
||||
// ExternalReference2 newExternalReference = this.externalReferencesService.create(externalReference);
|
||||
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ExternalReference2>().payload(newExternalReference).status(ApiMessageCode.SUCCESS_MESSAGE));
|
||||
// }
|
||||
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
package eu.eudat.logic.services.externalreferences;
|
||||
|
||||
import eu.eudat.authorization.Permission;
|
||||
import eu.eudat.commons.enums.ExternalReferencesType;
|
||||
import eu.eudat.commons.scope.user.UserScope;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.dao.criteria.DataRepositoryCriteria;
|
||||
import eu.eudat.data.dao.criteria.ExternalDatasetCriteria;
|
||||
import eu.eudat.data.dao.criteria.RegistryCriteria;
|
||||
import eu.eudat.data.dao.criteria.ServiceCriteria;
|
||||
import eu.eudat.data.old.DataRepository;
|
||||
import eu.eudat.data.old.ExternalDataset;
|
||||
import eu.eudat.data.old.Registry;
|
||||
import eu.eudat.data.old.Service;
|
||||
import eu.eudat.logic.builders.model.criteria.ExternalDatasetCriteriaBuilder;
|
||||
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.model.deleter.ExternalReferenceDeleter;
|
||||
import eu.eudat.models.data.FetcherExternalReference;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.deleter.DeleterFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyForbiddenException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.MessageSource;
|
||||
|
||||
import javax.management.InvalidApplicationException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@org.springframework.stereotype.Service
|
||||
public class ExternalReferenceService {
|
||||
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalReferenceService.class));
|
||||
private final ApiContext apiContext;
|
||||
private final UserScope userScope;
|
||||
private final RemoteFetcher remoteFetcher;
|
||||
private final EntityManager entityManager;
|
||||
private final AuthorizationService authorizationService;
|
||||
private final DeleterFactory deleterFactory;
|
||||
private final BuilderFactory builderFactory;
|
||||
private final ConventionService conventionService;
|
||||
private final MessageSource messageSource;
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
public ExternalReferenceService(ApiContext apiContext,
|
||||
UserScope userScope,
|
||||
RemoteFetcher remoteFetcher,
|
||||
EntityManager entityManager,
|
||||
AuthorizationService authorizationService,
|
||||
DeleterFactory deleterFactory,
|
||||
BuilderFactory builderFactory,
|
||||
ConventionService conventionService,
|
||||
MessageSource messageSource,
|
||||
QueryFactory queryFactory) {
|
||||
this.apiContext = apiContext;
|
||||
this.userScope = userScope;
|
||||
this.remoteFetcher = remoteFetcher;
|
||||
this.entityManager = entityManager;
|
||||
this.authorizationService = authorizationService;
|
||||
this.deleterFactory = deleterFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
this.conventionService = conventionService;
|
||||
this.messageSource = messageSource;
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
|
||||
logger.debug("deleting : {}", id);
|
||||
|
||||
this.authorizationService.authorizeForce(Permission.DeleteExternalReference);
|
||||
|
||||
this.deleterFactory.deleter(ExternalReferenceDeleter.class).deleteAndSaveByIds(List.of(id));
|
||||
}
|
||||
|
||||
// external references:
|
||||
// taxonomies,
|
||||
// licenses,
|
||||
// publications,
|
||||
// journals,
|
||||
// pubRepositories,
|
||||
// dataRepositories
|
||||
// registries,
|
||||
// services
|
||||
public List<FetcherExternalReference> searchExternalReference(ExternalReferencesType externalType, String query, String type) throws HugeResultSet, NoURLFound, InvalidApplicationException {
|
||||
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
||||
|
||||
List<Map<String, String>> remoteRepos = null;
|
||||
if (externalType.equals(ExternalReferencesType.Datasets)){
|
||||
remoteRepos = remoteFetcher.getDatasets(externalUrlCriteria, type);
|
||||
}else {
|
||||
remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type);
|
||||
}
|
||||
|
||||
List<FetcherExternalReference> list = this.fetchFromDb(externalType, query, type, remoteRepos);
|
||||
|
||||
list.addAll(remoteRepos.stream().map(FetcherExternalReference::fromRemoteModel).toList());
|
||||
list = list.stream().filter(x -> x.getName().toLowerCase().contains(query.toLowerCase())).collect(Collectors.toList());
|
||||
list.sort(Comparator.comparing(FetcherExternalReference::getName));
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<FetcherExternalReference> fetchFromDb(ExternalReferencesType externalType, String query, String type, List<Map<String, String>> remoteRepos) throws InvalidApplicationException {
|
||||
List<FetcherExternalReference> list = new LinkedList<>();
|
||||
switch (externalType) {
|
||||
case DataRepositories:
|
||||
case PubRepositories:
|
||||
case Journals: {
|
||||
DataRepositoryCriteria criteria = new DataRepositoryCriteria();
|
||||
if (!query.isEmpty()) criteria.setLike(query);
|
||||
criteria.setCreationUserId(this.userScope.getUserId());
|
||||
if (type.equals("")) {
|
||||
List<DataRepository> dataRepositoryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().getWithCriteria(criteria)).toList();
|
||||
list = dataRepositoryList.stream().map(item -> new FetcherExternalReference().fromDataRepository(item)).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
case Registries: {
|
||||
RegistryCriteria criteria = new RegistryCriteria();
|
||||
if (!query.isEmpty()) criteria.setLike(query);
|
||||
criteria.setCreationUserId(this.userScope.getUserId());
|
||||
if (type.equals("")) {
|
||||
List<Registry> registryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().getWithCriteria(criteria)).toList();
|
||||
list = registryList.stream().map(item -> new FetcherExternalReference().fromRegistry(item)).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
case Services:
|
||||
{
|
||||
ServiceCriteria criteria = new ServiceCriteria();
|
||||
|
||||
if (!query.isEmpty()) criteria.setLike(query);
|
||||
criteria.setCreationUserId(this.userScope.getUserId());
|
||||
|
||||
if (type.equals("")) {
|
||||
List<Service> serviceList = (this.apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().getWithCriteria(criteria)).toList();
|
||||
list = serviceList.stream().map(item -> new FetcherExternalReference().fromService(item)).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
case Datasets:{
|
||||
|
||||
ExternalDatasetCriteria criteria = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ExternalDatasetCriteriaBuilder.class).like(query).build();
|
||||
|
||||
criteria.setCreationUserId(this.userScope.getUserId());
|
||||
QueryableList<ExternalDataset> items = apiContext.getOperationsContext().getDatabaseRepository().getExternalDatasetDao().getWithCriteria(criteria);
|
||||
|
||||
list = items.select(item -> new FetcherExternalReference().fromDataset(item));
|
||||
}
|
||||
case Taxonomies:
|
||||
case Publications:
|
||||
case Licenses:
|
||||
break;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,217 +0,0 @@
|
|||
package eu.eudat.logic.services.externalreferences;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.commons.enums.ExternalReferencesType;
|
||||
import eu.eudat.commons.scope.user.UserScope;
|
||||
import eu.eudat.data.dao.criteria.DataRepositoryCriteria;
|
||||
import eu.eudat.data.dao.criteria.ExternalDatasetCriteria;
|
||||
import eu.eudat.data.dao.criteria.RegistryCriteria;
|
||||
import eu.eudat.data.dao.criteria.ServiceCriteria;
|
||||
|
||||
import eu.eudat.data.old.DataRepository;
|
||||
import eu.eudat.data.old.ExternalDataset;
|
||||
import eu.eudat.data.old.Registry;
|
||||
import eu.eudat.data.old.Service;
|
||||
import eu.eudat.logic.builders.model.criteria.ExternalDatasetCriteriaBuilder;
|
||||
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.ExternalReference;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
|
||||
import javax.management.InvalidApplicationException;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@org.springframework.stereotype.Service
|
||||
public class ExternalReferencesService {
|
||||
|
||||
private final ApiContext apiContext;
|
||||
private final UserScope userScope;
|
||||
private final RemoteFetcher remoteFetcher;
|
||||
|
||||
public ExternalReferencesService(ApiContext apiContext, UserScope userScope, RemoteFetcher remoteFetcher) {
|
||||
this.apiContext = apiContext;
|
||||
this.userScope = userScope;
|
||||
this.remoteFetcher = remoteFetcher;
|
||||
}
|
||||
|
||||
// external references:
|
||||
// taxonomies,
|
||||
// licenses,
|
||||
// publications,
|
||||
// journals,
|
||||
// pubRepositories,
|
||||
// dataRepositories
|
||||
|
||||
// public ExternalReference createDataRepo(ExternalReference externalReference) throws Exception {
|
||||
// // only dataRepositories, pubRepositories, journals
|
||||
// DataRepository dataRepository = externalReference.toDataModel();
|
||||
// dataRepository.getCreationUser().setId(this.userScope.getUserId());
|
||||
//
|
||||
// dataRepository = apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().createOrUpdate(dataRepository);
|
||||
// return new ExternalReference().fromDataModel(dataRepository);
|
||||
// }
|
||||
|
||||
// public List<ExternalReference> getExternalReference(String externalType, String query, String type) throws HugeResultSet, NoURLFound, InvalidApplicationException {
|
||||
// ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
||||
// List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type);
|
||||
//
|
||||
// DataRepositoryCriteria criteria = new DataRepositoryCriteria();
|
||||
// if (!query.isEmpty()) criteria.setLike(query);
|
||||
//
|
||||
// List<ExternalReference> list = new LinkedList<>();
|
||||
// if((externalType.equals("dataRepositories") || externalType.equals("pubRepositories") || externalType.equals("journals"))){
|
||||
// criteria.setCreationUserId(this.userScope.getUserId());
|
||||
// if (type.equals("")) {
|
||||
// List<DataRepository> dataRepositoryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().getWithCriteria(criteria)).toList();
|
||||
// list = dataRepositoryList.stream().map(item -> new ExternalReference().fromDataModel(item)).collect(Collectors.toList());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
// list.addAll(remoteRepos.stream().map(item -> mapper.convertValue(item, ExternalReference.class)).collect(Collectors.toList()));
|
||||
// list = list.stream().filter(x -> x.getName().toLowerCase().contains(query.toLowerCase())).collect(Collectors.toList());
|
||||
// return list;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// external references2:
|
||||
// registries,
|
||||
// services
|
||||
|
||||
// public ExternalReference2 create(ExternalReference2 externalReference) throws Exception {
|
||||
// if (externalReference.getLabel() == null || externalReference.getAbbreviation() == null || externalReference.getUri() == null) {
|
||||
// throw new Exception("Missing mandatory entity.");
|
||||
// }
|
||||
//
|
||||
// ExternalReference2 newExternalReference = null;
|
||||
// if(externalReference.getExternalType().equals("registries")){
|
||||
// Registry registry = externalReference.toDataModelRegistry();
|
||||
// registry.getCreationUser().setId(this.userScope.getUserId());
|
||||
// registry = apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().createOrUpdate(registry);
|
||||
// newExternalReference = new ExternalReference2().fromDataModel(registry);
|
||||
// } else if (externalReference.getExternalType().equals("services")) {
|
||||
// Service service = externalReference.toDataModelService();
|
||||
// service.getCreationUser().setId(this.userScope.getUserId());
|
||||
// service = apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().createOrUpdate(service);
|
||||
// newExternalReference = new ExternalReference2().fromDataModel(service);
|
||||
// }
|
||||
//
|
||||
// return newExternalReference;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public List<ExternalReference2> getExternalReference2(String externalType, String query, String type) throws HugeResultSet, NoURLFound, InvalidApplicationException {
|
||||
// ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
||||
// List<Map<String, String>> remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType,externalUrlCriteria, type);
|
||||
//
|
||||
// List<ExternalReference2> list = new LinkedList<>();
|
||||
//
|
||||
// if (externalType.equals("registries")){
|
||||
// RegistryCriteria criteria = new RegistryCriteria();
|
||||
//
|
||||
// if (!query.isEmpty()) criteria.setLike(query);
|
||||
// criteria.setCreationUserId(this.userScope.getUserId());
|
||||
//
|
||||
// if (type.equals("")) {
|
||||
// List<Registry> registryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().getWithCriteria(criteria)).toList();
|
||||
// list = registryList.stream().map(item -> new ExternalReference2().fromDataModel(item)).collect(Collectors.toList());
|
||||
// }
|
||||
// } else if (externalType.equals("services")) {
|
||||
// ServiceCriteria criteria = new ServiceCriteria();
|
||||
//
|
||||
// if (!query.isEmpty()) criteria.setLike(query);
|
||||
// criteria.setCreationUserId(this.userScope.getUserId());
|
||||
//
|
||||
// if (type.equals("")) {
|
||||
// List<Service> serviceList = (this.apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().getWithCriteria(criteria)).toList();
|
||||
// list = serviceList.stream().map(item -> new ExternalReference2().fromDataModel(item)).collect(Collectors.toList());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
// list.addAll(remoteRepos.stream().map(item -> mapper.convertValue(item, ExternalReference2.class)).collect(Collectors.toList()));
|
||||
//
|
||||
// return list;
|
||||
// }
|
||||
|
||||
public List<ExternalReference> getExternalReference(ExternalReferencesType externalType, String query, String type) throws HugeResultSet, NoURLFound, InvalidApplicationException {
|
||||
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(query);
|
||||
|
||||
List<Map<String, String>> remoteRepos = null;
|
||||
if (externalType.equals(ExternalReferencesType.Datasets)){
|
||||
remoteRepos = remoteFetcher.getDatasets(externalUrlCriteria, type);
|
||||
}else {
|
||||
remoteRepos = this.apiContext.getOperationsContext().getRemoteFetcher().get(externalType, externalUrlCriteria, type);
|
||||
}
|
||||
|
||||
List<ExternalReference> list = this.fetchFromDb(externalType, query, type, remoteRepos);
|
||||
|
||||
list.addAll(remoteRepos.stream().map(ExternalReference::fromRemoteModel).toList());
|
||||
list = list.stream().filter(x -> x.getName().toLowerCase().contains(query.toLowerCase())).collect(Collectors.toList());
|
||||
list.sort(Comparator.comparing(ExternalReference::getName));
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<ExternalReference> fetchFromDb(ExternalReferencesType externalType, String query, String type, List<Map<String, String>> remoteRepos) throws InvalidApplicationException {
|
||||
List<ExternalReference> list = new LinkedList<>();
|
||||
switch (externalType) {
|
||||
case DataRepositories:
|
||||
case PubRepositories:
|
||||
case Journals: {
|
||||
DataRepositoryCriteria criteria = new DataRepositoryCriteria();
|
||||
if (!query.isEmpty()) criteria.setLike(query);
|
||||
criteria.setCreationUserId(this.userScope.getUserId());
|
||||
if (type.equals("")) {
|
||||
List<DataRepository> dataRepositoryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().getWithCriteria(criteria)).toList();
|
||||
list = dataRepositoryList.stream().map(item -> new ExternalReference().fromDataRepository(item)).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
case Registries: {
|
||||
RegistryCriteria criteria = new RegistryCriteria();
|
||||
if (!query.isEmpty()) criteria.setLike(query);
|
||||
criteria.setCreationUserId(this.userScope.getUserId());
|
||||
if (type.equals("")) {
|
||||
List<Registry> registryList = (this.apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().getWithCriteria(criteria)).toList();
|
||||
list = registryList.stream().map(item -> new ExternalReference().fromRegistry(item)).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
case Services:
|
||||
{
|
||||
ServiceCriteria criteria = new ServiceCriteria();
|
||||
|
||||
if (!query.isEmpty()) criteria.setLike(query);
|
||||
criteria.setCreationUserId(this.userScope.getUserId());
|
||||
|
||||
if (type.equals("")) {
|
||||
List<Service> serviceList = (this.apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().getWithCriteria(criteria)).toList();
|
||||
list = serviceList.stream().map(item -> new ExternalReference().fromService(item)).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
case Datasets:{
|
||||
|
||||
ExternalDatasetCriteria criteria = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ExternalDatasetCriteriaBuilder.class).like(query).build();
|
||||
|
||||
criteria.setCreationUserId(this.userScope.getUserId());
|
||||
QueryableList<ExternalDataset> items = apiContext.getOperationsContext().getDatabaseRepository().getExternalDatasetDao().getWithCriteria(criteria);
|
||||
|
||||
list = items.select(item -> new ExternalReference().fromDataset(item));
|
||||
}
|
||||
case Taxonomies:
|
||||
case Publications:
|
||||
case Licenses:
|
||||
break;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
package eu.eudat.logic.services.externalreferences;
|
||||
|
||||
import eu.eudat.commons.scope.user.UserScope;
|
||||
import eu.eudat.data.old.UserInfo;
|
||||
import eu.eudat.data.query.items.item.funder.FunderCriteriaRequest;
|
||||
import eu.eudat.logic.builders.model.models.FunderBuilder;
|
||||
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.utilities.helpers.ListHelper;
|
||||
import eu.eudat.models.data.external.ExternalSourcesItemModel;
|
||||
import eu.eudat.models.data.external.FundersExternalSourcesModel;
|
||||
import eu.eudat.models.data.funder.Funder;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.management.InvalidApplicationException;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class FunderService {
|
||||
|
||||
private ApiContext apiContext;
|
||||
private RemoteFetcher remoteFetcher;
|
||||
private ListHelper listHelper;
|
||||
private final UserScope userScope;
|
||||
|
||||
public FunderService(ApiContext apiContext, RemoteFetcher remoteFetcher, ListHelper listHelper, UserScope userScope) {
|
||||
this.apiContext = apiContext;
|
||||
this.remoteFetcher = remoteFetcher;
|
||||
this.listHelper = listHelper;
|
||||
this.userScope = userScope;
|
||||
}
|
||||
|
||||
public List<Funder> getCriteriaWithExternal(FunderCriteriaRequest funderCriteria) throws HugeResultSet, NoURLFound, InvalidApplicationException {
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setId(this.userScope.getUserId());
|
||||
funderCriteria.getCriteria().setReference("dmp:");
|
||||
QueryableList<eu.eudat.data.old.Funder> items = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getWithCritetia(funderCriteria.getCriteria());
|
||||
QueryableList<eu.eudat.data.old.Funder> authItems = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getAuthenticated(items, userInfo);
|
||||
List<Funder> funders = authItems.select(item -> new Funder().fromDataModel(item));
|
||||
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(funderCriteria.getCriteria().getLike());
|
||||
List<Map<String, String>> remoteRepos = remoteFetcher.getFunders(externalUrlCriteria);
|
||||
FundersExternalSourcesModel fundersExternalSourcesModel = new FundersExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||
for (ExternalSourcesItemModel externalListingItem : fundersExternalSourcesModel) {
|
||||
Funder funder = apiContext.getOperationsContext().getBuilderFactory().getBuilder(FunderBuilder.class)
|
||||
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
|
||||
.status(eu.eudat.data.old.Funder.Status.fromInteger(0))
|
||||
.key(externalListingItem.getKey())
|
||||
.source(externalListingItem.getTag())
|
||||
.build();
|
||||
if (externalListingItem.getSource() != null) {
|
||||
funder.setSource(externalListingItem.getSource());
|
||||
} else {
|
||||
funder.setSource(externalListingItem.getTag());
|
||||
}
|
||||
|
||||
funders.add(funder);
|
||||
}
|
||||
funders.sort(Comparator.comparing(Funder::getLabel));
|
||||
funders = funders.stream().filter(listHelper.distinctByKey(Funder::getLabel)).collect(Collectors.toList());
|
||||
return funders;
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package eu.eudat.logic.services.externalreferences;
|
||||
|
||||
import eu.eudat.commons.scope.user.UserScope;
|
||||
import eu.eudat.data.query.items.item.project.ProjectCriteriaRequest;
|
||||
import eu.eudat.logic.builders.model.models.ProjectBuilder;
|
||||
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
|
||||
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
|
||||
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
|
||||
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.utilities.helpers.ListHelper;
|
||||
import eu.eudat.models.data.external.ExternalSourcesItemModel;
|
||||
import eu.eudat.models.data.external.ProjectsExternalSourcesModel;
|
||||
import eu.eudat.models.data.project.Project;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.management.InvalidApplicationException;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private ApiContext apiContext;
|
||||
private RemoteFetcher remoteFetcher;
|
||||
private ListHelper listHelper;
|
||||
private final UserScope userScope;
|
||||
|
||||
public ProjectService(ApiContext apiContext, ListHelper listHelper, UserScope userScope) {
|
||||
this.apiContext = apiContext;
|
||||
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
|
||||
this.listHelper = listHelper;
|
||||
this.userScope = userScope;
|
||||
}
|
||||
|
||||
public List<Project> getCriteriaWithExternal(ProjectCriteriaRequest projectCriteria) throws HugeResultSet, NoURLFound, InvalidApplicationException {
|
||||
eu.eudat.data.old.UserInfo userInfo = new eu.eudat.data.old.UserInfo();
|
||||
userInfo.setId(this.userScope.getUserId());
|
||||
projectCriteria.getCriteria().setReference("dmp:");
|
||||
QueryableList<eu.eudat.data.old.Project> items = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getWithCritetia(projectCriteria.getCriteria());
|
||||
QueryableList<eu.eudat.data.old.Project> authItems = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getAuthenticated(items, userInfo);
|
||||
List<Project> projects = authItems.select(item -> new Project().fromDataModel(item));
|
||||
ExternalUrlCriteria externalUrlCriteria = new ExternalUrlCriteria(projectCriteria.getCriteria().getLike());
|
||||
List<Map<String, String>> remoteRepos = remoteFetcher.getProjects(externalUrlCriteria);
|
||||
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
|
||||
for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) {
|
||||
Project project = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ProjectBuilder.class)
|
||||
.reference(externalListingItem.getRemoteId()).label(externalListingItem.getName())
|
||||
.description(externalListingItem.getDescription()).uri(externalListingItem.getUri())
|
||||
.abbreviation(externalListingItem.getAbbreviation()).status(eu.eudat.data.old.Project.Status.fromInteger(0))
|
||||
.key(externalListingItem.getKey())
|
||||
.source(externalListingItem.getTag())
|
||||
.build();
|
||||
|
||||
projects.add(project);
|
||||
}
|
||||
projects.sort(Comparator.comparing(Project::getLabel));
|
||||
projects = projects.stream().filter(listHelper.distinctByKey(Project::getLabel)).collect(Collectors.toList());
|
||||
return projects;
|
||||
}
|
||||
}
|
|
@ -1,188 +0,0 @@
|
|||
package eu.eudat.models.data;
|
||||
|
||||
|
||||
|
||||
import eu.eudat.data.old.Registry;
|
||||
import eu.eudat.data.old.Service;
|
||||
import eu.eudat.data.old.UserInfo;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ExternalReference2 {
|
||||
private UUID id;
|
||||
private String label;
|
||||
private String name;
|
||||
private String pid;
|
||||
private String abbreviation;
|
||||
private String uri;
|
||||
private Date created;
|
||||
private Date modified;
|
||||
private String reference;
|
||||
private String tag;
|
||||
private String source;
|
||||
|
||||
private String externalType;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPid() {
|
||||
return pid;
|
||||
}
|
||||
public void setPid(String pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getAbbreviation() {
|
||||
return abbreviation;
|
||||
}
|
||||
public void setAbbreviation(String abbreviation) {
|
||||
this.abbreviation = abbreviation;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public Date getModified() {
|
||||
return modified;
|
||||
}
|
||||
public void setModified(Date modified) {
|
||||
this.modified = modified;
|
||||
}
|
||||
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
public void setSource(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public String getExternalType() {return externalType;}
|
||||
|
||||
public void setExternalType(String externalType) {this.externalType = externalType;}
|
||||
|
||||
public ExternalReference2 fromDataModel(Service entity) {
|
||||
this.abbreviation = entity.getAbbreviation();
|
||||
this.created = entity.getCreated();
|
||||
this.id = entity.getId();
|
||||
this.label = entity.getLabel();
|
||||
this.name = entity.getLabel();
|
||||
this.modified = entity.getModified();
|
||||
this.uri = entity.getUri();
|
||||
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
if (source.equals("dmp")) {
|
||||
this.source = "Internal";
|
||||
} else {
|
||||
this.source = source;
|
||||
}
|
||||
this.externalType = "services";
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExternalReference2 fromDataModel(Registry entity) {
|
||||
this.id = entity.getId();
|
||||
this.abbreviation = entity.getAbbreviation();
|
||||
this.created = entity.getCreated();
|
||||
this.label = entity.getLabel();
|
||||
this.name = entity.getLabel();
|
||||
this.modified = entity.getModified();
|
||||
this.uri = entity.getUri();
|
||||
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
||||
if (source1.equals("dmp")) {
|
||||
this.source = "Internal";
|
||||
} else {
|
||||
this.source = source1;
|
||||
}
|
||||
this.reference = entity.getReference();
|
||||
this.externalType = "registries";
|
||||
return this;
|
||||
}
|
||||
|
||||
public Service toDataModelService() throws Exception {
|
||||
Service service = new Service();
|
||||
service.setId(this.id != null ? this.id : UUID.randomUUID());
|
||||
service.setAbbreviation(this.abbreviation);
|
||||
service.setCreated(this.created != null ? this.created : new Date());
|
||||
service.setLabel(this.label != null ? this.label : this.name);
|
||||
service.setModified(new Date());
|
||||
service.setUri(this.uri);
|
||||
if (this.source == null) this.source = "dmp";
|
||||
if (this.reference == null) this.reference = service.getId().toString();
|
||||
if (this.source.equals(this.reference.substring(0, this.source.length()))) {
|
||||
service.setReference(this.reference);
|
||||
} else {
|
||||
service.setReference(this.source + ":" + this.reference);
|
||||
}
|
||||
service.setModified(new Date());
|
||||
service.setStatus((short) 0);
|
||||
service.setCreationUser(new UserInfo());
|
||||
return service;
|
||||
}
|
||||
|
||||
public Registry toDataModelRegistry() throws Exception {
|
||||
Registry registry = new Registry();
|
||||
registry.setAbbreviation(this.abbreviation);
|
||||
registry.setCreated(this.created != null ? this.created : new Date());
|
||||
registry.setId(this.id != null ? this.id : UUID.randomUUID());
|
||||
registry.setLabel(this.label != null ? this.label : this.name);
|
||||
registry.setUri(this.uri);
|
||||
registry.setModified(new Date());
|
||||
if (this.source == null) this.source = "dmp";
|
||||
if (this.source.equals(registry.getId().toString().substring(0, this.source.length()))) {
|
||||
registry.setReference(registry.getId().toString());
|
||||
} else {
|
||||
registry.setReference(this.source + ":" + registry.getId());
|
||||
}
|
||||
registry.setStatus((short)0);
|
||||
registry.setCreationUser(new UserInfo());
|
||||
return registry;
|
||||
}
|
||||
|
||||
public String getHint() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ import eu.eudat.data.old.*;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
public class ExternalReference {
|
||||
public class FetcherExternalReference {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
|
@ -133,28 +133,28 @@ public class ExternalReference {
|
|||
this.tag = tag;
|
||||
}
|
||||
|
||||
public static ExternalReference fromRemoteModel(Map<String, String> data) {
|
||||
ExternalReference externalReference = new ExternalReference();
|
||||
if (data == null) return externalReference;
|
||||
public static FetcherExternalReference fromRemoteModel(Map<String, String> data) {
|
||||
FetcherExternalReference fetcherExternalReference = new FetcherExternalReference();
|
||||
if (data == null) return fetcherExternalReference;
|
||||
|
||||
externalReference.setId(data.getOrDefault("id", null));
|
||||
externalReference.setName(data.getOrDefault("name", null));
|
||||
externalReference.setPid(data.getOrDefault("pid", null));
|
||||
externalReference.setPidTypeField(data.getOrDefault("pidTypeField", null));
|
||||
externalReference.setUri(data.getOrDefault("uri", null));
|
||||
externalReference.setDescription(data.getOrDefault("description", null));
|
||||
externalReference.setSource(data.getOrDefault("source", null));
|
||||
externalReference.setCount(data.getOrDefault("count", null));
|
||||
externalReference.setPath(data.getOrDefault("path", null));
|
||||
externalReference.setHost(data.getOrDefault("host", null));
|
||||
externalReference.setTypes(data.getOrDefault("types", null));
|
||||
externalReference.setFirstName(data.getOrDefault("firstName", null));
|
||||
externalReference.setLastName(data.getOrDefault("lastName", null));
|
||||
externalReference.setTag(data.getOrDefault("tag", null));
|
||||
return externalReference;
|
||||
fetcherExternalReference.setId(data.getOrDefault("id", null));
|
||||
fetcherExternalReference.setName(data.getOrDefault("name", null));
|
||||
fetcherExternalReference.setPid(data.getOrDefault("pid", null));
|
||||
fetcherExternalReference.setPidTypeField(data.getOrDefault("pidTypeField", null));
|
||||
fetcherExternalReference.setUri(data.getOrDefault("uri", null));
|
||||
fetcherExternalReference.setDescription(data.getOrDefault("description", null));
|
||||
fetcherExternalReference.setSource(data.getOrDefault("source", null));
|
||||
fetcherExternalReference.setCount(data.getOrDefault("count", null));
|
||||
fetcherExternalReference.setPath(data.getOrDefault("path", null));
|
||||
fetcherExternalReference.setHost(data.getOrDefault("host", null));
|
||||
fetcherExternalReference.setTypes(data.getOrDefault("types", null));
|
||||
fetcherExternalReference.setFirstName(data.getOrDefault("firstName", null));
|
||||
fetcherExternalReference.setLastName(data.getOrDefault("lastName", null));
|
||||
fetcherExternalReference.setTag(data.getOrDefault("tag", null));
|
||||
return fetcherExternalReference;
|
||||
}
|
||||
|
||||
public ExternalReference fromDataRepository(DataRepository entity) {
|
||||
public FetcherExternalReference fromDataRepository(DataRepository entity) {
|
||||
// this.setAbbreviation(entity.getAbbreviation());
|
||||
this.setName(entity.getLabel());
|
||||
this.setUri(entity.getUri());
|
||||
|
@ -169,7 +169,7 @@ public class ExternalReference {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ExternalReference fromRegistry(Registry entity){
|
||||
public FetcherExternalReference fromRegistry(Registry entity){
|
||||
this.id = entity.getId().toString();
|
||||
// this.abbreviation = entity.getAbbreviation();
|
||||
// this.created = entity.getCreated();
|
||||
|
@ -186,7 +186,7 @@ public class ExternalReference {
|
|||
// this.reference = entity.getReference();
|
||||
return this;
|
||||
}
|
||||
public ExternalReference fromService(Service entity) {
|
||||
public FetcherExternalReference fromService(Service entity) {
|
||||
// this.abbreviation = entity.getAbbreviation();
|
||||
// this.created = entity.getCreated();
|
||||
this.id = entity.getId().toString();
|
||||
|
@ -203,7 +203,7 @@ public class ExternalReference {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ExternalReference fromResearcher(Researcher entity){
|
||||
public FetcherExternalReference fromResearcher(Researcher entity){
|
||||
this.id = entity.getId().toString();
|
||||
this.name = entity.getLabel();
|
||||
String refParts[] = entity.getReference().split(":");
|
||||
|
@ -216,7 +216,7 @@ public class ExternalReference {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ExternalReference fromOrganisation(Organisation entity){
|
||||
public FetcherExternalReference fromOrganisation(Organisation entity){
|
||||
this.id = entity.getId().toString();
|
||||
this.name = entity.getLabel();
|
||||
String refParts[] = entity.getReference().split(":");
|
||||
|
@ -229,7 +229,7 @@ public class ExternalReference {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ExternalReference fromDataset(ExternalDataset entity){
|
||||
public FetcherExternalReference fromDataset(ExternalDataset entity){
|
||||
this.id = entity.getId().toString();
|
||||
this.name = entity.getLabel();
|
||||
String source1 = entity.getReference().substring(0, entity.getReference().indexOf(":"));
|
|
@ -60,7 +60,7 @@ export class ExternalSourcesService {
|
|||
}
|
||||
|
||||
public listExternal(externalType: ExternalReferencesType, query: string, type: string): Observable<ExternalReference[]> {
|
||||
const url = this.configurationService.server + `external-references/${externalType}`;
|
||||
const url = this.configurationService.server + `external-references/search/${externalType}`;
|
||||
const options = { params: { query: query, type: type } };
|
||||
|
||||
return this.http.get<ExternalReference[]>(url, options);
|
||||
|
|
Loading…
Reference in New Issue