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