Search in sources :

Example 1 with OfferedResource

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.");
    }
}
Also used : RepresentationArtifactLinker(io.dataspaceconnector.service.resource.relation.RepresentationArtifactLinker) OfferedResource(io.dataspaceconnector.model.resource.OfferedResource) RequestedResourceSubscriptionLinker(io.dataspaceconnector.service.resource.relation.RequestedResourceSubscriptionLinker) Representation(io.dataspaceconnector.model.representation.Representation) RequestedResource(io.dataspaceconnector.model.resource.RequestedResource) ResourceNotFoundException(io.dataspaceconnector.common.exception.ResourceNotFoundException) Artifact(io.dataspaceconnector.model.artifact.Artifact) SubscriptionProcessingException(io.dataspaceconnector.common.exception.SubscriptionProcessingException)

Example 2 with OfferedResource

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);
}
Also used : OfferedResource(io.dataspaceconnector.model.resource.OfferedResource) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 3 with OfferedResource

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;
}
Also used : RepresentationsToRequestsController(io.dataspaceconnector.controller.resource.relation.RepresentationsToRequestsController) RepresentationsToSubscriptionsController(io.dataspaceconnector.controller.resource.relation.RepresentationsToSubscriptionsController) OfferedResource(io.dataspaceconnector.model.resource.OfferedResource) RequestedResource(io.dataspaceconnector.model.resource.RequestedResource) UnreachableLineException(io.dataspaceconnector.common.exception.UnreachableLineException) RepresentationsToArtifactsController(io.dataspaceconnector.controller.resource.relation.RepresentationsToArtifactsController) Link(org.springframework.hateoas.Link) ModelMapper(org.modelmapper.ModelMapper)

Example 4 with OfferedResource

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;
}
Also used : ContractsToRulesController(io.dataspaceconnector.controller.resource.relation.ContractsToRulesController) OfferedResource(io.dataspaceconnector.model.resource.OfferedResource) ContractsToRequestedResourcesController(io.dataspaceconnector.controller.resource.relation.ContractsToRequestedResourcesController) RequestedResource(io.dataspaceconnector.model.resource.RequestedResource) UnreachableLineException(io.dataspaceconnector.common.exception.UnreachableLineException) Link(org.springframework.hateoas.Link) ModelMapper(org.modelmapper.ModelMapper)

Aggregations

OfferedResource (io.dataspaceconnector.model.resource.OfferedResource)4 RequestedResource (io.dataspaceconnector.model.resource.RequestedResource)3 UnreachableLineException (io.dataspaceconnector.common.exception.UnreachableLineException)2 ModelMapper (org.modelmapper.ModelMapper)2 Link (org.springframework.hateoas.Link)2 ResourceNotFoundException (io.dataspaceconnector.common.exception.ResourceNotFoundException)1 SubscriptionProcessingException (io.dataspaceconnector.common.exception.SubscriptionProcessingException)1 ContractsToRequestedResourcesController (io.dataspaceconnector.controller.resource.relation.ContractsToRequestedResourcesController)1 ContractsToRulesController (io.dataspaceconnector.controller.resource.relation.ContractsToRulesController)1 RepresentationsToArtifactsController (io.dataspaceconnector.controller.resource.relation.RepresentationsToArtifactsController)1 RepresentationsToRequestsController (io.dataspaceconnector.controller.resource.relation.RepresentationsToRequestsController)1 RepresentationsToSubscriptionsController (io.dataspaceconnector.controller.resource.relation.RepresentationsToSubscriptionsController)1 Artifact (io.dataspaceconnector.model.artifact.Artifact)1 Representation (io.dataspaceconnector.model.representation.Representation)1 RepresentationArtifactLinker (io.dataspaceconnector.service.resource.relation.RepresentationArtifactLinker)1 RequestedResourceSubscriptionLinker (io.dataspaceconnector.service.resource.relation.RequestedResourceSubscriptionLinker)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1