Search in sources :

Example 11 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project BIMserver by opensourceBIM.

the class StructureAnalyzer method start.

private void start() {
    limit = 1000000;
    try {
        out = new PrintWriter(Paths.get("structure.txt").toFile());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    int i = 0;
    // Ifc2x3tc1Package einstance = Ifc2x3tc1Package.eINSTANCE;
    // System.out.println(printClassifier("root", Ifc2x3tc1Package.eINSTANCE.getEClassifier("IfcWall"), new ArrayList<EClassifier>(), 0));
    // EList<EClassifier> classifiers = Ifc2x3tc1Package.eINSTANCE.getEClassifiers();
    EList<EClassifier> classifiers = new BasicEList<EClassifier>();
    classifiers.add(Ifc2x3tc1Package.eINSTANCE.getEClassifier("IfcWall"));
    for (EClassifier ecl : classifiers) {
        try {
            out2 = new PrintWriter(Paths.get("structure/" + ecl.getName() + ".txt").toFile());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        count = 0;
        int printClassifier = printClassifier("root", ecl, new ArrayList<EClassifier>(), 0);
        if (printClassifier == -1) {
            out2.println("TERMINATED AFTER " + limit + " REFERENCES");
        }
        String string = i + "\t" + printClassifier + "\t" + ecl.getName();
        System.out.println(string);
        out.println(string);
        out.flush();
        out2.close();
        i++;
    }
    out.close();
}
Also used : BasicEList(org.eclipse.emf.common.util.BasicEList) FileNotFoundException(java.io.FileNotFoundException) EClassifier(org.eclipse.emf.ecore.EClassifier) PrintWriter(java.io.PrintWriter)

Example 12 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project BIMserver by opensourceBIM.

the class DatabaseSession method readList.

@SuppressWarnings("unchecked")
private Object readList(IdEObject idEObject, EClass originalQueryClass, ByteBuffer buffer, IfcModelInterface model, QueryInterface query, TodoList todoList, EStructuralFeature feature) throws BimserverDatabaseException {
    if (feature.getEType() instanceof EEnum) {
    } else if (feature.getEType() instanceof EClass) {
        if (buffer.capacity() == 1 && buffer.get(0) == -1) {
            buffer.position(buffer.position() + 1);
        } else {
            /*
				 * TODO There still is a problem with this,
				 * when readReference (and all calls beyond
				 * that call) alter (by opposites) this
				 * list, this list can potentially grow too
				 * large
				 * 
				 * Only can happen with non-unique
				 * references
				 */
            int listSize = buffer.getInt();
            BasicEList<Object> list = (BasicEList<Object>) idEObject.eGet(feature);
            list.grow(listSize);
            for (int i = 0; i < listSize; i++) {
                if (feature.getEAnnotation("twodimensionalarray") != null) {
                    IdEObjectImpl newObject = createInternal((EClass) feature.getEType(), query);
                    Object result = readList(newObject, originalQueryClass, buffer, model, query, todoList, newObject.eClass().getEStructuralFeature("List"));
                    if (result != null) {
                        newObject.eSet(newObject.eClass().getEStructuralFeature("List"), result);
                    }
                    list.addUnique(newObject);
                } else {
                    IdEObject referencedObject = null;
                    buffer.order(ByteOrder.LITTLE_ENDIAN);
                    short cid = buffer.getShort();
                    buffer.order(ByteOrder.BIG_ENDIAN);
                    if (cid == -1) {
                    // null, do nothing
                    } else if (cid < 0) {
                        // negative cid means value is
                        // embedded
                        // in record
                        EClass referenceClass = database.getEClassForCid((short) (-cid));
                        if (referenceClass == null) {
                            throw new BimserverDatabaseException("No class found for cid " + (-cid));
                        }
                        if (feature.isMany()) {
                            referencedObject = readEmbeddedValue(feature, buffer, referenceClass, query);
                        } else {
                            referencedObject = readWrappedValue(feature, buffer, referenceClass, query);
                        }
                    } else if (cid > 0) {
                        // positive cid means value is a
                        // reference
                        // to another record
                        EClass referenceClass = database.getEClassForCid(cid);
                        if (referenceClass == null) {
                            throw new BimserverDatabaseException("Cannot find class with cid " + cid);
                        }
                        buffer.position(buffer.position() - 2);
                        referencedObject = readReference(originalQueryClass, buffer, model, idEObject, feature, referenceClass, query, todoList);
                    }
                    if (referencedObject != null) {
                        if (!feature.getEType().isInstance(referencedObject)) {
                            throw new BimserverDatabaseException(referencedObject.getClass().getSimpleName() + " cannot be stored in list of type " + feature.getEType().getName() + " for feature " + feature.getName());
                        }
                        if (feature.isUnique()) {
                            list.add(referencedObject);
                        } else {
                            list.addUnique(referencedObject);
                        }
                    }
                }
            }
        }
    } else if (feature.getEType() instanceof EDataType) {
        int listSize = buffer.getInt();
        BasicEList<Object> list = new BasicEList<Object>(listSize);
        for (int i = 0; i < listSize; i++) {
            Object reference = readPrimitiveValue(feature.getEType(), buffer, query);
            if (reference != null) {
                list.addUnique(reference);
            }
        }
        return list;
    }
    return null;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) IdEObject(org.bimserver.emf.IdEObject) EDataType(org.eclipse.emf.ecore.EDataType) BasicEList(org.eclipse.emf.common.util.BasicEList) VirtualObject(org.bimserver.shared.VirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) EEnum(org.eclipse.emf.ecore.EEnum)

Example 13 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project tdq-studio-se by Talend.

the class MetadataTableWithFilter method getColumns.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.metadata.builder.connection.impl.MetadataTableImpl#getColumns()
     */
@Override
public EList<MetadataColumn> getColumns() {
    EList<MetadataColumn> columns = metadataTable.getColumns();
    EList<MetadataColumn> columnList = new BasicEList<MetadataColumn>(filterNames.size());
    for (MetadataColumn column : columns) {
        if (filterNames.contains(column.getName())) {
            columnList.add(column);
        }
    }
    return columnList;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) BasicEList(org.eclipse.emf.common.util.BasicEList)

Example 14 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project tdq-studio-se by Talend.

the class CompositeIndicatorImpl method getLeafIndicators.

/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 *
 * @generated NOT getLeafIndicators()
 */
public EList<Indicator> getLeafIndicators() {
    EList<Indicator> leafIndicators = new BasicEList<Indicator>();
    EList<Indicator> childIndicators = getChildIndicators();
    for (Indicator indicator : childIndicators) {
        if (indicator instanceof CompositeIndicator) {
            leafIndicators.addAll(((CompositeIndicator) indicator).getLeafIndicators());
        } else {
            leafIndicators.add(indicator);
        }
    }
    return leafIndicators;
}
Also used : BasicEList(org.eclipse.emf.common.util.BasicEList) CompositeIndicator(org.talend.dataquality.indicators.CompositeIndicator) Indicator(org.talend.dataquality.indicators.Indicator) CompositeIndicator(org.talend.dataquality.indicators.CompositeIndicator)

Example 15 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project tdq-studio-se by Talend.

the class SoftwareSystemManagerTest method testUpdateSoftwareSystem.

/**
 * Test method for
 * {@link org.talend.cwm.management.api.SoftwareSystemManager#updateSoftwareSystem(java.sql.Connection, orgomg.cwm.foundation.softwaredeployment.SoftwareSystem)}
 * .
 */
@Test
public void testUpdateSoftwareSystem() {
    SoftwareSystemManager softwareSystemManger = SoftwareSystemManager.getInstance();
    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>();
    when(softwareSysResource.getContents()).thenReturn(existedSystems);
    when(emfSharedResourceMock.saveResource(softwareSysResource)).thenReturn(Boolean.TRUE);
    try {
        softwareSystemManger.updateSoftwareSystem(null);
        Connection mockConnection = mock(Connection.class);
        DatabaseMetaData mockDBMetaData = mock(DatabaseMetaData.class);
        // Mocking Static Class
        PowerMockito.mockStatic(DriverManager.class);
        // $NON-NLS-1$
        String sql = "jdbc:mysql://localhost:3306/tbi";
        when(DriverManager.getConnection(sql)).thenReturn(mockConnection);
        when(mockConnection.getMetaData()).thenReturn(mockDBMetaData);
        // Mock database product name.
        // $NON-NLS-1$
        String mysqlDB = "MYSQL";
        when(mockDBMetaData.getDatabaseProductName()).thenReturn(mysqlDB);
        // Mock database product version
        // $NON-NLS-1$
        String version = "5.5";
        when(mockDBMetaData.getDatabaseProductVersion()).thenReturn(version);
        when(mockDBMetaData.getDatabaseMinorVersion()).thenReturn(5);
        when(mockDBMetaData.getDatabaseMajorVersion()).thenReturn(5);
        DatabaseConnection dbConn = ConnectionPackage.eINSTANCE.getConnectionFactory().createDatabaseConnection();
        TaggedValueHelper.setTaggedValue(dbConn, TaggedValueHelper.DB_PRODUCT_NAME, mysqlDB);
        TaggedValueHelper.setTaggedValue(dbConn, TaggedValueHelper.DB_PRODUCT_VERSION, version);
        PowerMockito.mockStatic(ConvertionHelper.class);
        // $NON-NLS-1$
        when(ConvertionHelper.convert(dbConn, false, "")).thenReturn(null);
        PowerMockito.mockStatic(MetadataFillFactory.class);
        MetadataFillFactory metadataFillFactory = mock(MetadataFillFactory.class);
        when(MetadataFillFactory.getDBInstance()).thenReturn(metadataFillFactory);
        TypedReturnCode<java.sql.Connection> returnCode = new TypedReturnCode<Connection>(Boolean.TRUE);
        returnCode.setObject(mockConnection);
        when(metadataFillFactory.createConnection(null)).thenReturn(returnCode);
        softwareSystemManger.updateSoftwareSystem(dbConn);
        Assert.assertTrue(existedSystems.size() > 0);
        SoftwareSystem newSoftwareSys = (SoftwareSystem) existedSystems.get(0);
        Assert.assertEquals(mysqlDB, newSoftwareSys.getSubtype());
        Assert.assertEquals(version, newSoftwareSys.getVersion());
    } catch (SQLException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : SQLException(java.sql.SQLException) BasicEList(org.eclipse.emf.common.util.BasicEList) Resource(org.eclipse.emf.ecore.resource.Resource) Connection(java.sql.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseMetaData(java.sql.DatabaseMetaData) EMFSharedResources(org.talend.dq.writer.EMFSharedResources) EObject(org.eclipse.emf.ecore.EObject) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) TdSoftwareSystem(org.talend.cwm.softwaredeployment.TdSoftwareSystem) SoftwareSystem(orgomg.cwm.foundation.softwaredeployment.SoftwareSystem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) MetadataFillFactory(org.talend.metadata.managment.model.MetadataFillFactory) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

BasicEList (org.eclipse.emf.common.util.BasicEList)82 Test (org.junit.Test)25 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)16 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)16 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)16 EEFFeatureEditorDialog (org.eclipse.emf.eef.runtime.ui.widgets.EEFFeatureEditorDialog)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)16 GridData (org.eclipse.swt.layout.GridData)16 EObject (org.eclipse.emf.ecore.EObject)13 TdExpression (org.talend.cwm.relational.TdExpression)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 Button (org.eclipse.swt.widgets.Button)8 EList (org.eclipse.emf.common.util.EList)7 ObjectPropertyType (org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType)7 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)7 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)7 ProductVersion (org.talend.utils.ProductVersion)7 Property (org.eclipse.vorto.core.api.model.datatype.Property)6 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)6