Search in sources :

Example 1 with PropertiesDTO

use of org.opentosca.container.api.dto.boundarydefinitions.PropertiesDTO in project container by OpenTOSCA.

the class BoundaryDefinitionController method getBoundaryDefinitionProperties.

@GET
@Path("/properties")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ApiOperation(value = "Get properties of a service tempate", response = PropertiesDTO.class)
public Response getBoundaryDefinitionProperties(@ApiParam("ID of CSAR") @PathParam("csar") final String csarId, @ApiParam("qualified name of the service template") @PathParam("servicetemplate") final String servicetemplate) {
    logger.debug("Invoking getBoundaryDefinitionProperties");
    final Csar csar = this.storage.findById(new CsarId(csarId));
    final TServiceTemplate serviceTemplate;
    try {
        serviceTemplate = ToscaEngine.resolveServiceTemplate(csar, servicetemplate);
    } catch (org.opentosca.container.core.common.NotFoundException e) {
        throw new NotFoundException(e);
    }
    if (Objects.isNull(serviceTemplate)) {
        return Response.status(Response.Status.NOT_FOUND).entity("ServiceTemplate not found!").build();
    }
    TBoundaryDefinitions boundary = serviceTemplate.getBoundaryDefinitions();
    if (Objects.isNull(boundary)) {
        return Response.status(Response.Status.NOT_FOUND).entity("BoundaryDefinitions not found!").build();
    }
    List<TPropertyMapping> propertyMappings = Optional.of(boundary).map(TBoundaryDefinitions::getProperties).map(TBoundaryDefinitions.Properties::getPropertyMappings).orElse(Collections.emptyList());
    logger.debug("Found <{}> property mappings", propertyMappings.size());
    final List<PropertyMappingDTO> propertyMappingDTOs = propertyMappings.stream().map(mapping -> {
        final PropertyMappingDTO result = new PropertyMappingDTO();
        result.setServiceTemplatePropertyRef(mapping.getServiceTemplatePropertyRef());
        result.setTargetPropertyRef(mapping.getTargetPropertyRef());
        if (!(mapping.getTargetObjectRef() instanceof TEntityTemplate)) {
            logger.error("Unexpected mapping target detected for the property (" + mapping.getServiceTemplatePropertyRef() + ")");
        } else {
            result.setTargetObjectRef(mapping.getTargetObjectRef().getId());
        }
        return result;
    }).collect(Collectors.toList());
    final PropertiesDTO dto = new PropertiesDTO();
    if (Objects.nonNull(boundary.getProperties())) {
        dto.setXmlFragment(boundary.getProperties().getAny());
        if (!propertyMappingDTOs.isEmpty()) {
            dto.setPropertyMappings(propertyMappingDTOs);
        }
    }
    dto.add(Link.fromUri(UriUtil.encode(this.uriInfo.getAbsolutePath())).rel("self").build());
    return Response.ok(dto).build();
}
Also used : Produces(javax.ws.rs.Produces) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) PlanType(org.opentosca.container.core.next.model.PlanType) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) ToscaEngine(org.opentosca.container.core.engine.ToscaEngine) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) ServiceTemplateInstanceRepository(org.opentosca.container.core.next.repository.ServiceTemplateInstanceRepository) Map(java.util.Map) URI(java.net.URI) CsarId(org.opentosca.container.core.model.csar.CsarId) Context(javax.ws.rs.core.Context) InterfaceDTO(org.opentosca.container.api.dto.boundarydefinitions.InterfaceDTO) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) ServiceTemplateInstance(org.opentosca.container.core.next.model.ServiceTemplateInstance) Objects(java.util.Objects) PropertiesDTO(org.opentosca.container.api.dto.boundarydefinitions.PropertiesDTO) List(java.util.List) Response(javax.ws.rs.core.Response) TPlan(org.eclipse.winery.model.tosca.TPlan) PlanDTO(org.opentosca.container.api.dto.plan.PlanDTO) Optional(java.util.Optional) Request(javax.ws.rs.core.Request) UriInfo(javax.ws.rs.core.UriInfo) UriUtil(org.opentosca.container.core.common.uri.UriUtil) Link(javax.ws.rs.core.Link) InterfaceListDTO(org.opentosca.container.api.dto.boundarydefinitions.InterfaceListDTO) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) PropertyMappingDTO(org.opentosca.container.api.dto.boundarydefinitions.PropertyMappingDTO) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) Inject(javax.inject.Inject) TExportedInterface(org.eclipse.winery.model.tosca.TExportedInterface) ResourceSupport(org.opentosca.container.api.dto.ResourceSupport) Api(io.swagger.annotations.Api) Csar(org.opentosca.container.core.model.csar.Csar) NodeOperationDTO(org.opentosca.container.api.dto.NodeOperationDTO) Logger(org.slf4j.Logger) CsarStorageService(org.opentosca.container.core.service.CsarStorageService) TPropertyMapping(org.eclipse.winery.model.tosca.TPropertyMapping) Component(org.springframework.stereotype.Component) OperationDTO(org.opentosca.container.api.dto.boundarydefinitions.OperationDTO) Collections(java.util.Collections) TExportedOperation(org.eclipse.winery.model.tosca.TExportedOperation) Csar(org.opentosca.container.core.model.csar.Csar) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) NotFoundException(javax.ws.rs.NotFoundException) CsarId(org.opentosca.container.core.model.csar.CsarId) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) PropertiesDTO(org.opentosca.container.api.dto.boundarydefinitions.PropertiesDTO) PropertyMappingDTO(org.opentosca.container.api.dto.boundarydefinitions.PropertyMappingDTO) TPropertyMapping(org.eclipse.winery.model.tosca.TPropertyMapping) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Api (io.swagger.annotations.Api)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 URI (java.net.URI)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 GET (javax.ws.rs.GET)1 NotFoundException (javax.ws.rs.NotFoundException)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1 Context (javax.ws.rs.core.Context)1 Link (javax.ws.rs.core.Link)1 MediaType (javax.ws.rs.core.MediaType)1