use of io.dataspaceconnector.model.resource.OfferedResource in project DataspaceConnector by International-Data-Spaces-Association.
the class SubscriptionService method linkSubscriptionToEntityById.
/**
* Link subscription to database entity.
*
* @param target The entity id.
* @param subscription The subscription.
* @throws SubscriptionProcessingException if subscription for targeted entity failed.
* @throws ResourceNotFoundException if the resource could not be found.
*/
private void linkSubscriptionToEntityById(final URI target, final Subscription subscription) throws SubscriptionProcessingException, ResourceNotFoundException, IllegalArgumentException {
// Check if target exists.
final var entity = entityResolver.getEntityById(target);
if (entity.isEmpty()) {
throw new ResourceNotFoundException(ErrorMessage.EMTPY_ENTITY.toString());
}
// Link subscription to entity.
final var subscriptionId = subscription.getId();
final var value = entity.get();
if (value instanceof Artifact) {
lookUp.getService(ArtifactSubscriptionLinker.class).get().add(value.getId(), Set.of(subscriptionId));
} else if (value instanceof Representation) {
lookUp.getService(RepresentationArtifactLinker.class).get().add(value.getId(), Set.of(subscriptionId));
} else if (value instanceof OfferedResource) {
lookUp.getService(OfferedResourceSubscriptionLinker.class).get().add(value.getId(), Set.of(subscriptionId));
} else if (value instanceof RequestedResource) {
lookUp.getService(RequestedResourceSubscriptionLinker.class).get().add(value.getId(), Set.of(subscriptionId));
} else {
throw new SubscriptionProcessingException("No subscription offered for this target.");
}
}
use of io.dataspaceconnector.model.resource.OfferedResource in project DataspaceConnector by International-Data-Spaces-Association.
the class BrokerOfferedResourceLinker method add.
/**
* This method also makes sure the bootstrap ids in entities are
* converted to the real DSC resource ids.
* {@inheritDoc}
*/
@Override
public void add(final UUID ownerId, final Set<UUID> entities) {
Utils.requireNonNull(ownerId, ErrorMessage.ENTITYID_NULL);
Utils.requireNonNull(entities, ErrorMessage.ENTITYSET_NULL);
if (entities.isEmpty()) {
// Prevent read call to database for the owner.
return;
}
Set<UUID> correctEntities = new HashSet<>(entities);
// if this is the case, replace it with the correct resource id
for (OfferedResource e : getManyService().getAll(Pageable.unpaged())) {
for (var entity : entities) {
if (e.getBootstrapId() != null) {
UUID bootstrapId = UUIDUtils.uuidFromUri(e.getBootstrapId());
if (bootstrapId.equals(entity)) {
correctEntities.remove(bootstrapId);
correctEntities.add(e.getId());
}
}
}
}
throwIfEntityDoesNotExist(correctEntities);
addInternal(ownerId, correctEntities);
}
use of io.dataspaceconnector.model.resource.OfferedResource in project DataspaceConnector by International-Data-Spaces-Association.
the class RepresentationViewAssembler method toModel.
/**
* Construct the RepresentationView from a Representation.
*
* @param representation The representation.
* @return The new view.
*/
@Override
public RepresentationView toModel(final Representation representation) {
final var modelMapper = new ModelMapper();
final var view = modelMapper.map(representation, RepresentationView.class);
view.add(getSelfLink(representation.getId()));
final var artifactsLink = linkTo(methodOn(RepresentationsToArtifactsController.class).getResource(representation.getId(), null, null)).withRel(BaseType.ARTIFACTS);
view.add(artifactsLink);
final var resourceType = representation.getResources();
Link resourceLinker;
if (resourceType.isEmpty()) {
// No elements found, default to offered resources
resourceLinker = linkTo(methodOn(RepresentationsToOfferedResourcesController.class).getResource(representation.getId(), null, null)).withRel(BaseType.OFFERS);
} else {
// Construct the link for the right resource type.
if (resourceType.get(0) instanceof OfferedResource) {
resourceLinker = linkTo(methodOn(RepresentationsToOfferedResourcesController.class).getResource(representation.getId(), null, null)).withRel(BaseType.OFFERS);
} else if (resourceType.get(0) instanceof RequestedResource) {
resourceLinker = linkTo(methodOn(RepresentationsToRequestsController.class).getResource(representation.getId(), null, null)).withRel(BaseType.REQUESTS);
} else {
throw new UnreachableLineException(ErrorMessage.UNKNOWN_TYPE);
}
}
view.add(resourceLinker);
final var subscriptionLink = linkTo(methodOn(RepresentationsToSubscriptionsController.class).getResource(representation.getId(), null, null)).withRel(BaseType.SUBSCRIPTIONS);
view.add(subscriptionLink);
return view;
}
use of io.dataspaceconnector.model.resource.OfferedResource in project DataspaceConnector by International-Data-Spaces-Association.
the class ContractViewAssembler method toModel.
/**
* Construct the ContractView from a Contract.
*
* @param contract The contract.
* @return The new view.
*/
@Override
public ContractView toModel(final Contract contract) {
final var modelMapper = new ModelMapper();
final var view = modelMapper.map(contract, ContractView.class);
view.add(getSelfLink(contract.getId()));
final var rulesLink = linkTo(methodOn(ContractsToRulesController.class).getResource(contract.getId(), null, null)).withRel(BaseType.RULES);
view.add(rulesLink);
final var resourceType = contract.getResources();
Link resourceLinker;
if (resourceType.isEmpty()) {
// No elements found, default to offered resources
resourceLinker = linkTo(methodOn(ContractsToOfferedResourcesController.class).getResource(contract.getId(), null, null)).withRel(BaseType.OFFERS);
} else {
// Construct the link for the right resource type.
if (resourceType.get(0) instanceof OfferedResource) {
resourceLinker = linkTo(methodOn(ContractsToOfferedResourcesController.class).getResource(contract.getId(), null, null)).withRel(BaseType.OFFERS);
} else if (resourceType.get(0) instanceof RequestedResource) {
resourceLinker = linkTo(methodOn(ContractsToRequestedResourcesController.class).getResource(contract.getId(), null, null)).withRel(BaseType.REQUESTS);
} else {
throw new UnreachableLineException(ErrorMessage.UNKNOWN_TYPE);
}
}
view.add(resourceLinker);
return view;
}
Aggregations