use of org.talend.core.repository.utils.XmiResourceManager in project tdi-studio-se by Talend.
the class AddContextCommentValueMigrationTaskTest method createTempProject.
private static void createTempProject() throws CoreException, PersistenceException, LoginException {
Project projectInfor = new Project();
projectInfor.setLabel("testauto");
projectInfor.setDescription("no desc");
projectInfor.setLanguage(ECodeLanguage.JAVA);
User user = PropertiesFactory.eINSTANCE.createUser();
user.setLogin("testauto@talend.com");
projectInfor.setAuthor(user);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
String technicalLabel = Project.createTechnicalName(projectInfor.getLabel());
IProject prj = root.getProject(technicalLabel);
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
IProjectDescription desc = null;
if (prj.exists()) {
// always delete to avoid conflicts between 2 tests
prj.delete(true, null);
}
desc = workspace.newProjectDescription(technicalLabel);
desc.setNatureIds(new String[] { TalendNature.ID });
desc.setComment(projectInfor.getDescription());
prj.create(desc, null);
prj.open(IResource.DEPTH_INFINITE, null);
prj.setDefaultCharset("UTF-8", null);
} catch (CoreException e) {
throw new PersistenceException(e);
}
sampleProject = new Project();
// Fill project object
sampleProject.setLabel(projectInfor.getLabel());
sampleProject.setDescription(projectInfor.getDescription());
sampleProject.setLanguage(projectInfor.getLanguage());
sampleProject.setAuthor(projectInfor.getAuthor());
sampleProject.setLocal(true);
sampleProject.setTechnicalLabel(technicalLabel);
XmiResourceManager xmiResourceManager = new XmiResourceManager();
Resource projectResource = xmiResourceManager.createProjectResource(prj);
projectResource.getContents().add(sampleProject.getEmfProject());
projectResource.getContents().add(sampleProject.getAuthor());
xmiResourceManager.saveResource(projectResource);
}
use of org.talend.core.repository.utils.XmiResourceManager in project tdi-studio-se by Talend.
the class FixUnevenItemContextParametersMigrationTaskTest method createTempProject.
private static void createTempProject() throws CoreException, PersistenceException, LoginException {
Project projectInfor = new Project();
projectInfor.setLabel("testauto");
projectInfor.setDescription("no desc");
projectInfor.setLanguage(ECodeLanguage.JAVA);
User user = PropertiesFactory.eINSTANCE.createUser();
user.setLogin("testauto@talend.com");
projectInfor.setAuthor(user);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
String technicalLabel = Project.createTechnicalName(projectInfor.getLabel());
IProject prj = root.getProject(technicalLabel);
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
IProjectDescription desc = null;
if (prj.exists()) {
// always delete to avoid conflicts between 2 tests
prj.delete(true, null);
}
desc = workspace.newProjectDescription(technicalLabel);
desc.setNatureIds(new String[] { TalendNature.ID });
desc.setComment(projectInfor.getDescription());
prj.create(desc, null);
prj.open(IResource.DEPTH_INFINITE, null);
prj.setDefaultCharset("UTF-8", null);
} catch (CoreException e) {
throw new PersistenceException(e);
}
sampleProject = new Project();
// Fill project object
sampleProject.setLabel(projectInfor.getLabel());
sampleProject.setDescription(projectInfor.getDescription());
sampleProject.setLanguage(projectInfor.getLanguage());
sampleProject.setAuthor(projectInfor.getAuthor());
sampleProject.setLocal(true);
sampleProject.setTechnicalLabel(technicalLabel);
XmiResourceManager xmiResourceManager = new XmiResourceManager();
Resource projectResource = xmiResourceManager.createProjectResource(prj);
projectResource.getContents().add(sampleProject.getEmfProject());
projectResource.getContents().add(sampleProject.getAuthor());
xmiResourceManager.saveResource(projectResource);
}
use of org.talend.core.repository.utils.XmiResourceManager in project tdi-studio-se by Talend.
the class ChangeXmiSerialization method execute.
@Override
public ExecutionResult execute(Project project) {
try {
if (!project.isLocal()) {
return ExecutionResult.NOTHING_TO_DO;
}
IProject iProject = ResourceUtils.getProject(project);
xmiResourceManager = new XmiResourceManager();
xmiResourceManager.setUseOldProjectFile(true);
if (!xmiResourceManager.hasTalendProjectFile(iProject)) {
return ExecutionResult.NOTHING_TO_DO;
}
PropertiesResourcesCollector propertiesResourcesCollector = new PropertiesResourcesCollector();
iProject.accept(propertiesResourcesCollector);
Collection<IFile> propertiesResourcesFiles = propertiesResourcesCollector.getPropertiesResourcesFiles();
for (IFile file : propertiesResourcesFiles) {
Property property = xmiResourceManager.loadProperty(file);
// we access the author (resolve proxy)
boolean correctAuthor = false;
try {
property.getAuthor();
} catch (Exception e) {
// author is null : fix old bug
correctAuthor = true;
}
if (correctAuthor || property.getAuthor().getLogin() == null) {
property.setAuthor(project.getAuthor());
}
EcoreUtil.resolveAll(property.eResource());
// if .properties is saved then migrated .item must also be saved
if (property.getItem() instanceof BusinessProcessItem) {
BusinessProcessItem businessProcessItem = (BusinessProcessItem) property.getItem();
businessProcessItem.getNotation();
}
modifiedResources.add(property.eResource());
}
Resource projectResource = xmiResourceManager.loadProject(iProject).eResource();
xmiResourceManager.setUseOldProjectFile(false);
Resource newProjectResource = xmiResourceManager.createProjectResource(iProject);
EObject[] objects = (EObject[]) projectResource.getContents().toArray();
for (EObject object : objects) {
newProjectResource.getContents().add(object);
}
modifiedResources.add(newProjectResource);
for (Resource resource : modifiedResources) {
try {
resource.setModified(true);
xmiResourceManager.saveResource(resource);
} catch (PersistenceException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
xmiResourceManager.deleteResource(projectResource);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
use of org.talend.core.repository.utils.XmiResourceManager in project tdi-studio-se by Talend.
the class FixProjectResourceLink method execute.
@Override
public ExecutionResult execute(Item item) {
if (item.getProperty().getAuthor() == null) {
// this case shouldn't happen normally, but just in case, each item should have one author
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
item.getProperty().setAuthor(factory.getRepositoryContext().getUser());
}
if (ERepositoryObjectType.getItemType(item).isDQItemType() && !ERepositoryObjectType.getItemType(item).isDIItemType()) {
return ExecutionResult.NOTHING_TO_DO;
}
if (item.getProperty().getAuthor().getLogin() != null) {
return ExecutionResult.NOTHING_TO_DO;
}
// if go here, it means property got wrong link to the project.
// (like for example item look for: ../../../talend.project, but it should be: ../../talend.project)
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
item.getProperty().setAuthor(factory.getRepositoryContext().getUser());
clearReferenceResourcesFileName(item);
// now we should remove wrong URI from resource manager.
// if this bug above happen, means the resourceSet keep wrong link to the project
XmiResourceManager manager = ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager();
List<Resource> toDelete = new ArrayList<Resource>();
for (Resource resource : manager.resourceSet.getResources()) {
if (resource.getURI().toString().contains(manager.getProjectFilename())) {
try {
IFile file = URIHelper.getFile(resource.getURI());
if (!file.exists()) {
toDelete.add(resource);
}
} catch (Exception e) {
toDelete.add(resource);
}
}
}
EmfHelper.visitChilds(item);
try {
factory.save(item, true);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
} catch (UnsupportedOperationException e1) {
ExceptionHandler.process(e1);
}
manager.resourceSet.getResources().removeAll(toDelete);
return ExecutionResult.SUCCESS_NO_ALERT;
}
use of org.talend.core.repository.utils.XmiResourceManager in project tdi-studio-se by Talend.
the class GenericRepositoryContentHandler method save.
private Resource save(GenericConnectionItem item) {
XmiResourceManager xmiResourceManager = ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager();
Resource itemResource = xmiResourceManager.getItemResource(item);
itemResource.getContents().clear();
MetadataManager.addContents(item, itemResource);
return itemResource;
}
Aggregations