Search in sources :

Example 1 with TPlans

use of org.eclipse.winery.model.tosca.TPlans in project winery by eclipse.

the class BackendUtils method synchronizeReferences.

/**
 * Synchronizes the known plans with the data in the XML. When there is a stored file, but no known entry in the
 * XML, we guess "BPEL" as language and "build plan" as type.
 */
public static void synchronizeReferences(ServiceTemplateId id) throws IOException {
    final IRepository repository = RepositoryFactory.getRepository();
    final TServiceTemplate serviceTemplate = repository.getElement(id);
    // locally stored plans
    TPlans plans = serviceTemplate.getPlans();
    // plans stored in the repository
    PlansId plansContainerId = new PlansId(id);
    SortedSet<PlanId> nestedPlans = repository.getNestedIds(plansContainerId, PlanId.class);
    Set<PlanId> plansToAdd = new HashSet<>();
    plansToAdd.addAll(nestedPlans);
    if (nestedPlans.isEmpty()) {
        if (plans == null) {
            // data on the file system equals the data -> no plans
            return;
        } else {
        // noinspection StatementWithEmptyBody
        // we have to check for equality later
        }
    }
    if (plans == null) {
        plans = new TPlans();
        serviceTemplate.setPlans(plans);
    }
    for (Iterator<TPlan> iterator = plans.getPlan().iterator(); iterator.hasNext(); ) {
        TPlan plan = iterator.next();
        if (plan.getPlanModel() != null) {
            // in case, a plan is directly contained in a Model element, we do not need to do anything
            continue;
        }
        TPlan.PlanModelReference planModelReference;
        if ((planModelReference = plan.getPlanModelReference()) != null) {
            String ref = planModelReference.getReference();
            if ((ref == null) || ref.startsWith("../")) {
                // special case (due to errors in the importer): empty PlanModelReference field
                if (plan.getId() == null) {
                    // invalid plan entry: no id.
                    // we remove the entry
                    iterator.remove();
                    continue;
                }
                PlanId planId = new PlanId(plansContainerId, new XmlId(plan.getId(), false));
                if (nestedPlans.contains(planId)) {
                    // everything allright
                    // we do NOT need to add the plan on the HDD to the XML
                    plansToAdd.remove(planId);
                } else {
                    // no local storage for the plan, we remove it from the XML
                    iterator.remove();
                }
            }
        }
    }
    // add all plans locally stored, but not contained in the XML, as plan element to the plans of the service template.
    List<TPlan> thePlans = plans.getPlan();
    for (PlanId planId : plansToAdd) {
        SortedSet<RepositoryFileReference> files = repository.getContainedFiles(planId);
        if (files.size() != 1) {
            throw new IllegalStateException("Currently, only one file per plan is supported.");
        }
        RepositoryFileReference ref = files.iterator().next();
        TPlan plan = new TPlan();
        plan.setId(planId.getXmlId().getDecoded());
        plan.setName(planId.getXmlId().getDecoded());
        plan.setPlanType(org.eclipse.winery.repository.Constants.TOSCA_PLANTYPE_BUILD_PLAN);
        plan.setPlanLanguage(Namespaces.URI_BPEL20_EXECUTABLE);
        // create a PlanModelReferenceElement pointing to that file
        String path = Util.getUrlPath(ref);
        // path is relative from the definitions element
        path = "../" + path;
        TPlan.PlanModelReference pref = new TPlan.PlanModelReference();
        pref.setReference(path);
        plan.setPlanModelReference(pref);
        thePlans.add(plan);
    }
    if (serviceTemplate.getPlans().getPlan().isEmpty()) {
        serviceTemplate.setPlans(null);
    }
    RepositoryFactory.getRepository().setElement(id, serviceTemplate);
}
Also used : TPlans(org.eclipse.winery.model.tosca.TPlans) PlanId(org.eclipse.winery.common.ids.elements.PlanId) PlansId(org.eclipse.winery.common.ids.elements.PlansId) RepositoryFileReference(org.eclipse.winery.common.RepositoryFileReference) TPlan(org.eclipse.winery.model.tosca.TPlan) XmlId(org.eclipse.winery.common.ids.XmlId) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) HashSet(java.util.HashSet)

Example 2 with TPlans

use of org.eclipse.winery.model.tosca.TPlans in project winery by eclipse.

the class BoundaryDefinitionsJSPData method getlistOfAllPlans.

public List<Select2DataItem> getlistOfAllPlans() {
    TPlans plans = this.ste.getPlans();
    if (plans == null) {
        return null;
    } else {
        List<Select2DataItem> res = new ArrayList<>(plans.getPlan().size());
        for (TPlan plan : plans.getPlan()) {
            String id = plan.getId();
            String name = ModelUtilities.getNameWithIdFallBack(plan);
            Select2DataItem di = new Select2DataItem(id, name);
            res.add(di);
        }
        return res;
    }
}
Also used : TPlans(org.eclipse.winery.model.tosca.TPlans) ArrayList(java.util.ArrayList) TPlan(org.eclipse.winery.model.tosca.TPlan) Select2DataItem(org.eclipse.winery.repository.rest.datatypes.select2.Select2DataItem)

Example 3 with TPlans

use of org.eclipse.winery.model.tosca.TPlans in project winery by eclipse.

the class ServiceTemplateResource method getPlansResource.

@Path("plans/")
public PlansResource getPlansResource() {
    TPlans plans = this.getServiceTemplate().getPlans();
    if (plans == null) {
        plans = new TPlans();
        this.getServiceTemplate().setPlans(plans);
    }
    return new PlansResource(plans.getPlan(), this);
}
Also used : TPlans(org.eclipse.winery.model.tosca.TPlans) PlansResource(org.eclipse.winery.repository.rest.resources.servicetemplates.plans.PlansResource) Path(javax.ws.rs.Path)

Aggregations

TPlans (org.eclipse.winery.model.tosca.TPlans)3 TPlan (org.eclipse.winery.model.tosca.TPlan)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Path (javax.ws.rs.Path)1 RepositoryFileReference (org.eclipse.winery.common.RepositoryFileReference)1 XmlId (org.eclipse.winery.common.ids.XmlId)1 PlanId (org.eclipse.winery.common.ids.elements.PlanId)1 PlansId (org.eclipse.winery.common.ids.elements.PlansId)1 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)1 Select2DataItem (org.eclipse.winery.repository.rest.datatypes.select2.Select2DataItem)1 PlansResource (org.eclipse.winery.repository.rest.resources.servicetemplates.plans.PlansResource)1