Search in sources :

Example 1 with EObject

use of org.eclipse.emf.ecore.EObject in project openhab1-addons by openhab.

the class ConfigurationHandler method fillupConfig.

/**
     * Fills in the configuration into the configuration object and adds it to the {@link OHConfig}.
     *
     * @param ohtfDevice The device specific configuration object {@link OHTFDevice}.
     * @param deviceConfig The device configuration as {@code Map} of {@code Strings}.
     * @throws ConfigurationException
     */
private void fillupConfig(OHTFDevice<?, ?> ohtfDevice, Map<String, String> deviceConfig) throws ConfigurationException {
    String uid = deviceConfig.get(ConfigKey.uid.name());
    if (uid == null || uid.equals("")) {
        // das kommt hier gar nie an
        logger.error("===== uid missing");
        throw new ConfigurationException(deviceConfig.toString(), "config is an invalid missing uid: openhab.cfg has to be fixed!");
    } else {
        logger.debug("*** uid is \"{}\"", uid);
    }
    ohtfDevice.setUid(uid);
    String subid = deviceConfig.get(ConfigKey.subid.name());
    if (subid != null) {
        if (!ohtfDevice.isValidSubId(subid)) {
            throw new ConfigurationException(subid, String.format("\"%s\" is an invalid subId: openhab.cfg has to be fixed!", subid));
        }
        logger.trace("fillupConfig ohtfDevice subid {}", subid);
        ohtfDevice.setSubid(subid);
    }
    if (ohConfig.getConfigByTFId(uid, subid) != null) {
        throw new ConfigurationException(String.format("uid: %s subId: %s", uid, subid), String.format("%s: duplicate device config for uid \"%s\" and subId \"%s\": fix openhab.cfg", LoggerConstants.CONFIG, uid, subid));
    }
    String symbolicName = deviceConfig.get(ConfigKeyAdmin.ohId.name());
    if (ohConfig.getConfigByOHId(symbolicName) != null) {
        throw new ConfigurationException(String.format("symbolic name: %s", symbolicName), String.format("%s: duplicate device config for symbolic name \"%s\": fix openhab.cfg", LoggerConstants.CONFIG, symbolicName));
    }
    ohtfDevice.setOhid(symbolicName);
    EObject tfConfig = ohtfDevice.getTfConfig();
    EList<EStructuralFeature> features = null;
    if (tfConfig != null) {
        features = tfConfig.eClass().getEAllStructuralFeatures();
    }
    ArrayList<String> configKeyList = new ArrayList<String>();
    for (ConfigKeyAdmin configKey : ConfigKeyAdmin.values()) {
        configKeyList.add(configKey.toString());
    }
    for (String property : deviceConfig.keySet()) {
        if (configKeyList.contains(property)) {
            continue;
        } else {
            logger.trace("{} found  property {}", LoggerConstants.CONFIG, property);
        }
        if (features != null) {
            for (EStructuralFeature feature : features) {
                logger.trace("found feature: {}", feature.getName());
                if (feature.getName().equals(property)) {
                    logger.trace("{} feature type {}", LoggerConstants.CONFIG, feature.getEType().getInstanceClassName());
                    logger.debug("configuring feature: {} for uid {} subid {}", feature.getName(), uid, subid);
                    String className = feature.getEType().getInstanceClassName();
                    if (className.equals("int") || className.equals("java.lang.Integer")) {
                        tfConfig.eSet(feature, Integer.parseInt(deviceConfig.get(property)));
                    } else if (className.equals("short") || className.equals("java.lang.Short")) {
                        tfConfig.eSet(feature, Short.parseShort(deviceConfig.get(property)));
                    } else if (className.equals("long") || className.equals("java.lang.Long")) {
                        tfConfig.eSet(feature, Long.parseLong(deviceConfig.get(property)));
                    } else if (className.equals("boolean") || className.equals("java.lang.Boolean")) {
                        logger.debug("{} found boolean value", LoggerConstants.CONFIG);
                        tfConfig.eSet(feature, Boolean.parseBoolean(deviceConfig.get(property)));
                    } else if (className.equals("java.lang.String")) {
                        logger.debug("{} found String value", LoggerConstants.CONFIG);
                        tfConfig.eSet(feature, deviceConfig.get(property));
                    } else if (className.equals("java.math.BigDecimal")) {
                        logger.debug("{} found BigDecimal value", LoggerConstants.CONFIG);
                        tfConfig.eSet(feature, new BigDecimal(deviceConfig.get(property)));
                    // } else if (feature.getEType().getInstanceClassName().equals("EList")){
                    // logger.debug("{} found EList value", LoggerConstants.CONFIG);
                    // List<String> strings = new
                    // ArrayList<String>(Arrays.asList(deviceConfig.get(property).trim().split("\\s+")));
                    // tfConfig.eSet(feature, strings);
                    } else {
                        throw new ConfigurationException(feature.getName(), "unsupported configuration type needed: " + className);
                    }
                    break;
                }
            }
        }
    }
    ohConfig.getOhTfDevices().add(ohtfDevice);
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) EObject(org.eclipse.emf.ecore.EObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal)

Example 2 with EObject

use of org.eclipse.emf.ecore.EObject in project tdi-studio-se by Talend.

the class JSONRepositoryContentHandler method save.

private Resource save(JSONFileConnectionItem item) {
    Resource itemResource = xmiResourceManager.getItemResource(item);
    itemResource.getContents().clear();
    MetadataManager.addContents(item, itemResource);
    // add to the current resource all Document and Description instances because they are not reference in
    // containment references.
    Map<EObject, Collection<Setting>> externalCrossref = EcoreUtil.ExternalCrossReferencer.find(item.getConnection());
    Collection<Object> documents = EcoreUtil.getObjectsByType(externalCrossref.keySet(), BusinessinformationPackage.Literals.DOCUMENT);
    for (Object doc : documents) {
        itemResource.getContents().add((EObject) doc);
    }
    Collection<Object> descriptions = EcoreUtil.getObjectsByType(externalCrossref.keySet(), BusinessinformationPackage.Literals.DESCRIPTION);
    for (Object doc : descriptions) {
        itemResource.getContents().add((EObject) doc);
    }
    return itemResource;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 3 with EObject

use of org.eclipse.emf.ecore.EObject in project tdi-studio-se by Talend.

the class ImportItemUtil method resetItemReference.

/**
     * 
     * cLi Comment method "resetItemReference".
     * 
     * resolve the encode some special character(bug 6252), maybe, It's not better to resolve this by manually.
     * 
     * such as, "[" is "%5B", "]" is "%5D", etc.
     */
@SuppressWarnings("unchecked")
private void resetItemReference(ItemRecord itemRecord, Resource resource) {
    Item item = itemRecord.getItem();
    EList<EObject> contents = resource.getContents();
    /*
         * ignore job. no need, because it can't be allowed input special char for name.
         */
    if (item instanceof ProcessItem) {
    // ((ProcessItem) item).setProcess((ProcessType) EcoreUtil.getObjectByType(contents,
    // TalendFilePackage.eINSTANCE
    // .getProcessType()));
    } else /*
         * ignore joblet. no need, because it can't be allowed input special char for name.
         */
    if (item instanceof JobletProcessItem) {
    // JobletProcessItem jobletProcessItem = (JobletProcessItem) item;
    //
    // jobletProcessItem.setJobletProcess((JobletProcess) EcoreUtil.getObjectByType(contents,
    // JobletPackage.eINSTANCE
    // .getJobletProcess()));
    // jobletProcessItem
    // .setIcon((ByteArray) EcoreUtil.getObjectByType(contents, PropertiesPackage.eINSTANCE.getByteArray()));
    } else // connectionItem
    if (item instanceof ConnectionItem) {
        ((ConnectionItem) item).setConnection((Connection) EcoreUtil.getObjectByType(contents, ConnectionPackage.eINSTANCE.getConnection()));
    } else // context
    if (item instanceof ContextItem) {
        EList contexts = ((ContextItem) item).getContext();
        contexts.clear();
        contexts.addAll(EcoreUtil.getObjectsByType(contents, TalendFilePackage.eINSTANCE.getContextType()));
    } else // file
    if (item instanceof FileItem) {
        /*
             * ignore routine, no need, because it can't be allowed input special char for name.
             */
        if (item instanceof RoutineItem) {
            return;
        }
        FileItem fileItem = (FileItem) item;
        fileItem.setContent((ByteArray) EcoreUtil.getObjectByType(contents, PropertiesPackage.eINSTANCE.getByteArray()));
    } else // snippet
    if (item instanceof SnippetItem) {
        EList variables = ((SnippetItem) item).getVariables();
        variables.clear();
        variables.addAll(EcoreUtil.getObjectsByType(contents, PropertiesPackage.eINSTANCE.getSnippetVariable()));
    } else // link doc
    if (item instanceof LinkDocumentationItem) {
        ((LinkDocumentationItem) item).setLink((LinkType) EcoreUtil.getObjectByType(contents, PropertiesPackage.eINSTANCE.getLinkType()));
    } else // business
    if (item instanceof BusinessProcessItem) {
        BusinessProcessItem businessProcessItem = (BusinessProcessItem) item;
        businessProcessItem.setSemantic((BusinessProcess) EcoreUtil.getObjectByType(contents, BusinessPackage.eINSTANCE.getBusinessProcess()));
        businessProcessItem.setNotationHolder((NotationHolder) EcoreUtil.getObjectByType(contents, PropertiesPackage.eINSTANCE.getNotationHolder()));
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) RoutineItem(org.talend.core.model.properties.RoutineItem) NotationHolder(org.talend.core.model.properties.NotationHolder) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) SnippetItem(org.talend.core.model.properties.SnippetItem) Item(org.talend.core.model.properties.Item) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) FolderItem(org.talend.core.model.properties.FolderItem) RoutineItem(org.talend.core.model.properties.RoutineItem) TDQItem(org.talend.core.model.properties.TDQItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) FileItem(org.talend.core.model.properties.FileItem) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) FileItem(org.talend.core.model.properties.FileItem) SnippetItem(org.talend.core.model.properties.SnippetItem) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EObject(org.eclipse.emf.ecore.EObject) BusinessProcess(org.talend.designer.business.model.business.BusinessProcess)

Example 4 with EObject

use of org.eclipse.emf.ecore.EObject in project tdi-studio-se by Talend.

the class MergeTosMetadataMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    if (item instanceof ConnectionItem) {
        try {
            URI itemURI = getItemURI(item);
            if (itemURI != null) {
                URI itemResourceURI = getItemResourceURI(itemURI);
                if (metadata400to410 == null) {
                    metadata400to410 = new TosMetadataMigrationFrom400to410();
                }
                Resource migratedResource = metadata400to410.migrate(itemResourceURI.toString(), new NullProgressMonitor());
                HashMap<String, Object> xmlSaveOtions = XML_SAVE_OTIONS_1_0;
                if (migratedResource != null) {
                    // check for DB connection caus we need to setup Schema and Catalog properly
                    EObject content = migratedResource.getContents().get(0);
                    if (content != null && "DatabaseConnection".equals(content.eClass().getName())) {
                        // resource is dynamic EMF so convert it to static model by serialising it and reloading it
                        ByteArrayOutputStream tempStream = new ByteArrayOutputStream();
                        try {
                            // serialize into memory
                            try {
                                migratedResource.save(tempStream, XML_SAVE_OTIONS_1_0);
                            } catch (Exception e) {
                                // try with version 1.1
                                tempStream = new ByteArrayOutputStream();
                                xmlSaveOtions = XML_SAVE_OTIONS_1_1;
                                migratedResource.save(tempStream, xmlSaveOtions);
                            } finally {
                                tempStream.close();
                            }
                            // create a resource to laod the inmemory resource that should be a static EMF model
                            migratedResource = resourceSet.createResource(URI.createURI(//$NON-NLS-1$
                            "http://talend/dummy_static.metadata"));
                            migratedResource.load(new ByteArrayInputStream(tempStream.toByteArray()), xmlSaveOtions);
                            // check that DBConnection is firdt element
                            DatabaseConnection databaseConnection = SwitchHelpers.DATABASECONNECTION_SWITCH.doSwitch(migratedResource.getContents().get(0));
                            // do not check for null caus DB connection is already check above
                            String databaseType = databaseConnection.getDatabaseType();
                            databaseConnection.setDriverClass(ExtractMetaDataUtils.getInstance().getDriverClassByDbType(databaseType));
                            EDatabaseTypeName currentType = EDatabaseTypeName.getTypeFromDbType(databaseType);
                            EDatabaseSchemaOrCatalogMapping curCatalog = currentType.getCatalogMappingField();
                            EDatabaseSchemaOrCatalogMapping curSchema = currentType.getSchemaMappingField();
                            // all the DB connection are migrated with a Schema by default
                            if (!curCatalog.equals(EDatabaseSchemaOrCatalogMapping.None)) {
                                List<Schema> schemas = ConnectionHelper.getSchema(databaseConnection);
                                if (!curSchema.equals(EDatabaseSchemaOrCatalogMapping.None)) {
                                    // we need to place the current schemas into a catalogs
                                    ConnectionHelper.removeSchemas(schemas, databaseConnection);
                                    for (Schema schema : schemas) {
                                        // compute the name of the schema and the catalogs
                                        String schemaName = computeSchemaName(schema, databaseConnection, curSchema);
                                        String catalogName = computeCatalogName(databaseConnection, curCatalog);
                                        schema.setName(schemaName);
                                        Catalog catalog = RelationalFactory.eINSTANCE.createCatalog();
                                        // catalogs are not in a contained reference
                                        migratedResource.getContents().add(catalog);
                                        catalog.setName(catalogName);
                                        // add the schema to the catalog and the the catalog to the connection
                                        CatalogHelper.addSchemas(Collections.singleton(schema), catalog);
                                        ConnectionHelper.addCatalog(catalog, databaseConnection);
                                    }
                                } else {
                                    // we need to replace the Schemas with a Catalogs
                                    for (Schema schema : schemas) {
                                        // compute the name the catalog
                                        String catalogName = computeCatalogName(databaseConnection, curCatalog);
                                        // use owned elements to get everything regardless of tables or views or
                                        // else
                                        Catalog catalog = RelationalFactory.eINSTANCE.createCatalog();
                                        // catalogs are not in a contained reference
                                        migratedResource.getContents().add(catalog);
                                        catalog.setName(catalogName);
                                        catalog.getOwnedElement().addAll(schema.getOwnedElement());
                                        ConnectionHelper.addCatalog(catalog, databaseConnection);
                                        ConnectionHelper.removeSchemas(Collections.singleton(schema), databaseConnection);
                                    }
                                }
                            } else if (!curSchema.equals(EDatabaseSchemaOrCatalogMapping.None)) {
                                List<Schema> schemas = ConnectionHelper.getSchema(databaseConnection);
                                for (Schema schema : schemas) {
                                    String schemaName = computeSchemaName(schema, databaseConnection, curSchema);
                                    schema.setName(schemaName);
                                }
                            }
                        // else no catalog so we keep the schema as is
                        } catch (Exception e) {
                            // we have an exception finalising the migration but we trap it caus we still try to
                            // save it
                            log.error("Cannot complete merge metadata migration on file:" + itemResourceURI.toString(), e);
                            ExceptionHandler.process(e);
                        } finally {
                            tempStream.close();
                        }
                    }
                    // else not a DB connection so persist
                    OutputStream outputStream = item.eResource().getResourceSet().getURIConverter().createOutputStream(itemResourceURI, null);
                    try {
                        migratedResource.save(outputStream, xmlSaveOtions);
                    } finally {
                        outputStream.close();
                    }
                }
                return ExecutionResult.SUCCESS_WITH_ALERT;
            }
        } catch (ATLCoreException e) {
            log.error(e);
            ExceptionHandler.process(e);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (IOException e) {
            log.error(e);
            ExceptionHandler.process(e);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } finally {
            resourceSet.getResources().clear();
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ConnectionItem(org.talend.core.model.properties.ConnectionItem) EDatabaseSchemaOrCatalogMapping(org.talend.core.model.metadata.builder.database.EDatabaseSchemaOrCatalogMapping) Schema(orgomg.cwm.resource.relational.Schema) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) ATLCoreException(org.eclipse.m2m.atl.core.ATLCoreException) IOException(java.io.IOException) Catalog(orgomg.cwm.resource.relational.Catalog) ATLCoreException(org.eclipse.m2m.atl.core.ATLCoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) TosMetadataMigrationFrom400to410(org.talend.model.migration.TosMetadataMigrationFrom400to410) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) List(java.util.List) EDatabaseTypeName(org.talend.core.database.EDatabaseTypeName)

Example 5 with EObject

use of org.eclipse.emf.ecore.EObject in project tdi-studio-se by Talend.

the class ListBusinessItemNameEditPart method addSemanticListeners.

/**
     * @generated
     */
protected void addSemanticListeners() {
    if (getParser() instanceof ISemanticParser) {
        EObject element = resolveSemanticElement();
        parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
        for (int i = 0; i < parserElements.size(); i++) {
            //$NON-NLS-1$
            addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i));
        }
    } else {
        super.addSemanticListeners();
    }
}
Also used : ISemanticParser(org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser) EObject(org.eclipse.emf.ecore.EObject) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)7019 AntlrDatatypeRuleToken (org.eclipse.xtext.parser.antlr.AntlrDatatypeRuleToken)1947 Resource (org.eclipse.emf.ecore.resource.Resource)304 Test (org.junit.Test)295 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)262 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)262 ArrayList (java.util.ArrayList)203 GridData (org.eclipse.swt.layout.GridData)195 URI (org.eclipse.emf.common.util.URI)190 InternalEObject (org.eclipse.emf.ecore.InternalEObject)180 SelectionEvent (org.eclipse.swt.events.SelectionEvent)179 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)177 ReferencesTable (org.eclipse.emf.eef.runtime.ui.widgets.ReferencesTable)162 ReferencesTableListener (org.eclipse.emf.eef.runtime.ui.widgets.ReferencesTable.ReferencesTableListener)162 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)138 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)127 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)126 List (java.util.List)121 XtextResource (org.eclipse.xtext.resource.XtextResource)121 INode (org.eclipse.xtext.nodemodel.INode)90