Search in sources :

Example 1 with Component

use of orgomg.cwm.foundation.softwaredeployment.Component in project tdq-studio-se by Talend.

the class SoftwareSystemManager method cleanSoftWareSystem.

/**
 * remove the softWareSystem which have relation about dataprovider and any softWareSystem which don't contain any
 * one.
 *
 * @param dataProvider
 * @return
 * @deprecated
 */
@Deprecated
public boolean cleanSoftWareSystem(Connection dataProvider) {
    if (dataProvider == null) {
        return false;
    }
    Resource softwareSystemResource = EMFSharedResources.getInstance().getSoftwareDeploymentResource();
    if (WorkspaceUtils.getModelElementResource(softwareSystemResource.getURI()).exists()) {
        softwareSystemResource = EMFSharedResources.getInstance().reloadsoftwareDeploymentResource();
    }
    if (softwareSystemResource != null) {
        List<EObject> softwareSystems = softwareSystemResource.getContents();
        // Loop the software system from .softwaresystem.softwaredeployment file.
        List<EObject> needToRemoves = new ArrayList<EObject>();
        for (EObject softwareSystem : softwareSystems) {
            if (softwareSystem instanceof TdSoftwareSystem) {
                List<ModelElement> ownedELements = ((TdSoftwareSystem) softwareSystem).getOwnedElement();
                // Loop owned element.
                for (ModelElement me : ownedELements) {
                    if (me == null || !(me instanceof Component)) {
                        continue;
                    }
                    List<DeployedComponent> deployComponents = ((Component) me).getDeployment();
                    if (deployComponents.size() > 0) {
                        if (ResourceHelper.areSame(deployComponents.get(0), dataProvider)) {
                            needToRemoves.add(softwareSystem);
                            break;
                        }
                    } else {
                        needToRemoves.add(softwareSystem);
                    }
                }
                if (ownedELements.size() <= 0) {
                    needToRemoves.add(softwareSystem);
                }
            }
        }
        if (needToRemoves.size() > 0) {
            softwareSystems.removeAll(needToRemoves);
            EMFSharedResources.getInstance().saveSoftwareDeploymentResource();
            return true;
        }
    }
    return false;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) EObject(org.eclipse.emf.ecore.EObject) TdSoftwareSystem(org.talend.cwm.softwaredeployment.TdSoftwareSystem) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) DeployedComponent(orgomg.cwm.foundation.softwaredeployment.DeployedComponent) Component(orgomg.cwm.foundation.softwaredeployment.Component) DeployedComponent(orgomg.cwm.foundation.softwaredeployment.DeployedComponent)

Aggregations

ArrayList (java.util.ArrayList)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 TdSoftwareSystem (org.talend.cwm.softwaredeployment.TdSoftwareSystem)1 Component (orgomg.cwm.foundation.softwaredeployment.Component)1 DeployedComponent (orgomg.cwm.foundation.softwaredeployment.DeployedComponent)1 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)1