Search in sources :

Example 1 with NodeTypeImplementationsResource

use of org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationsResource in project winery by eclipse.

the class EdmmResource method createPlaceholders.

@POST
@Consumes(MediaType.TEXT_PLAIN)
@Path("create-placeholders-scripts")
public Response createPlaceholders(String componentType, @Context UriInfo uriInfo) throws IOException {
    // adding the interface to the component node type
    NodeTypeResource nodeTypeResource = new NodeTypesResource().getComponentInstanceResource(EncodingUtil.URLencode(NODE_TYPES), componentType);
    // the interfaces will be overridden
    nodeTypeResource.getInterfaces().onPost(buildInterfacesForNodeType(LIFECYCLE_NAME, LIFECYCLE));
    for (String operation : LIFECYCLE) {
        // adding a new artifact template
        final String artifactLocalName = componentType + "-" + StringUtils.capitalize(operation);
        ArtifactTemplatesResource artifactTemplatesResource = new ArtifactTemplatesResource();
        QNameWithTypeApiData qNameWithTypeApiData = new QNameWithTypeApiData(artifactLocalName, ARTIFACT_TEMPLATES, "{" + ARTIFACT_TYPES + "}Script");
        artifactTemplatesResource.onJsonPost(qNameWithTypeApiData);
        // adding the placeholder file
        ArtifactTemplateResource artifactTemplateResource = artifactTemplatesResource.getComponentInstanceResource(EncodingUtil.URLencode(ARTIFACT_TEMPLATES), artifactLocalName);
        boolean fileExists = artifactTemplateResource.getFilesResource().getAllFileMetas().stream().anyMatch(fileMeta -> fileMeta.getName().equals(operation + ".sh"));
        // if the file exists it will be overridden, but we do not want that.
        if (!fileExists) {
            artifactTemplateResource.getFilesResource().putContentToFile(operation + ".sh", getPlaceholderFile(operation), "text/x-sh");
            artifactTemplateResource.synchronizeReferences();
        }
        // creating a new node type implementation
        String nodeTypeImplementationLocalName = componentType + "-IA";
        NodeTypeImplementationsResource nodeTypeImplementationsResource = new NodeTypeImplementationsResource();
        qNameWithTypeApiData = new QNameWithTypeApiData(nodeTypeImplementationLocalName, NODE_TYPE_IMPLEMENTATIONS, "{" + NODE_TYPES + "}" + componentType);
        nodeTypeImplementationsResource.onJsonPost(qNameWithTypeApiData);
        // linking the artifact template to the node type implementation
        NodeTypeImplementationResource nodeTypeImplementationResource = nodeTypeImplementationsResource.getComponentInstanceResource(EncodingUtil.URLencode(NODE_TYPE_IMPLEMENTATIONS), nodeTypeImplementationLocalName);
        GenerateArtifactApiData artifactApiData = new GenerateArtifactApiData();
        artifactApiData.artifactName = operation;
        artifactApiData.artifactTemplate = "{" + ARTIFACT_TEMPLATES + "}" + artifactLocalName;
        artifactApiData.interfaceName = LIFECYCLE_NAME;
        artifactApiData.operationName = operation;
        boolean implementationResourceExists = nodeTypeImplementationResource.getImplementationArtifacts().getAllArtifactResources().stream().anyMatch(artifactResource -> {
            TImplementationArtifact implementationArtifact = artifactResource.getImplementationArtifact();
            return operation.equals(implementationArtifact.getOperationName()) && LIFECYCLE_NAME.equals(implementationArtifact.getInterfaceName()) && implementationArtifact.getArtifactRef() != null && artifactApiData.artifactTemplate.equals(implementationArtifact.getArtifactRef().toString());
        });
        if (!implementationResourceExists) {
            nodeTypeImplementationResource.getImplementationArtifacts().generateArtifact(artifactApiData, uriInfo);
        }
    }
    return Response.status(Response.Status.CREATED).build();
}
Also used : TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) NodeTypeImplementationsResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationsResource) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) NodeTypeResource(org.eclipse.winery.repository.rest.resources.entitytypes.nodetypes.NodeTypeResource) NodeTypeImplementationResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationResource) GenerateArtifactApiData(org.eclipse.winery.repository.rest.resources.apiData.GenerateArtifactApiData) NodeTypesResource(org.eclipse.winery.repository.rest.resources.entitytypes.nodetypes.NodeTypesResource) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 2 with NodeTypeImplementationsResource

use of org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationsResource 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();
}
Also used : TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) RelationshipTypeImplementationsResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.relationshiptypeimplementations.RelationshipTypeImplementationsResource) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) TInterface(org.eclipse.winery.model.tosca.TInterface) INodeTemplateResourceOrNodeTypeImplementationResourceOrRelationshipTypeImplementationResource(org.eclipse.winery.repository.rest.resources._support.INodeTemplateResourceOrNodeTypeImplementationResourceOrRelationshipTypeImplementationResource) RelationshipTypeImplementationResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.relationshiptypeimplementations.RelationshipTypeImplementationResource) NodeTypeImplementationsResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationsResource) ArrayList(java.util.ArrayList) NodeTypeImplementationResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationResource) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeType(org.eclipse.winery.model.tosca.TNodeType)

Aggregations

NodeTypeImplementationResource (org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationResource)2 NodeTypeImplementationsResource (org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationsResource)2 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)1 TImplementationArtifact (org.eclipse.winery.model.tosca.TImplementationArtifact)1 TInterface (org.eclipse.winery.model.tosca.TInterface)1 TNodeType (org.eclipse.winery.model.tosca.TNodeType)1 TRelationshipType (org.eclipse.winery.model.tosca.TRelationshipType)1 IRepository (org.eclipse.winery.repository.backend.IRepository)1 INodeTemplateResourceOrNodeTypeImplementationResourceOrRelationshipTypeImplementationResource (org.eclipse.winery.repository.rest.resources._support.INodeTemplateResourceOrNodeTypeImplementationResourceOrRelationshipTypeImplementationResource)1 GenerateArtifactApiData (org.eclipse.winery.repository.rest.resources.apiData.GenerateArtifactApiData)1 QNameWithTypeApiData (org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData)1 ArtifactTemplateResource (org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource)1 ArtifactTemplatesResource (org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource)1 RelationshipTypeImplementationResource (org.eclipse.winery.repository.rest.resources.entitytypeimplementations.relationshiptypeimplementations.RelationshipTypeImplementationResource)1 RelationshipTypeImplementationsResource (org.eclipse.winery.repository.rest.resources.entitytypeimplementations.relationshiptypeimplementations.RelationshipTypeImplementationsResource)1 NodeTypeResource (org.eclipse.winery.repository.rest.resources.entitytypes.nodetypes.NodeTypeResource)1