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();
}
Aggregations