Search in sources :

Example 1 with CreateFromArtifactApiData

use of org.eclipse.winery.repository.rest.resources._support.CreateFromArtifactApiData in project winery by eclipse.

the class ServiceTemplatesResource method getCreateFromArtifactData.

@GET
@Path("createfromartifact")
@Produces(MediaType.APPLICATION_JSON)
public CreateFromArtifactApiData getCreateFromArtifactData() {
    Set<QName> artifactTypes = new HashSet<QName>();
    Set<QName> infrastructureNodeTypes = new HashSet<QName>();
    Collection<AbstractComponentInstanceResource> templates = this.getAll();
    for (AbstractComponentInstanceResource resource : templates) {
        if (resource instanceof ServiceTemplateResource) {
            ServiceTemplateResource stRes = (ServiceTemplateResource) resource;
            if (stRes.getServiceTemplate().getTags() != null) {
                int check = 0;
                QName artifactType = null;
                for (TTag tag : stRes.getServiceTemplate().getTags().getTag()) {
                    switch(tag.getName()) {
                        case "xaasPackageNode":
                            check++;
                            break;
                        case "xaasPackageArtifactType":
                            check++;
                            artifactType = QName.valueOf(tag.getValue());
                            break;
                        case "xaasPackageDeploymentArtifact":
                            check++;
                            break;
                        case "xaasPackageInfrastructure":
                            // optional tag, hence no check++
                            infrastructureNodeTypes.add(QName.valueOf(tag.getValue()));
                        default:
                            break;
                    }
                }
                if (check == 3) {
                    artifactTypes.add(artifactType);
                }
            }
        }
    }
    return new CreateFromArtifactApiData(artifactTypes, infrastructureNodeTypes);
}
Also used : TTag(org.eclipse.winery.model.tosca.TTag) CreateFromArtifactApiData(org.eclipse.winery.repository.rest.resources._support.CreateFromArtifactApiData) QName(javax.xml.namespace.QName) AbstractComponentInstanceResource(org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResource)

Aggregations

QName (javax.xml.namespace.QName)1 TTag (org.eclipse.winery.model.tosca.TTag)1 AbstractComponentInstanceResource (org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResource)1 CreateFromArtifactApiData (org.eclipse.winery.repository.rest.resources._support.CreateFromArtifactApiData)1