Search in sources :

Example 1 with TdSoftwareSystem

use of org.talend.cwm.softwaredeployment.TdSoftwareSystem in project tdq-studio-se by Talend.

the class SoftwareSystemManagerTest method testGetNewDBTypes.

@Test
public void testGetNewDBTypes() {
    SoftwareSystemManager softwareSystemManger = SoftwareSystemManager.getInstance();
    Set<String> existingTypes = new HashSet<String>();
    // $NON-NLS-1$
    existingTypes.add("MYSQL");
    // $NON-NLS-1$
    existingTypes.add("oracle");
    PowerMockito.mockStatic(EMFSharedResources.class);
    EMFSharedResources emfSharedResourceMock = mock(EMFSharedResources.class);
    when(EMFSharedResources.getInstance()).thenReturn(emfSharedResourceMock).thenReturn(emfSharedResourceMock);
    Resource softwareSysResource = mock(Resource.class);
    when(emfSharedResourceMock.getSoftwareDeploymentResource()).thenReturn(softwareSysResource);
    EList<EObject> existedSystems = new BasicEList<EObject>();
    TdSoftwareSystem softwareSystem1 = SoftwaredeploymentPackage.eINSTANCE.getSoftwaredeploymentFactory().createTdSoftwareSystem();
    // $NON-NLS-1$
    softwareSystem1.setSubtype("mysql");
    TdSoftwareSystem softwareSystem2 = SoftwaredeploymentPackage.eINSTANCE.getSoftwaredeploymentFactory().createTdSoftwareSystem();
    // $NON-NLS-1$
    softwareSystem2.setSubtype("VERTICA");
    TdSoftwareSystem softwareSystem3 = SoftwaredeploymentPackage.eINSTANCE.getSoftwaredeploymentFactory().createTdSoftwareSystem();
    // $NON-NLS-1$
    softwareSystem3.setSubtype("Oracle");
    existedSystems.add(softwareSystem1);
    existedSystems.add(softwareSystem2);
    existedSystems.add(softwareSystem3);
    when(softwareSysResource.getContents()).thenReturn(existedSystems);
    List<String> newTypes = softwareSystemManger.getNewDBTypesFromSoftwareSystem(existingTypes);
    Assert.assertEquals(1, newTypes.size());
    // $NON-NLS-1$
    Assert.assertEquals("VERTICA", newTypes.get(0));
}
Also used : EMFSharedResources(org.talend.dq.writer.EMFSharedResources) EObject(org.eclipse.emf.ecore.EObject) BasicEList(org.eclipse.emf.common.util.BasicEList) TdSoftwareSystem(org.talend.cwm.softwaredeployment.TdSoftwareSystem) Resource(org.eclipse.emf.ecore.resource.Resource) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with TdSoftwareSystem

use of org.talend.cwm.softwaredeployment.TdSoftwareSystem in project tdq-studio-se by Talend.

the class SoftwareSystemManager method isExistedInSoftwareSystem.

/**
 * DOC zhao Comment method "isExistedInSoftwareSystem".
 *
 * @param databaseConnection
 * @return
 */
private Boolean isExistedInSoftwareSystem(DatabaseConnection databaseConnection, List<EObject> softwareSystems) throws TalendException {
    String databaseType = TaggedValueHelper.getValueString(TaggedValueHelper.DB_PRODUCT_NAME, databaseConnection);
    if (StringUtils.isEmpty(databaseType)) {
        // $NON-NLS-1$
        throw new TalendException(Messages.getString("SoftwareSystemManager_NULL_DB_TYPE") + databaseConnection.getName());
    }
    String productVersion = TaggedValueHelper.getValueString(TaggedValueHelper.DB_PRODUCT_VERSION, databaseConnection);
    for (EObject system : softwareSystems) {
        if (system instanceof TdSoftwareSystem) {
            if (StringUtils.equalsIgnoreCase(((TdSoftwareSystem) system).getSubtype(), databaseType) && StringUtils.endsWithIgnoreCase(((TdSoftwareSystem) system).getVersion(), productVersion)) {
                // Found the software system given the database type and version.
                return Boolean.TRUE;
            }
        }
    }
    return Boolean.FALSE;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) TdSoftwareSystem(org.talend.cwm.softwaredeployment.TdSoftwareSystem) TalendException(org.talend.utils.exceptions.TalendException)

Example 3 with TdSoftwareSystem

use of org.talend.cwm.softwaredeployment.TdSoftwareSystem in project tdq-studio-se by Talend.

the class SoftwareSystemManager method getNewDBTypesFromSoftwareSystem.

/**
 * Get new database types from software system.
 *
 * @return the new datababse types (e.g. new type created via generic JDBC connection).
 */
public List<String> getNewDBTypesFromSoftwareSystem(Set<String> existingTypes) {
    List<String> newDBTypes = new ArrayList<String>();
    Resource softwareSystemResource = EMFSharedResources.getInstance().getSoftwareDeploymentResource();
    List<EObject> softwareSystems = softwareSystemResource.getContents();
    for (EObject system : softwareSystems) {
        if (system instanceof TdSoftwareSystem) {
            String subtype = ((TdSoftwareSystem) system).getSubtype();
            if (subtype == null) {
                continue;
            }
            Boolean isExist = Boolean.FALSE;
            for (String existType : existingTypes) {
                if (StringUtils.equalsIgnoreCase(existType, subtype)) {
                    isExist = Boolean.TRUE;
                    break;
                }
            }
            if (!isExist) {
                // TDQ-11558 msjian: because we have "Redshift" and "Hive | Impala" types, so ignore these
                if (subtype.equalsIgnoreCase(SupportDBUrlType.REDSHIFT.getLanguage()) || subtype.equalsIgnoreCase(SupportDBUrlType.IMPALA.getLanguage()) || subtype.contains(SupportDBUrlType.HIVEDEFAULTURL.getLanguage())) {
                    continue;
                }
                // TDQ-11558~
                newDBTypes.add(subtype);
            }
        }
    }
    return newDBTypes;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) TdSoftwareSystem(org.talend.cwm.softwaredeployment.TdSoftwareSystem) ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource)

Example 4 with TdSoftwareSystem

use of org.talend.cwm.softwaredeployment.TdSoftwareSystem 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)

Example 5 with TdSoftwareSystem

use of org.talend.cwm.softwaredeployment.TdSoftwareSystem in project tdq-studio-se by Talend.

the class SoftwareSystemManager method update.

/**
 * DOC zhao Comment method "update".
 *
 * @param databaseProductName
 * @param databaseProductVersion
 */
private void update(DatabaseConnection databaseConnection, List<EObject> softwareSystems, Resource softwareSystemResource) {
    String databaseType = TaggedValueHelper.getValueString(TaggedValueHelper.DB_PRODUCT_NAME, databaseConnection);
    if (StringUtils.isEmpty(databaseType)) {
        return;
    }
    String productVersion = TaggedValueHelper.getValueString(TaggedValueHelper.DB_PRODUCT_VERSION, databaseConnection);
    // update software system.
    TdSoftwareSystem softwareSystemNew = SoftwaredeploymentPackage.eINSTANCE.getSoftwaredeploymentFactory().createTdSoftwareSystem();
    softwareSystemNew.setName(databaseType);
    softwareSystemNew.setSubtype(databaseType);
    if (productVersion != null) {
        softwareSystemNew.setVersion(productVersion);
    }
    softwareSystems.add(softwareSystemNew);
    EMFSharedResources.getInstance().saveResource(softwareSystemResource);
}
Also used : TdSoftwareSystem(org.talend.cwm.softwaredeployment.TdSoftwareSystem)

Aggregations

TdSoftwareSystem (org.talend.cwm.softwaredeployment.TdSoftwareSystem)5 EObject (org.eclipse.emf.ecore.EObject)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 EMFSharedResources (org.talend.dq.writer.EMFSharedResources)1 TalendException (org.talend.utils.exceptions.TalendException)1 Component (orgomg.cwm.foundation.softwaredeployment.Component)1 DeployedComponent (orgomg.cwm.foundation.softwaredeployment.DeployedComponent)1 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)1