use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class UpdatePropertiesFileTask method doExecute.
/*
* (non-Javadoc)
*
* @see org.talend.dataprofiler.core.migration.AMigrationTask#doExecute()
*/
@Override
protected boolean doExecute() throws Exception {
boolean ok = true;
EMFUtil emfUtil = new EMFUtil();
for (File file : fileList) {
if (file.isFile()) {
URI uri = URI.createFileURI(file.getAbsolutePath());
if (log.isDebugEnabled()) {
// $NON-NLS-1$
log.debug("---------Translate " + uri.toString());
}
EObject eObject = null;
try {
Resource resource = emfUtil.getResourceSet().getResource(uri, true);
ResourceFileMap resourceFileMap = ModelElementFileFactory.getResourceFileMap(uri.fileExtension());
if (resourceFileMap != null) {
eObject = resourceFileMap.getModelElement(resource);
}
} catch (Exception e) {
// $NON-NLS-1$
log.warn(DefaultMessagesImpl.getString("UpdatePropertiesFileTask_2", file.getAbsolutePath()), e);
ok = false;
}
if (eObject != null) {
if (eObject instanceof ModelElement) {
try {
saveObject(emfUtil, file, uri, eObject);
} catch (Exception e) {
// $NON-NLS-1$
log.error(DefaultMessagesImpl.getString("UpdatePropertiesFileTask_3", eObject, file, uri), e);
ok = false;
}
} else {
// $NON-NLS-1$
log.warn(DefaultMessagesImpl.getString("UpdatePropertiesFileTask_4", eObject.toString()));
ok = false;
}
}
}
}
emfUtil = null;
return ok;
}
use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class LoadSerialDataMain method main.
/**
* DOC scorreia Comment method "main".
*
* @param args
*/
public static void main(String[] args) {
EMFUtil util = new EMFUtil();
File file = new File("out/columnTest_0.1.ana");
System.out.println("Loading file " + file.getAbsolutePath());
ResourceSet rs = util.getResourceSet();
Resource r = rs.getResource(URI.createFileURI(file.getAbsolutePath()), true);
EList<EObject> contents = r.getContents();
if (contents.isEmpty()) {
System.err.println("No content in " + r);
}
System.out.println("Nb elements in contents " + contents.size());
IndicatorsSwitch<FrequencyIndicator> mySwitch = new IndicatorsSwitch<FrequencyIndicator>() {
@Override
public FrequencyIndicator caseFrequencyIndicator(FrequencyIndicator object) {
return object;
}
};
for (EObject object : contents) {
FrequencyIndicator freqI = mySwitch.doSwitch(object);
if (freqI != null) {
Long uniqueValueCount = freqI.getUniqueValueCount();
System.out.println("nb unique values = " + uniqueValueCount);
EList<Object> uniqueValues = freqI.getUniqueValues();
for (Object data : uniqueValues) {
System.out.println("unique value= " + data + " " + freqI.getCount(data));
}
}
}
}
use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class ResourceViewLabelProviderTest method initProxyRepository.
/**
* DOC talend Comment method "initProxyRepository".
*/
private void initProxyRepository(IProject rootProject) {
Project project = null;
ProxyRepositoryFactory proxyRepository = ProxyRepositoryFactory.getInstance();
IRepositoryFactory repository = RepositoryFactoryProvider.getRepositoriyById(RepositoryConstants.REPOSITORY_LOCAL_ID);
if (repository == null) {
log.fatal(DefaultMessagesImpl.getString(// $NON-NLS-1$
"No local Repository found! Probably due to a missing plugin in the product."));
}
proxyRepository.setRepositoryFactoryFromProvider(repository);
try {
proxyRepository.checkAvailability();
proxyRepository.initialize();
XmiResourceManager xmiResourceManager = new XmiResourceManager();
if (rootProject.getFile(FileConstants.LOCAL_PROJECT_FILENAME).exists()) {
// Initialize TDQ EMF model packages.
new EMFUtil();
project = new Project(xmiResourceManager.loadProject(rootProject));
} else {
User user = org.talend.core.model.properties.impl.PropertiesFactoryImpl.eINSTANCE.createUser();
// $NON-NLS-1$
user.setLogin("talend@talend.com");
// $NON-NLS-1$
user.setPassword("talend@talend.com".getBytes());
String projectName = ResourceManager.getRootProjectName();
String projectDesc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName).getComment();
Project projectInfor = ProjectHelper.createProject(projectName, projectDesc, ECodeLanguage.JAVA.getName(), user);
// MOD zshen create project by proxyRepository
checkFileName(projectInfor.getLabel(), RepositoryConstants.PROJECT_PATTERN);
project = proxyRepository.getRepositoryFactoryFromProvider().createProject(projectInfor);
}
if (project != null) {
initRepositoryContext(project);
// add status
// $NON-NLS-1$
String defaultTechnicalStatusList = "DEV development;TEST testing;PROD production";
List<Status> statusList = StatusHelper.parse(defaultTechnicalStatusList);
proxyRepository.setTechnicalStatus(statusList);
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
log.error(e, e);
Assert.fail(e.getMessage());
}
}
use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class TDQJrxmlItemImplTest method setUp.
/**
* DOC yyin Comment method "setUp".
*
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
jrxmlItem = PropertiesFactory.eINSTANCE.createTDQJrxmlItem();
EMFUtil emfUtil = new EMFUtil();
// File position = new File(""); //$NON-NLS-1$
// $NON-NLS-1$
file = new File("test_0.1.jrxml");
// $NON-NLS-1$
writeToFile("original jrxml content");
ResourceSet rs = emfUtil.getResourceSet();
// init the bytearray resource
ByteArray byteArray = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createByteArray();
byteArray.setInnerContentFromFile(file);
byteArrayResource = new ByteArrayResource(URI.createFileURI(file.getAbsolutePath()));
byteArrayResource.getContents().add(byteArray);
rs.getResources().add(byteArrayResource);
org.talend.core.model.properties.Property fileProperty = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
fileProperty.setId(EcoreUtil.generateUUID());
fileProperty.setItem(jrxmlItem);
// $NON-NLS-1$
fileProperty.setLabel("test1");
// $NON-NLS-1$
jrxmlItem.setName("test1");
jrxmlItem.setProperty(fileProperty);
ItemState itemState = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createItemState();
// $NON-NLS-1$
itemState.setPath("data");
jrxmlItem.setState(itemState);
// get the eresource of the item without creating the real project
// $NON-NLS-1$
File property = new File("test_0.1.property");
Resource propertyResource = emfUtil.getResourceSet().createResource(URI.createFileURI(property.getAbsolutePath()));
propertyResource.getContents().add(jrxmlItem.getProperty());
propertyResource.getContents().add(jrxmlItem.getState());
propertyResource.getContents().add(jrxmlItem);
rs.getResources().add(propertyResource);
byteArrayResource.load(null);
jrxmlItem.setContent(byteArray);
emfUtil.save();
}
use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class ReadItemConnectionFile method test.
@Test
public void test() {
EMFUtil emfUtil = new EMFUtil();
File file = new File("data/my_0.1.item");
System.out.println("Loading file " + file.getAbsolutePath());
ResourceSet rs = emfUtil.getResourceSet();
Resource r = rs.getResource(URI.createFileURI(file.getAbsolutePath()), true);
// TreeIterator<EObject> allContents = r.getAllContents();
// while (allContents.hasNext()) {
// EObject metadata = allContents.next();
// System.out.println(metadata);
// }
// should contain the connection, then catalog/schema, then tables, then columns
EList<EObject> contents = r.getContents();
// switch class that returns a connection when it finds one.
ConnectionSwitch<Connection> connectionFinder = new ConnectionSwitch<Connection>() {
/*
* (non-Javadoc)
*
* @see
* org.talend.core.model.metadata.builder.connection.util.ConnectionSwitch#caseConnection(org.talend.core
* .model.metadata.builder.connection.Connection)
*/
@Override
public Connection caseConnection(Connection object) {
return object;
}
};
// loop on all the content of the resource
for (EObject eObject : contents) {
Connection connection = connectionFinder.doSwitch(eObject);
if (connection != null) {
Set<Catalog> allCatalogs = ConnectionHelper.getAllCatalogs(connection);
for (Catalog catalog : allCatalogs) {
System.out.println("## Catalog: " + catalog.getName());
System.out.println("\t## Tables");
List<TdTable> tables = CatalogHelper.getTables(catalog);
for (TdTable tdTable : tables) {
System.out.println("\t\t" + tdTable.getName());
List<TdColumn> columns = TableHelper.getColumns(tdTable);
if (!columns.isEmpty()) {
System.out.println("\t\t\t## Columns");
}
for (TdColumn tdColumn : columns) {
System.out.println("\t\t\t\t" + tdColumn.getName());
}
}
System.out.println("\t## Views");
List<TdView> views = CatalogHelper.getViews(catalog);
for (TdView tdView : views) {
System.out.println("\t\t" + tdView.getName());
List<TdColumn> columns = ViewHelper.getColumns(tdView);
if (!columns.isEmpty()) {
System.out.println("\t\t\t## Columns");
}
for (TdColumn tdColumn : columns) {
System.out.println("\t\t\t\t" + tdColumn.getName());
}
}
}
}
}
}
Aggregations