use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class CategoryHandler method loadFromFile.
/**
* DOC bZhou Comment method "loadFromFile".
*
* @return
*/
private static AnalysisCategories loadFromFile() {
EMFUtil util = new EMFUtil();
// $NON-NLS-1$
String pathName = "/org.talend.cwm.management/My.category";
URI uri = URI.createPlatformPluginURI(pathName, false);
Resource catFile = null;
try {
catFile = util.getResourceSet().getResource(uri, true);
} catch (RuntimeException e) {
log.error(e.getMessage());
}
if (catFile == null) {
// try to load from a local file
// $NON-NLS-1$
catFile = util.getResourceSet().getResource(URI.createFileURI(".." + File.separator + pathName), true);
}
if (catFile == null) {
// $NON-NLS-1$
log.error(Messages.getString("CategoryHandler.NORESOUTCEFOUND", pathName, uri));
return null;
}
EList<EObject> contents = catFile.getContents();
if (contents == null) {
// $NON-NLS-1$
log.error(Messages.getString("CategoryHandler.NOCATALOGFOUND", uri));
return null;
}
CategorySwitch<AnalysisCategories> catSwitch = new CategorySwitch<AnalysisCategories>() {
@Override
public AnalysisCategories caseAnalysisCategories(AnalysisCategories object) {
return object;
}
};
return catSwitch.doSwitch(contents.get(0));
}
use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class UnitTestBuildHelper method initProxyRepository.
/**
* DOC talend Comment method "initProxyRepository".
*/
public static 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 = rootProject.getName();
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) {
Assert.fail(e.getMessage());
}
}
use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class RefreshActionDelegate method synchronizeDirect.
@SuppressWarnings("unused")
private void synchronizeDirect() {
EMFUtil util = EMFSharedResources.getSharedEmfUtil();
ResourceSet resourceSet = util.getResourceSet();
URI uri = URI.createPlatformResourceURI(selectedFileObject.getFullPath().toString(), false);
final Resource resource = resourceSet.createResource(uri);
Collection<? extends ModelElement> schemata = ConnectionHelper.getSchema(selectedDataProvider);
if (CAT_WITH_PRV) {
resource.getContents().addAll(schemata);
}
}
use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class RefreshActionDelegate method loadDataProviderAndStructureInMemory.
// private void synchronize() {
// // Load Model from Prv File
// // Creates the resourceSet where we'll load the models
// final ResourceSet resourceSet = new ResourceSetImpl();
// try {
// final EObject alreadySavedModel = ModelUtils.load(selectedFileObject.toString(), resourceSet);
//
// Connection connection = null;
// if (alreadySavedModel instanceof Connection) {
// connection = (Connection) alreadySavedModel;
// }
// Connection newConn = null;
// if (connection != null) {
// String dbUrl = JavaSqlFactory.getURL(connection);
// String driverClassName = JavaSqlFactory.getDriverClass(connection);
// EList<EObject> pcObjects = connection.eContents();
// ListIterator<EObject> liEObject = pcObjects.listIterator();
//
// Properties parameters = new Properties();
//
// while (liEObject.hasNext()) {
// EObject eo = liEObject.next();
// if (eo instanceof TaggedValue) {
// String tag = ((TaggedValue) eo).getTag();
// System.out.print(tag);
// String value = ((TaggedValue) eo).getValue();
// System.out.println(" " + value); //$NON-NLS-1$
// parameters.put(tag, value);
// }
//
// }
//
// System.out.println(dbUrl);
// System.out.println(driverClassName);
// DBConnectionParameter dbcp = new DBConnectionParameter();
//
// dbcp.setName(connection.getName());
// dbcp.setAuthor(MetadataHelper.getAuthor(connection));
// dbcp.setDescription(MetadataHelper.getDescription(connection));
// dbcp.setPurpose(MetadataHelper.getPurpose(connection));
// dbcp.setStatus(MetadataHelper.getDevStatus(connection));
//
// dbcp.setDriverClassName(driverClassName);
// dbcp.setJdbcUrl(dbUrl);
// dbcp.setParameters(parameters);
// IMetadataConnection metadataConnection = MetadataFillFactory.getDBInstance(connection).fillUIParams(
// ParameterUtil.toMap(dbcp));
// newConn = MetadataFillFactory.getDBInstance(connection).fillUIConnParams(metadataConnection, null);
// }
// if (newConn == null) {
// log.error(Messages.getString(
// "RefreshActionDelegate.errorUnableCreateNewCon", connection == null ? "" : connection.getName()));//$NON-NLS-1$ //$NON-NLS-2$
// return;
// }
// // System.out.println(alreadySavedModel.toString());
// IFolder folder = ResourceManager.getConnectionFolder();
// FolderProvider fp = new FolderProvider();
// fp.setFolderResource(folder);
// IFile file2 = loadDataProviderAndStructureInMemory(newConn, fp);
//
// final EObject model2 = ModelUtils.load(file2.toString(), resourceSet);
//
// // MODSCA 2008-03-31 add option for ignoring some elements
// Map<String, Object> options = new HashMap<String, Object>();
// options.put(MatchOptions.OPTION_IGNORE_XMI_ID, true);
// options.put(MatchOptions.OPTION_SEARCH_WINDOW, 500);
//
// // Creates the match then the diff model for those two models
// final MatchModel match = MatchService.doMatch(alreadySavedModel, model2, options);
// final DiffModel diff = DiffService.doDiff(match, false);
//
// EList<UnmatchElement> unMatchedElements = match.getUnmatchedElements();
// for (Object object : unMatchedElements) {
// UnmatchElement unMatched = (UnmatchElement) object;
// ModelElement modelElt = (ModelElement) unMatched.getElement();
// System.out.println("Unmatched elt= " + modelElt.getName()); //$NON-NLS-1$
// }
// @SuppressWarnings("unused")
// EList<DiffElement> ownedElements = diff.getOwnedElements();
//
// // Prints the results
// try {
// System.out.println(ModelUtils.serialize(match));
// System.out.println(ModelUtils.serialize(diff));
// } catch (IOException e) {
// log.error(e, e);
// }
//
// // Serializes the result as "result.emfdiff" in the directory this
// // class has been called from.
// String outputFile = "out/result.emfdiff"; //$NON-NLS-1$
// System.out.println("saving emfdiff as \"" + outputFile + "\""); //$NON-NLS-1$ //$NON-NLS-2$
// final ComparisonResourceSnapshot snapshot = DiffFactory.eINSTANCE.createComparisonResourceSnapshot();
// snapshot.setDate(Calendar.getInstance().getTime());
// snapshot.setMatch(match);
// snapshot.setDiff(diff);
// // MOD scorreia 2010-01-29: we may need to set the file.encoding property here.
// ModelUtils.save(snapshot, outputFile);
//
// } catch (IOException e) {
// System.out.print(e.getMessage());
// // log.error(e, e);
// } catch (InterruptedException e) {
// System.out.print(e.getMessage());
// log.error(e, e);
// }
// }
private IFile loadDataProviderAndStructureInMemory(Connection dataProvider, FolderProvider folderProvider) {
IPath folderPath = ((folderProvider != null) && folderProvider.getFolder() != null) ? folderProvider.getFolderResource().getFullPath() : null;
if (folderPath == null) {
// do not serialize data
// $NON-NLS-1$
System.out.println("Data provider not serialized: no folder given.");
return null;
}
// --- add resources in resource set
EMFUtil util = EMFSharedResources.getSharedEmfUtil();
ResourceSet resourceSet = util.getResourceSet();
// $NON-NLS-1$
String fileName = ".refresh.prv";
IFile file = folderProvider == null ? null : folderProvider.getFolderResource().getFile(fileName);
// File file = new File(dataproviderFilename);
if (file != null && file.exists()) {
try {
file.delete(true, null);
} catch (CoreException e) {
log.error(e, e);
}
}
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), false);
final Resource resource = resourceSet.createResource(uri);
@SuppressWarnings("unused") boolean ok = resource.getContents().add(dataProvider);
// save each catalog is its own file
Collection<? extends ModelElement> catalogs = ConnectionHelper.getCatalogs(dataProvider);
if (CAT_WITH_PRV) {
ok = resource.getContents().addAll(catalogs);
} else {
// ok = addElementsToOwnResources(catalogs,
// folderProvider.getFolderResource(), util);
}
// save each schema is its own file
Collection<? extends ModelElement> schemata = ConnectionHelper.getSchema(dataProvider);
if (CAT_WITH_PRV) {
ok = resource.getContents().addAll(schemata);
} else {
// ok = addElementsToOwnResources(schemata,
// folderProvider.getFolderResource(), util);
// util.save();
}
Iterator<? extends ModelElement> it = schemata.iterator();
while (it.hasNext()) {
Schema tdschema = (Schema) it.next();
Collection<? extends ModelElement> tables = SchemaHelper.getTables(tdschema);
ok = resource.getContents().addAll(tables);
Collection<? extends ModelElement> views = SchemaHelper.getViews(tdschema);
ok = resource.getContents().addAll(views);
}
EMFUtil.saveSingleResource(resource);
return file;
}
use of org.talend.commons.emf.EMFUtil in project tdq-studio-se by Talend.
the class MoveProviderMain method main.
/**
* DOC scorreia Comment method "main".
*
* @param args
*/
public static void main(String[] args) {
// instantiate a new resource set
EMFUtil util = new EMFUtil();
ResourceSet rs = util.getResourceSet();
// load data provider resource and store it into the resource set
File file = new File("out/columnTest_0.1.ana");
System.out.println("Loading file " + file.getAbsolutePath());
Resource r = rs.getResource(URI.createFileURI(file.getAbsolutePath()), true);
// resolve all proxies of the resource to be moved (catalogs and provider connection)
// EcoreUtil.resolveAll(r);
// get all external cross references and for each resolve all proxies (inverse links)
// Map<EObject, Collection<Setting>> find =
// EcoreUtil.ExternalCrossReferencer.find(util.getResourceSet().getResources()
// .iterator().next());
// for (EObject object : find.keySet()) {
// Resource resource = object.eResource();
// EcoreUtil.resolveAll(resource);
// }
// change uri for the loaded data provider resource
URI destinationUri = URI.createFileURI("out/move");
EMFUtil.changeUri(r, destinationUri);
System.out.println("Destination = " + destinationUri);
// delete original file
file.delete();
// save resource set
util.save();
}
Aggregations