use of org.eclipse.winery.model.tosca.TInterface in project winery by eclipse.
the class EdmmConverter method createOperations.
private void createOperations(TEntityType type, EntityId nodeTypeEntityId, EntityGraph entityGraph) {
if (type instanceof TNodeType && Objects.nonNull(((TNodeType) type).getInterfaces())) {
List<TInterface> interfaces = ((TNodeType) type).getInterfaces();
interfaces.forEach(anInterface -> {
anInterface.getOperations().forEach(operation -> {
EntityId operationsEntityId = nodeTypeEntityId.extend(DefaultKeys.OPERATIONS);
entityGraph.addEntity(new MappingEntity(operationsEntityId, entityGraph));
TNodeTypeImplementation implementation = nodeTypeImplementations.values().stream().filter(impl -> impl.getNodeType().equals(type.getQName())).findFirst().orElse(null);
String path = getImplementationForOperation(implementation, anInterface.getName(), operation.getName());
EntityId operationId = operationsEntityId.extend(operation.getName());
createPathReferenceEntity(entityGraph, path, operationId);
});
});
}
}
use of org.eclipse.winery.model.tosca.TInterface 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.tosca.TInterface in project winery by eclipse.
the class Splitting method getInputParamListofIncomingRelationshipTemplates.
public List<TParameter> getInputParamListofIncomingRelationshipTemplates(TTopologyTemplate topologyTemplate, List<TRelationshipTemplate> listOfIncomingRelationshipTemplates) {
List<TParameter> listOfInputs = new ArrayList<>();
IRepository repo = RepositoryFactory.getRepository();
for (TRelationshipTemplate incomingRelationshipTemplate : listOfIncomingRelationshipTemplates) {
TNodeTemplate incomingNodetemplate = ModelUtilities.getSourceNodeTemplateOfRelationshipTemplate(topologyTemplate, incomingRelationshipTemplate);
NodeTypeId incomingNodeTypeId = new NodeTypeId(incomingNodetemplate.getType());
TNodeType incomingNodeType = repo.getElement(incomingNodeTypeId);
List<TInterface> incomingNodeTypeInterfaces = incomingNodeType.getInterfaces();
RelationshipTypeId incomingRelationshipTypeId = new RelationshipTypeId(incomingRelationshipTemplate.getType());
if (!incomingNodeTypeInterfaces.isEmpty()) {
TInterface relevantInterface = null;
List<TInterface> connectionInterfaces = incomingNodeTypeInterfaces.stream().filter(tInterface -> tInterface.getIdFromIdOrNameField().contains("connection")).collect(Collectors.toList());
if (connectionInterfaces.size() > 1) {
TNodeTemplate targetNodeTemplate = ModelUtilities.getTargetNodeTemplateOfRelationshipTemplate(topologyTemplate, incomingRelationshipTemplate);
for (TInterface tInterface : connectionInterfaces) {
int separator = tInterface.getIdFromIdOrNameField().lastIndexOf("/");
String prefixRelation = tInterface.getIdFromIdOrNameField().substring(separator + 1);
if (targetNodeTemplate.getName() != null && targetNodeTemplate.getName().toLowerCase().contains(prefixRelation.toLowerCase())) {
relevantInterface = tInterface;
}
}
} else {
relevantInterface = connectionInterfaces.get(0);
}
if (relevantInterface != null) {
for (TOperation tOperation : relevantInterface.getOperations()) {
List<TParameter> inputParameters = tOperation.getInputParameters();
if (inputParameters != null) {
listOfInputs.addAll(inputParameters);
}
}
}
}
}
return listOfInputs;
}
use of org.eclipse.winery.model.tosca.TInterface in project winery by eclipse.
the class GenericArtifactsResource method findInterface.
private Optional<TInterface> findInterface(EntityTypeId id, String interfaceName) {
TInterface i;
List<TInterface> interfaces = new ArrayList<>();
IRepository repository = RepositoryFactory.getRepository();
if (this.res instanceof NodeTypeImplementationResource || this.res instanceof NodeTypeImplementationsResource) {
TNodeType nodeType = repository.getElement((NodeTypeId) id);
if (nodeType.getInterfaces() != null) {
interfaces.addAll(nodeType.getInterfaces());
}
} else if (this.res instanceof RelationshipTypeImplementationResource || this.res instanceof RelationshipTypeImplementationsResource) {
TRelationshipType relationshipType = repository.getElement((RelationshipTypeId) id);
if (relationshipType.getSourceInterfaces() != null) {
interfaces.addAll(relationshipType.getSourceInterfaces());
}
if (relationshipType.getTargetInterfaces() != null) {
interfaces.addAll(relationshipType.getTargetInterfaces());
}
if (relationshipType.getInterfaces() != null) {
interfaces.addAll(relationshipType.getInterfaces());
}
}
Iterator<TInterface> it = interfaces.iterator();
do {
i = it.next();
if (i.getName().equals(interfaceName)) {
return Optional.of(i);
}
} while (it.hasNext());
return Optional.empty();
}
use of org.eclipse.winery.model.tosca.TInterface in project winery by eclipse.
the class GeneratorTest method testInOut.
@Test
public void testInOut() throws Exception {
TInterface tinterface = new TInterface();
tinterface.setName("http://www.example.org/interfaces/lifecycle");
TOperation op1 = new TOperation();
op1.setName("Op1InOut");
tinterface.getOperation().add(op1);
TOperation.InputParameters op1InputParameters = new TOperation.InputParameters();
TParameter op1ip1 = new TParameter();
op1ip1.setName("op1ip1");
op1ip1.setType("xs:string");
op1InputParameters.getInputParameter().add(op1ip1);
TParameter op1ip2 = new TParameter();
op1ip2.setName("op1ip2");
op1ip2.setType("xs:string");
op1InputParameters.getInputParameter().add(op1ip2);
op1.setInputParameters(op1InputParameters);
TOperation.OutputParameters op1OutputParameters = new TOperation.OutputParameters();
TParameter op1op1 = new TParameter();
op1op1.setName("op1op1");
op1op1.setType("xs:string");
op1OutputParameters.getOutputParameter().add(op1op1);
TParameter op1op2 = new TParameter();
op1op2.setName("op1op2");
op1op1.setType("xs:string");
op1OutputParameters.getOutputParameter().add(op1op2);
op1.setOutputParameters(op1OutputParameters);
TNodeType nodeType = new TNodeType();
nodeType.setName("test");
nodeType.setTargetNamespace("http://asd.com");
Generator gen = new Generator(tinterface, "org.opentosca.ia", new URL("http://asd.com"), "testname", WORKING_DIR.toFile());
Path generateProject = gen.generateProject();
System.out.println(generateProject);
}
Aggregations