use of org.eclipse.jdt.annotation.NonNull in project winery by eclipse.
the class PropertiesResource method getProperties.
/**
* Gets the defined properties. If no properties are defined, an empty JSON object is returned. If k/v properties
* are defined, then a JSON is returned. Otherwise an XML is returned.
*
* @return Key/Value map in the case of Winery WPD mode - else instance of XML Element in case of non-key/value
* properties
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@NonNull
public Response getProperties() {
TEntityType tempType = RepositoryFactory.getRepository().getTypeForTemplate(this.template);
WinerysPropertiesDefinition wpd = tempType.getWinerysPropertiesDefinition();
TEntityTemplate.Properties props = this.template.getProperties();
if (wpd == null) {
// These can be null resulting in 200 No Content at the caller
if (props == null) {
return Response.ok().entity("{}").type(MediaType.APPLICATION_JSON).build();
} else {
@Nullable final Object any = props.getAny();
if (any == null) {
LOGGER.debug("XML properties expected, but none found. Returning empty JSON.");
return Response.ok().entity("{}").type(MediaType.APPLICATION_JSON).build();
}
try {
@ADR(6) String xmlAsString = BackendUtils.getXMLAsString(TEntityTemplate.Properties.class, props, true);
return Response.ok().entity(xmlAsString).type(MediaType.TEXT_XML).build();
} catch (Exception e) {
throw new WebApplicationException(e);
}
}
} else {
Map<String, String> kvProperties = this.template.getProperties().getKVProperties();
return Response.ok().entity(kvProperties).type(MediaType.APPLICATION_JSON).build();
}
}
use of org.eclipse.jdt.annotation.NonNull in project winery by eclipse.
the class ReflectionUtil method getFieldName.
/**
* Checks a field for XmlElement or XmlAttribute annotations
*
* @return a pair of name and field
*/
@NonNull
private Pair<String, Field> getFieldName(Field field) {
XmlAttribute xmlAttribute = field.getAnnotation(XmlAttribute.class);
XmlElement xmlElement = field.getAnnotation(XmlElement.class);
String name = field.getName();
if (Objects.nonNull(xmlAttribute) && !xmlAttribute.name().equals("##default")) {
name = xmlAttribute.name();
} else if (Objects.nonNull(xmlElement) && !xmlElement.name().equals("##default")) {
name = xmlElement.name();
}
return Tuples.pair(name, field);
}
use of org.eclipse.jdt.annotation.NonNull in project winery by eclipse.
the class Splitting method resolveTopologyTemplate.
/**
* @param serviceTemplateId
* @throws SplittingException
*/
public void resolveTopologyTemplate(ServiceTemplateId serviceTemplateId) throws SplittingException, IOException {
IRepository repository = RepositoryFactory.getRepository();
@NonNull TServiceTemplate serviceTemplate = repository.getElement(serviceTemplateId);
@NonNull TTopologyTemplate topologyTemplate = serviceTemplate.getTopologyTemplate();
List<TRequirement> openRequirements = getOpenRequirements(topologyTemplate);
for (TRequirement requirement : openRequirements) {
QName requiredCapTypeQName = getRequiredCapabilityTypeQNameOfRequirement(requirement);
List<TNodeTemplate> nodesWithMatchingCapability = topologyTemplate.getNodeTemplates().stream().filter(nt -> nt.getCapabilities() != null).filter(nt -> nt.getCapabilities().getCapability().stream().anyMatch(c -> c.getType().equals(requiredCapTypeQName))).collect(Collectors.toList());
if (!nodesWithMatchingCapability.isEmpty() && nodesWithMatchingCapability.size() == 1) {
TCapability matchingCapability = nodesWithMatchingCapability.get(0).getCapabilities().getCapability().stream().filter(c -> c.getType().equals(requiredCapTypeQName)).findFirst().get();
TRelationshipType matchingRelationshipType = getMatchingRelationshipType(requirement, matchingCapability);
if (matchingRelationshipType != null) {
addMatchingRelationshipTemplateToTopologyTemplate(topologyTemplate, matchingRelationshipType, requirement, matchingCapability);
} else {
throw new SplittingException("No suitable relationship type found for matching");
}
}
}
repository.setElement(serviceTemplateId, serviceTemplate);
}
use of org.eclipse.jdt.annotation.NonNull in project winery by eclipse.
the class Splitting method matchTopologyOfServiceTemplate.
/**
* Splits the topology template of the given service template. Creates a new service template with "-split" suffix
* as id. Any existing "-split" service template will be deleted. Matches the split topology template to the cloud
* providers according to the target labels. Creates a new service template with "-matched" suffix as id. Any
* existing "-matched" service template will be deleted.
*
* @param id of the ServiceTemplate switch should be split and matched to cloud providers
* @return id of the ServiceTemplate which contains the matched topology
*/
public ServiceTemplateId matchTopologyOfServiceTemplate(ServiceTemplateId id) throws Exception {
long start = System.currentTimeMillis();
IRepository repository = RepositoryFactory.getRepository();
@NonNull TServiceTemplate serviceTemplate = repository.getElement(id);
@NonNull TTopologyTemplate topologyTemplate = serviceTemplate.getTopologyTemplate();
/*
Get all open requirements and the basis type of the required capability type
Two different basis types are distinguished:
"Container" which means a hostedOn injection is required
"Endpoint" which means a connectsTo injection is required
*/
Map<TRequirement, String> requirementsAndMatchingBasisCapabilityTypes = getOpenRequirementsAndMatchingBasisCapabilityTypeNames(topologyTemplate);
// Output check
for (TRequirement req : requirementsAndMatchingBasisCapabilityTypes.keySet()) {
System.out.println("open Requirement: " + req.getId());
System.out.println("matchingbasisType: " + requirementsAndMatchingBasisCapabilityTypes.get(req));
}
TTopologyTemplate matchedConnectedTopologyTemplate;
if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Container")) {
@NonNull TTopologyTemplate matchedHostsTopologyTemplate = hostMatchingWithDefaultLabelingAndHostSelection(topologyTemplate);
if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
matchedConnectedTopologyTemplate = connectionMatchingWithDefaultConnectorSelection(matchedHostsTopologyTemplate);
} else {
matchedConnectedTopologyTemplate = matchedHostsTopologyTemplate;
}
} else if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
matchedConnectedTopologyTemplate = connectionMatchingWithDefaultConnectorSelection(topologyTemplate);
} else {
throw new SplittingException("No open Requirements which can be matched");
}
TTopologyTemplate daSpecifiedTopology = matchedConnectedTopologyTemplate;
// Start additional functionality Driver Injection
if (!DASpecification.getNodeTemplatesWithAbstractDAs(matchedConnectedTopologyTemplate).isEmpty() && DASpecification.getNodeTemplatesWithAbstractDAs(matchedConnectedTopologyTemplate) != null) {
daSpecifiedTopology = DriverInjection.injectDriver(matchedConnectedTopologyTemplate);
}
// End additional functionality Driver Injection
// create wrapper service template
ServiceTemplateId matchedServiceTemplateId = new ServiceTemplateId(id.getNamespace().getDecoded(), id.getXmlId().getDecoded() + "-matched", false);
RepositoryFactory.getRepository().forceDelete(matchedServiceTemplateId);
RepositoryFactory.getRepository().flagAsExisting(matchedServiceTemplateId);
repository.flagAsExisting(matchedServiceTemplateId);
TServiceTemplate matchedServiceTemplate = new TServiceTemplate();
matchedServiceTemplate.setName(matchedServiceTemplateId.getXmlId().getDecoded());
matchedServiceTemplate.setId(matchedServiceTemplate.getName());
matchedServiceTemplate.setTargetNamespace(id.getNamespace().getDecoded());
matchedServiceTemplate.setTopologyTemplate(daSpecifiedTopology);
LOGGER.debug("Persisting...");
repository.setElement(matchedServiceTemplateId, matchedServiceTemplate);
LOGGER.debug("Persisted.");
long duration = System.currentTimeMillis() - start;
LOGGER.debug("Execution Time in millisec: " + duration + "ms");
return matchedServiceTemplateId;
}
use of org.eclipse.jdt.annotation.NonNull in project winery by eclipse.
the class GenericImportResource method getFile.
@GET
@Path("{filename}")
public Response getFile(@PathParam("filename") @NonNull final String encodedFileName) {
Objects.requireNonNull(encodedFileName);
final Optional<TImport> theImport = ImportUtils.getTheImport((GenericImportId) id);
if (!theImport.isPresent()) {
return Response.status(Status.NOT_FOUND).build();
}
@Nullable final String location = theImport.get().getLocation();
@NonNull String fileName = Util.URLdecode(encodedFileName);
if (!fileName.equals(location)) {
LOGGER.debug("Filename mismatch %s vs %s", fileName, location);
return Response.status(Status.NOT_FOUND).build();
}
RepositoryFileReference ref = new RepositoryFileReference(this.id, location);
return RestUtils.returnRepoPath(ref, null);
}
Aggregations