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();
}
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();
}
Aggregations