Search in sources :

Example 1 with AElementPersistance

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);
            }
        }
    }
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) IFile(org.eclipse.core.resources.IFile) Resource(org.eclipse.emf.ecore.resource.Resource) AElementPersistance(org.talend.dq.writer.AElementPersistance) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with AElementPersistance

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);
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) IFile(org.eclipse.core.resources.IFile) AElementPersistance(org.talend.dq.writer.AElementPersistance) Property(org.talend.core.model.properties.Property)

Example 3 with AElementPersistance

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;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) AElementPersistance(org.talend.dq.writer.AElementPersistance)

Example 4 with AElementPersistance

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;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Item(org.talend.core.model.properties.Item) AElementPersistance(org.talend.dq.writer.AElementPersistance) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with AElementPersistance

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);
    }
}
Also used : EResourceConstant(org.talend.resource.EResourceConstant) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) Dependency(orgomg.cwm.objectmodel.core.Dependency) URI(org.eclipse.emf.common.util.URI) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) Item(org.talend.core.model.properties.Item) TDQSourceFileItem(org.talend.dataquality.properties.TDQSourceFileItem) TDQFileItem(org.talend.dataquality.properties.TDQFileItem) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) EObject(org.eclipse.emf.ecore.EObject) AElementPersistance(org.talend.dq.writer.AElementPersistance) File(java.io.File) Property(org.talend.core.model.properties.Property)

Aggregations

AElementPersistance (org.talend.dq.writer.AElementPersistance)6 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)6 Resource (org.eclipse.emf.ecore.resource.Resource)3 Property (org.talend.core.model.properties.Property)3 IFile (org.eclipse.core.resources.IFile)2 IFolder (org.eclipse.core.resources.IFolder)2 URI (org.eclipse.emf.common.util.URI)2 Item (org.talend.core.model.properties.Item)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 EObject (org.eclipse.emf.ecore.EObject)1 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)1 TDQFileItem (org.talend.dataquality.properties.TDQFileItem)1 TDQSourceFileItem (org.talend.dataquality.properties.TDQSourceFileItem)1 EResourceConstant (org.talend.resource.EResourceConstant)1 Dependency (orgomg.cwm.objectmodel.core.Dependency)1