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