use of org.eclipse.winery.model.tosca.TCapabilityDefinition in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(NodeTypeId id) {
Collection<DefinitionsChildId> ids = new ArrayList<>();
Collection<NodeTypeImplementationId> allNodeTypeImplementations = this.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, id.getQName());
for (NodeTypeImplementationId ntiId : allNodeTypeImplementations) {
ids.add(ntiId);
}
final TNodeType nodeType = this.getElement(id);
// add all referenced requirement types
TNodeType.RequirementDefinitions reqDefsContainer = nodeType.getRequirementDefinitions();
if (reqDefsContainer != null) {
List<TRequirementDefinition> reqDefs = reqDefsContainer.getRequirementDefinition();
for (TRequirementDefinition reqDef : reqDefs) {
RequirementTypeId reqTypeId = new RequirementTypeId(reqDef.getRequirementType());
ids.add(reqTypeId);
}
}
// add all referenced capability types
TNodeType.CapabilityDefinitions capDefsContainer = nodeType.getCapabilityDefinitions();
if (capDefsContainer != null) {
List<TCapabilityDefinition> capDefs = capDefsContainer.getCapabilityDefinition();
for (TCapabilityDefinition capDef : capDefs) {
CapabilityTypeId capTypeId = new CapabilityTypeId(capDef.getCapabilityType());
ids.add(capTypeId);
}
}
return ids;
}
use of org.eclipse.winery.model.tosca.TCapabilityDefinition in project winery by eclipse.
the class RequirementOrCapabilityDefinitionsResource method onPost.
@POST
// As there is no supertype of TCapabilityType and TRequirementType containing the common attributes, we have to rely on unchecked casts
@SuppressWarnings("unchecked")
@Consumes(MediaType.APPLICATION_JSON)
public Response onPost(CapabilityDefinitionPostData postData) {
if (StringUtils.isEmpty(postData.name)) {
return Response.status(Status.BAD_REQUEST).entity("Name has to be provided").build();
}
if (StringUtils.isEmpty(postData.type)) {
return Response.status(Status.BAD_REQUEST).entity("Type has to be provided").build();
}
int lbound = 1;
if (!StringUtils.isEmpty(postData.lowerBound)) {
try {
lbound = Integer.parseInt(postData.lowerBound);
} catch (NumberFormatException e) {
return Response.status(Status.BAD_REQUEST).entity("Bad format of lowerbound: " + e.getMessage()).build();
}
}
String ubound = "1";
if (!StringUtils.isEmpty(postData.upperBound)) {
ubound = postData.upperBound;
}
// we also support replacement of existing requirements
// therefore, we loop through the existing requirements
int idx = -1;
boolean found = false;
for (ReqDefOrCapDef d : this.list) {
idx++;
if (this.getId(d).equals(postData.name)) {
found = true;
break;
}
}
QName typeQName = QName.valueOf(postData.type);
// Create object and put type in it
ReqDefOrCapDef def;
if (this instanceof CapabilityDefinitionsResource) {
def = (ReqDefOrCapDef) new TCapabilityDefinition();
((TCapabilityDefinition) def).setCapabilityType(typeQName);
} else {
assert (this instanceof RequirementDefinitionsResource);
def = (ReqDefOrCapDef) new TRequirementDefinition();
((TRequirementDefinition) def).setRequirementType(typeQName);
}
// copy all other data into object
AbstractReqOrCapDefResource.invokeSetter(def, "setName", postData.name);
AbstractReqOrCapDefResource.invokeSetter(def, "setLowerBound", lbound);
AbstractReqOrCapDefResource.invokeSetter(def, "setUpperBound", ubound);
if (found) {
// replace element
this.list.set(idx, def);
} else {
// add new element
this.list.add(def);
}
return RestUtils.persist(this.res);
}
Aggregations