use of org.eclipse.winery.common.ids.definitions.PolicyTemplateId in project winery by eclipse.
the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.
public static Definitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
final Definitions definitions = createWrapperDefinitions(id);
HasIdInIdOrNameField element;
if (id instanceof RelationshipTypeImplementationId) {
element = new TRelationshipTypeImplementation();
} else if (id instanceof NodeTypeImplementationId) {
element = new TNodeTypeImplementation();
} else if (id instanceof RequirementTypeId) {
element = new TRequirementType();
} else if (id instanceof NodeTypeId) {
element = new TNodeType();
} else if (id instanceof RelationshipTypeId) {
element = new TRelationshipType();
} else if (id instanceof CapabilityTypeId) {
element = new TCapabilityType();
} else if (id instanceof ArtifactTypeId) {
element = new TArtifactType();
} else if (id instanceof PolicyTypeId) {
element = new TPolicyType();
} else if (id instanceof PolicyTemplateId) {
element = new TPolicyTemplate();
} else if (id instanceof ServiceTemplateId) {
element = new TServiceTemplate();
} else if (id instanceof ArtifactTemplateId) {
element = new TArtifactTemplate();
} else if (id instanceof XSDImportId) {
// TImport has no id; thus directly generating it without setting an id
TImport tImport = new TImport();
definitions.setElement(tImport);
return definitions;
} else {
throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
}
copyIdToFields(element, id);
definitions.setElement((TExtensibleElements) element);
return definitions;
}
use of org.eclipse.winery.common.ids.definitions.PolicyTemplateId in project winery by eclipse.
the class BackendUtilsTestWithGitBackedRepository method initializePropertiesDoesNothingInTheCaseOfXmlElemenetPropperties.
@Test
public void initializePropertiesDoesNothingInTheCaseOfXmlElemenetPropperties() throws Exception {
this.setRevisionTo("origin/plain");
PolicyTemplateId policyTemplateId = new PolicyTemplateId("http://www.example.org", "policytemplate", false);
// create prepared policy template
final IRepository repository = RepositoryFactory.getRepository();
final Definitions definitions = BackendUtils.createWrapperDefinitionsAndInitialEmptyElement(repository, policyTemplateId);
final TPolicyTemplate policyTemplate = (TPolicyTemplate) definitions.getElement();
QName policyTypeQName = new QName("http://plain.winery.opentosca.org/policytypes", "PolicyTypeWithXmlElementProperty");
policyTemplate.setType(policyTypeQName);
BackendUtils.initializeProperties(repository, policyTemplate);
Assert.assertNull(policyTemplate.getProperties());
}
use of org.eclipse.winery.common.ids.definitions.PolicyTemplateId in project winery by eclipse.
the class BackendUtilsTestWithGitBackedRepository method initializePropertiesGeneratesCorrectKvProperties.
@Test
public void initializePropertiesGeneratesCorrectKvProperties() throws Exception {
this.setRevisionTo("origin/plain");
PolicyTemplateId policyTemplateId = new PolicyTemplateId("http://www.example.org", "policytemplate", false);
// create prepared policy template
final IRepository repository = RepositoryFactory.getRepository();
final Definitions definitions = BackendUtils.createWrapperDefinitionsAndInitialEmptyElement(repository, policyTemplateId);
final TPolicyTemplate policyTemplate = (TPolicyTemplate) definitions.getElement();
QName policyTypeQName = new QName("http://plain.winery.opentosca.org/policytypes", "PolicyTypeWithTwoKvProperties");
policyTemplate.setType(policyTypeQName);
BackendUtils.initializeProperties(repository, policyTemplate);
Assert.assertNotNull(policyTemplate.getProperties());
LinkedHashMap<String, String> kvProperties = policyTemplate.getProperties().getKVProperties();
LinkedHashMap<String, String> expectedPropertyKVS = new LinkedHashMap<>();
expectedPropertyKVS.put("key1", "");
expectedPropertyKVS.put("key2", "");
Assert.assertEquals(expectedPropertyKVS, kvProperties);
}
use of org.eclipse.winery.common.ids.definitions.PolicyTemplateId in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ServiceTemplateId id) {
// We have to use a HashSet to ensure that no duplicate ids are added
// E.g., there may be multiple relationship templates having the same type
Collection<DefinitionsChildId> ids = new HashSet<>();
TServiceTemplate serviceTemplate = this.getElement(id);
// add included things to export queue
TBoundaryDefinitions boundaryDefs;
if ((boundaryDefs = serviceTemplate.getBoundaryDefinitions()) != null) {
TBoundaryDefinitions.Policies policies = boundaryDefs.getPolicies();
if (policies != null) {
for (TPolicy policy : policies.getPolicy()) {
PolicyTypeId policyTypeId = new PolicyTypeId(policy.getPolicyType());
ids.add(policyTypeId);
PolicyTemplateId policyTemplateId = new PolicyTemplateId(policy.getPolicyRef());
ids.add(policyTemplateId);
}
}
// reqs and caps don't have to be exported here as they are references to existing reqs/caps (of nested node templates)
}
if (serviceTemplate.getTopologyTemplate() != null) {
for (TEntityTemplate entityTemplate : serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) {
QName qname = entityTemplate.getType();
if (entityTemplate instanceof TNodeTemplate) {
ids.add(new NodeTypeId(qname));
TNodeTemplate n = (TNodeTemplate) entityTemplate;
// crawl through deployment artifacts
TDeploymentArtifacts deploymentArtifacts = n.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
List<TDeploymentArtifact> das = deploymentArtifacts.getDeploymentArtifact();
for (TDeploymentArtifact da : das) {
ids.add(new ArtifactTypeId(da.getArtifactType()));
if ((qname = da.getArtifactRef()) != null) {
ids.add(new ArtifactTemplateId(qname));
}
}
}
// crawl through reqs/caps
TNodeTemplate.Requirements requirements = n.getRequirements();
if (requirements != null) {
for (TRequirement req : requirements.getRequirement()) {
QName type = req.getType();
RequirementTypeId rtId = new RequirementTypeId(type);
ids.add(rtId);
}
}
TNodeTemplate.Capabilities capabilities = n.getCapabilities();
if (capabilities != null) {
for (TCapability cap : capabilities.getCapability()) {
QName type = cap.getType();
CapabilityTypeId ctId = new CapabilityTypeId(type);
ids.add(ctId);
}
}
// crawl through policies
org.eclipse.winery.model.tosca.TNodeTemplate.Policies policies = n.getPolicies();
if (policies != null) {
for (TPolicy pol : policies.getPolicy()) {
QName type = pol.getPolicyType();
PolicyTypeId ctId = new PolicyTypeId(type);
ids.add(ctId);
QName template = pol.getPolicyRef();
if (template != null) {
PolicyTemplateId policyTemplateId = new PolicyTemplateId(template);
ids.add(policyTemplateId);
}
}
}
} else {
assert (entityTemplate instanceof TRelationshipTemplate);
ids.add(new RelationshipTypeId(qname));
}
}
}
return ids;
}
use of org.eclipse.winery.common.ids.definitions.PolicyTemplateId in project winery by eclipse.
the class AbstractComponentsResource method onPost.
/**
* Creates a new component instance in the given namespace
*
* @param namespace plain namespace
* @param name the name; used as id
*/
protected ResourceCreationResult onPost(String namespace, String name) {
ResourceCreationResult res;
if (StringUtils.isEmpty(namespace) || StringUtils.isEmpty(name)) {
res = new ResourceCreationResult(Status.BAD_REQUEST);
} else {
String id = RestUtils.createXMLidAsString(name);
DefinitionsChildId tcId;
try {
tcId = this.getDefinitionsChildId(namespace, id, false);
res = this.createComponentInstance(tcId);
// in case the resource additionally supports a name attribute, we set the original name
if (res.getStatus().equals(Status.CREATED)) {
if ((tcId instanceof ServiceTemplateId) || (tcId instanceof ArtifactTemplateId) || (tcId instanceof PolicyTemplateId)) {
// these three types have an additional name (instead of a pure id)
// we store the name
IHasName resource = (IHasName) AbstractComponentsResource.getComponentInstaceResource(tcId);
resource.setName(name);
}
}
} catch (Exception e) {
AbstractComponentsResource.LOGGER.debug("Could not create id instance", e);
res = new ResourceCreationResult(Status.INTERNAL_SERVER_ERROR);
}
}
return res;
}
Aggregations