use of org.talend.dq.writer.AElementPersistance in project tdq-studio-se by Talend.
the class UpdateAfterMergeTosApiTask method createNewItemFile.
/**
* DOC bZhou Comment method "createNewItemFile".
*
* @param file
*/
private void createNewItemFile(File file) {
ModelElement modelElement = getModelElement(file);
if (modelElement != null) {
boolean needUpdateFlag = !modelElement.eIsProxy();
// log.info("modelElement======>" + modelElement);
if (needUpdateFlag) {
IFile iFile = WorkspaceUtils.fileToIFile(file);
IFolder parentFolder = (IFolder) iFile.getParent();
Resource oldRes = modelElement.eResource();
List<Resource> needSaves = getReferenceResources(oldRes, modelElement);
AElementPersistance writer = ElementWriterFactory.getInstance().create(modelElement);
writer.create(modelElement, parentFolder, true);
EMFUtil.changeUri(oldRes, EObjectHelper.getURI(modelElement));
for (Resource toSave : needSaves) {
EMFSharedResources.getInstance().saveResource(toSave);
}
}
}
}
use of org.talend.dq.writer.AElementPersistance in project tdq-studio-se by Talend.
the class DQStructureManager method copyFileToFolder.
/**
* DOC klliu Comment method "copyFileToFolder".
*
* @param inputStream
* @param fileName
* @param folder
* @throws CoreException
* @throws IOException
*/
private void copyFileToFolder(InputStream inputStream, String fileName, IFolder folder, boolean... isImportItem) throws CoreException, IOException {
if (inputStream == null) {
return;
}
IFile elementFile = folder.getFile(fileName);
if (!elementFile.exists()) {
elementFile.create(inputStream, false, null);
ModelElement modelElement = ModelElementFileFactory.getModelElement(elementFile);
if (modelElement != null) {
AElementPersistance writer = ElementWriterFactory.getInstance().create(elementFile.getFileExtension());
if (writer != null) {
Property initProperty = writer.initProperty(modelElement);
String propFileName = // $NON-NLS-1$ //$NON-NLS-2$
initProperty.getLabel() + "_" + initProperty.getVersion() + "." + elementFile.getFileExtension();
IFile file = elementFile.getParent().getFile(new Path(propFileName));
if (file == null || !file.exists()) {
writer.create(modelElement, folder, isImportItem);
}
elementFile.delete(true, null);
}
}
}
}
use of org.talend.dq.writer.AElementPersistance in project tdq-studio-se by Talend.
the class CreateElementPropertiesTask method doExecute.
/*
* (non-Javadoc)
*
* @see org.talend.dataprofiler.core.migration.AMigrationTask#doExecute()
*/
@Override
protected boolean doExecute() throws Exception {
ModelElement[] allElements = ModelElementFileFactory.getALLElements(false);
for (ModelElement element : allElements) {
AElementPersistance writer = ElementWriterFactory.getInstance().create(element);
writer.createProperty(element);
}
return true;
}
use of org.talend.dq.writer.AElementPersistance in project tdq-studio-se by Talend.
the class ModelElementDuplicateHandle method duplicateItem.
/*
* (non-Javadoc)
*
* @see
* org.talend.dataprofiler.core.ui.action.actions.handle.IDuplicateHandle#duplicateItem(org.talend.core.model.properties
* .Item, java.lang.String)
*/
public Item duplicateItem(Item oldItem, String newName) throws BusinessException {
// duplicate the related model element
ModelElement oldModelElement = PropertyHelper.getModelElement(oldItem.getProperty());
// create the related item and save
AElementPersistance elementWriter = ElementWriterFactory.getInstance().create(oldModelElement);
ModelElement newModelElement = duplicateModelElement(oldModelElement, newName);
IFolder folder = extractFolder(oldItem, oldModelElement);
TypedReturnCode<Object> returnCode = elementWriter.create(newModelElement, folder);
if (returnCode.isOk()) {
if (needSaveDepend()) {
// In order to save related dependency's change, need to save again
elementWriter.save((Item) returnCode.getObject(), Boolean.TRUE);
}
return (Item) returnCode.getObject();
} else {
createBusinessException(DefaultMessagesImpl.getString("ModelElementDuplicateHandle.duplicateFail", oldModelElement.getName(), returnCode.getMessage()));
}
return null;
}
use of org.talend.dq.writer.AElementPersistance in project tdq-studio-se by Talend.
the class DependenciesHandler method findClientAndRemoveDependencyInLocalProject.
private static void findClientAndRemoveDependencyInLocalProject(ModelElement modelElement, ModelElement analysis) {
URI uri = EObjectHelper.getURI(modelElement).trimFileExtension().appendFileExtension(FactoriesUtil.PROPERTIES_EXTENSION);
// get file from filename
String fileName = uri.lastSegment();
File foundFile = null;
EResourceConstant[] topConstants = EResourceConstant.getTopConstants();
for (EResourceConstant resource : topConstants) {
File reportFolder = ResourceManager.getRootProject().getLocation().append(resource.getPath()).toFile();
List<File> fileList = FileUtils.getFilesByExtension(reportFolder, FactoriesUtil.PROPERTIES_EXTENSION);
for (File file : fileList) {
if (file.getName().equals(fileName)) {
foundFile = file;
break;
}
}
if (foundFile != null) {
break;
}
}
// from file to get model and change it
if (foundFile != null) {
Property property = PropertyHelper.getProperty(foundFile);
// change the cache content also
Item item = property.getItem();
Resource itemResource = ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().getItemResource(item);
List<EObject> toRemoveObjList = new ArrayList<EObject>();
for (EObject obj : itemResource.getContents()) {
if (obj != null && obj instanceof Dependency) {
EList<ModelElement> clients = ((Dependency) obj).getClient();
for (ModelElement model : clients) {
if (model.getName() == null) {
toRemoveObjList.add(obj);
} else {
if (StringUtils.equals(model.getName(), analysis.getName())) {
toRemoveObjList.add(obj);
break;
}
}
}
EList<ModelElement> supplier = ((Dependency) obj).getSupplier();
for (ModelElement model : supplier) {
if (model.getName() == null) {
toRemoveObjList.add(obj);
} else {
if (StringUtils.equals(model.getName(), item.getProperty().getLabel())) {
toRemoveObjList.add(obj);
break;
}
}
}
} else {
// modify where rule
EList<Dependency> supplierDependency = ((ModelElement) obj).getSupplierDependency();
Iterator<Dependency> iterator = supplierDependency.iterator();
while (iterator.hasNext()) {
Dependency model = iterator.next();
EList<ModelElement> clients = model.getClient();
for (ModelElement client : clients) {
if (StringUtils.equals(client.getName(), analysis.getName())) {
iterator.remove();
break;
}
}
}
}
}
for (EObject removeObj : toRemoveObjList) {
if (removeObj != null) {
itemResource.getContents().remove(removeObj);
}
}
// save the node
AElementPersistance writer = ElementWriterFactory.getInstance().create(item);
writer.save(item, true);
}
}
Aggregations