use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class ServiceTemplateResource method generatePlaceholdersWithCapability.
@POST
@Path("placeholder/generator")
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
public Response generatePlaceholdersWithCapability() {
Splitting splitting = new Splitting();
TTopologyTemplate topologyTemplate = this.getServiceTemplate().getTopologyTemplate();
if (topologyTemplate == null) {
return Response.notModified().build();
}
try {
// get all open requirements and the respective node templates with open requirements
Map<TRequirement, TNodeTemplate> requirementsAndItsNodeTemplates = splitting.getOpenRequirementsAndItsNodeTemplate(topologyTemplate);
IRepository repo = RepositoryFactory.getRepository();
// iterate over all open requirements
for (Map.Entry<TRequirement, TNodeTemplate> entry : requirementsAndItsNodeTemplates.entrySet()) {
List<PropertyDefinitionKV> propertyDefinitionKVList = new ArrayList<>();
LinkedHashMap<String, String> placeholderNodeTemplateProperties = new LinkedHashMap<>();
// current node template with open requirements
TNodeTemplate nodeTemplateWithOpenReq = entry.getValue();
// get type of node template with open requirements
NodeTypeId id = new NodeTypeId(nodeTemplateWithOpenReq.getType());
TNodeType sourceNodeType = repo.getElement(id);
List<TInterface> sourceNodeTypeInterfaces = sourceNodeType.getInterfaces();
if (sourceNodeTypeInterfaces != null) {
for (TInterface tInterface : sourceNodeTypeInterfaces) {
// TODO: make this more safe
for (TOperation tOperation : tInterface.getOperations()) {
List<TParameter> inputParameters = tOperation.getInputParameters();
if (inputParameters != null) {
for (TParameter inputParameter : inputParameters) {
generateInputParameters(propertyDefinitionKVList, placeholderNodeTemplateProperties, sourceNodeType, inputParameter);
}
}
}
}
}
List<TRelationshipTemplate> incomingRelationshipTemplates = ModelUtilities.getIncomingRelationshipTemplates(topologyTemplate, nodeTemplateWithOpenReq);
List<TParameter> inputParameters = splitting.getInputParamListofIncomingRelationshipTemplates(topologyTemplate, incomingRelationshipTemplates);
for (TParameter inputParameter : inputParameters) {
String prefixTARGET = "TARGET_";
String prefixSOURCE = "SOURCE_";
String inputParamName = inputParameter.getName();
if (inputParamName.contains(prefixTARGET)) {
inputParamName = inputParamName.replaceAll(prefixTARGET, "");
}
if (inputParamName.contains(prefixSOURCE)) {
inputParamName = inputParamName.replaceAll(prefixSOURCE, "");
}
inputParameter.setName(inputParamName);
generateInputParameters(propertyDefinitionKVList, placeholderNodeTemplateProperties, sourceNodeType, inputParameter);
}
// get required capability type of open requirement
QName capabilityType = splitting.getRequiredCapabilityTypeQNameOfRequirement(entry.getKey());
// create new placeholder node type
TNodeType placeholderNodeType = splitting.createPlaceholderNodeType(nodeTemplateWithOpenReq.getName());
QName placeholderQName = new QName(placeholderNodeType.getTargetNamespace(), placeholderNodeType.getName());
WinerysPropertiesDefinition winerysPropertiesDefinition = sourceNodeType.getWinerysPropertiesDefinition();
// add properties definition
placeholderNodeType.setProperties(null);
if (winerysPropertiesDefinition != null) {
winerysPropertiesDefinition.setPropertyDefinitions(propertyDefinitionKVList);
placeholderNodeType.setProperties(winerysPropertiesDefinition);
String namespace = placeholderNodeType.getWinerysPropertiesDefinition().getNamespace();
NamespaceManager namespaceManager = RepositoryFactory.getRepository().getNamespaceManager();
if (!namespaceManager.hasPermanentProperties(namespace)) {
namespaceManager.addPermanentNamespace(namespace);
}
}
NodeTypeId placeholderId = new NodeTypeId(placeholderQName);
// check if placeholder node type exists
if (repo.exists(placeholderId)) {
// delete and create new
RestUtils.delete(placeholderId);
}
repo.setElement(placeholderId, placeholderNodeType);
// create placeholder node template
TNodeTemplate placeholderNodeTemplate = splitting.createPlaceholderNodeTemplate(topologyTemplate, nodeTemplateWithOpenReq.getName(), placeholderQName);
// create capability of placeholder node template
TCapability capa = splitting.createPlaceholderCapability(topologyTemplate, capabilityType);
ModelUtilities.setPropertiesKV(placeholderNodeTemplate, placeholderNodeTemplateProperties);
if (placeholderNodeTemplate.getCapabilities() == null) {
placeholderNodeTemplate.setCapabilities(new ArrayList<>());
}
placeholderNodeTemplate.getCapabilities().add(capa);
for (Map.Entry<QName, String> targetLocation : nodeTemplateWithOpenReq.getOtherAttributes().entrySet()) {
placeholderNodeTemplate.getOtherAttributes().put(targetLocation.getKey(), targetLocation.getValue());
}
// add placeholder to node template and connect with source node template with open requirements
topologyTemplate.addNodeTemplate(placeholderNodeTemplate);
ModelUtilities.createRelationshipTemplateAndAddToTopology(nodeTemplateWithOpenReq, placeholderNodeTemplate, ToscaBaseTypes.hostedOnRelationshipType, topologyTemplate);
}
LOGGER.debug("PERSISTING");
RestUtils.persist(this);
LOGGER.debug("PERSISTED");
String responseId = this.getServiceTemplate().getId();
return Response.ok().entity(responseId).build();
} catch (Exception e) {
LOGGER.error("Could not fetch requirements and capabilities", e);
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
}
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class TopologyTemplateResource method computeDi.
@POST
@Path("kvcomparison")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public PropertyDiffList computeDi(UpdateInfo updateInfo) {
List<String> resolvedProperties = new ArrayList<>();
List<String> removedProperties = new ArrayList<>();
List<String> newProperties = new ArrayList<>();
Optional<TEntityTemplate> foundTemplate = topologyTemplate.getNodeTemplateOrRelationshipTemplate().stream().filter(template -> template.getId().equals(updateInfo.getNodeTemplateId())).filter(template -> template.getProperties() != null).findFirst();
if (foundTemplate.isPresent() && Objects.nonNull(foundTemplate.get().getProperties()) && Objects.nonNull(ModelUtilities.getPropertiesKV(foundTemplate.get()))) {
HashMap<String, String> oldKvs = ModelUtilities.getPropertiesKV(foundTemplate.get());
QName qNameType = QName.valueOf(updateInfo.getNewComponentType());
IRepository repository = RepositoryFactory.getRepository();
TEntityType newNodeTypeVersion = repository.getElement(new NodeTypeId(qNameType));
if (Objects.nonNull(newNodeTypeVersion) && Objects.nonNull(newNodeTypeVersion.getWinerysPropertiesDefinition())) {
List<PropertyDefinitionKV> newKvs = newNodeTypeVersion.getWinerysPropertiesDefinition().getPropertyDefinitions();
resolvedProperties = newKvs.stream().map(PropertyDefinitionKV::getKey).filter(keys -> oldKvs.keySet().stream().map(String::toLowerCase).collect(Collectors.toList()).contains(keys.toLowerCase())).collect(Collectors.toList());
removedProperties = oldKvs.keySet().stream().filter(keys -> !newKvs.stream().map(newProp -> newProp.getKey().toLowerCase()).collect(Collectors.toList()).contains(keys.toLowerCase())).collect(Collectors.toList());
newProperties = newKvs.stream().map(PropertyDefinitionKV::getKey).filter(keys -> !oldKvs.keySet().stream().map(String::toLowerCase).collect(Collectors.toList()).contains(keys.toLowerCase())).collect(Collectors.toList());
}
}
return new PropertyDiffList(resolvedProperties, removedProperties, newProperties);
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class TopologyTemplateResource method getNewVersionList.
@GET
@Path("newversions")
@Produces(MediaType.APPLICATION_JSON)
public List<NewVersionListElement> getNewVersionList() {
IRepository repository = RepositoryFactory.getRepository();
Map<QName, TNodeType> nodeTypes = repository.getQNameToElementMapping(NodeTypeId.class);
Map<QName, List<WineryVersion>> versionElements = new HashMap<>();
for (TNodeTemplate node : this.topologyTemplate.getNodeTemplates()) {
if (nodeTypes.containsKey(node.getType())) {
NodeTypeId nodeTypeId = new NodeTypeId(node.getType());
if (!versionElements.containsKey(nodeTypeId.getQName())) {
List<WineryVersion> versionList = WineryVersionUtils.getAllVersionsOfOneDefinition(nodeTypeId, repository).stream().filter(wineryVersion -> {
QName qName = VersionSupport.getDefinitionInTheGivenVersion(nodeTypeId, wineryVersion).getQName();
NamespaceProperties namespaceProperties = repository.getNamespaceManager().getNamespaceProperties(qName.getNamespaceURI());
return !(namespaceProperties.isGeneratedNamespace() || ModelUtilities.isFeatureType(qName, nodeTypes));
}).collect(Collectors.toList());
versionElements.put(nodeTypeId.getQName(), versionList);
}
}
}
return versionElements.entrySet().stream().map(qNameListEntry -> new NewVersionListElement(qNameListEntry.getKey(), qNameListEntry.getValue())).collect(Collectors.toList());
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class RestUtilsWithGitBackendTest method releaseComponentWhichHasNotBeenCommitted.
@Test
public void releaseComponentWhichHasNotBeenCommitted() throws Exception {
this.setRevisionTo("origin/plain");
NodeTypeId id = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWithALowerReleasableManagementVersion_2-w2-wip1", false);
NodeTypeId releasedId = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWithALowerReleasableManagementVersion_2-w2", false);
int formerVersionCount = WineryVersionUtils.getAllVersionsOfOneDefinition(id, repository).size();
// simulate a non-committed component
makeSomeChanges(id);
Response response = RestUtils.releaseVersion(id);
int finalVersionCount = WineryVersionUtils.getAllVersionsOfOneDefinition(releasedId, repository).size();
WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(releasedId, repository);
assertEquals(201, response.getStatus());
assertEquals(formerVersionCount + 1, finalVersionCount);
assertFalse(version.isReleasable());
assertEquals(0, version.getWorkInProgressVersion());
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeId in project winery by eclipse.
the class RestUtilsWithGitBackendTest method getFlagsOfAReleasedVersion.
@Test
public void getFlagsOfAReleasedVersion() throws Exception {
this.setRevisionTo("origin/plain");
DefinitionsChildId id = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWith5Versions_0.3.4-w3", false);
WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(id, repository);
assertFalse(version.isReleasable());
assertFalse(version.isEditable());
assertTrue(version.isCurrentVersion());
assertTrue(version.isLatestVersion());
}
Aggregations