Search in sources :

Example 41 with Property

use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.

the class GenericRepository method storeProperties.

@Override
public String storeProperties(ComponentProperties properties, String name, String repositoryLocation, String schemaPropertyName) {
    if (properties == null) {
        //$NON-NLS-1$
        throw new RuntimeException("Properties argument cannot be null!");
    }
    // Add repository value if it is from repository
    List<org.talend.daikon.properties.property.Property> propertyValues = ComponentsUtils.getAllValuedProperties(properties);
    for (org.talend.daikon.properties.property.Property property : propertyValues) {
        property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, property.getName());
    }
    String serializedProperties = properties.toSerialized();
    if (repositoryLocation.contains(IGenericConstants.REPOSITORY_LOCATION_SEPARATOR)) {
        // nested properties to be
        GenericConnectionItem item = getGenericConnectionItem(repositoryLocation.substring(0, repositoryLocation.indexOf(IGenericConstants.REPOSITORY_LOCATION_SEPARATOR)));
        if (item == null) {
            //$NON-NLS-1$
            throw new RuntimeException("Failed to find the GenericConnectionItem for location:" + repositoryLocation);
        }
        GenericConnection connection = (GenericConnection) item.getConnection();
        orgomg.cwm.objectmodel.core.Package parentContainer = null;
        if (repositoryLocation.endsWith(IGenericConstants.REPOSITORY_LOCATION_SEPARATOR)) {
            // first nested property
            parentContainer = connection;
        } else {
            parentContainer = getContainer(connection, repositoryLocation);
        }
        ModelElement childElement = null;
        if (schemaPropertyName == null) {
            // If schema property name is not provided, then create the subcontainer.
            childElement = createContainer(name, serializedProperties);
        } else {
            // Remove Repository Value tag value for schema property.
            org.talend.daikon.properties.property.Property<?> schemaProperty = properties.getValuedProperty(schemaPropertyName);
            if (schemaProperty != null) {
                schemaProperty.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, null);
            }
            childElement = SchemaUtils.createSchema(name, properties, schemaPropertyName);
        }
        parentContainer.getOwnedElement().add(childElement);
        return repositoryLocation + IGenericConstants.REPOSITORY_LOCATION_SEPARATOR + name;
    } else {
        // simple properties to be set
        GenericConnectionItem item = getGenericConnectionItem(repositoryLocation);
        if (item != null) {
            GenericConnection connection = (GenericConnection) item.getConnection();
            connection.setCompProperties(serializedProperties);
            connection.getOwnedElement().clear();
            return repositoryLocation + IGenericConstants.REPOSITORY_LOCATION_SEPARATOR;
        } else {
            //$NON-NLS-1$
            throw new RuntimeException("Failed to find the GenericConnectionItem for location:" + repositoryLocation);
        }
    }
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) Property(org.talend.core.model.properties.Property)

Example 42 with Property

use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.

the class TalendImportUtil method openJobs.

private static void openJobs(List<IRepositoryNode> nodes) {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    for (IRepositoryNode node : nodes) {
        Property property = node.getObject().getProperty();
        if (property != null) {
            Item item = property.getItem();
            if (!(item instanceof ProcessItem)) {
                continue;
            }
            try {
                ProcessItem processItem = (ProcessItem) item;
                final JobEditorInput fileEditorInput = getEditorInput(processItem);
                // checkUnLoadedNodeForProcess(fileEditorInput);
                final IEditorPart editorPart = page.findEditor(fileEditorInput);
                if (editorPart == null) {
                    fileEditorInput.setRepositoryNode(node);
                    page.openEditor(fileEditorInput, getEditorId(), true);
                } else {
                    ((AbstractMultiPageTalendEditor) editorPart).setReadOnly(fileEditorInput.setForceReadOnly(false));
                    page.activate(editorPart);
                }
            } catch (Throwable e) {
                CommonExceptionHandler.process(e);
            }
        }
    }
}
Also used : JobEditorInput(org.talend.core.ui.editor.JobEditorInput) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ProcessItem(org.talend.core.model.properties.ProcessItem) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) Property(org.talend.core.model.properties.Property)

Example 43 with Property

use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.

the class NewGenericWizardMigrationTask method updateComponentProperties.

protected boolean updateComponentProperties(Connection oldConnection, ComponentProperties componentProperties, Properties props) {
    boolean modified = false;
    if (props != null) {
        for (Object element : props.keySet()) {
            boolean changed = false;
            String propsKey = (String) element;
            String propsValue = props.getProperty(propsKey);
            if (propsValue != null && !"".equals(propsValue.trim())) {
                //$NON-NLS-1$
                Object value = getValueFromOldConnection(oldConnection, propsValue);
                if (value != null) {
                    NamedThing namedThing = componentProperties.getProperty(propsKey);
                    if (namedThing != null && namedThing instanceof org.talend.daikon.properties.property.Property) {
                        org.talend.daikon.properties.property.Property<?> property = (org.talend.daikon.properties.property.Property<?>) namedThing;
                        if (GenericTypeUtils.isEnumType(property)) {
                            //$NON-NLS-1$
                            Object obj = props.get(propsKey + "." + value);
                            if (obj != null) {
                                List<?> propertyPossibleValues = property.getPossibleValues();
                                Object newValue = null;
                                if (propertyPossibleValues != null) {
                                    for (Object possibleValue : propertyPossibleValues) {
                                        if (possibleValue.toString().equals(obj)) {
                                            newValue = possibleValue;
                                            break;
                                        }
                                    }
                                }
                                if (newValue == null) {
                                    // set default value
                                    newValue = propertyPossibleValues.get(0);
                                }
                                componentProperties.setValue(propsKey, newValue);
                                property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, property.getName());
                                changed = true;
                            }
                        }
                        if (GenericTypeUtils.isBooleanType(property)) {
                            if (value != null && value instanceof String) {
                                try {
                                    value = new Boolean((String) value);
                                } catch (Exception e) {
                                    value = Boolean.FALSE;
                                }
                            }
                        }
                        if (GenericTypeUtils.isIntegerType(property) && !oldConnection.isContextMode()) {
                            if (value != null && value instanceof String) {
                                try {
                                    value = new Integer((String) value);
                                } catch (Exception e) {
                                    value = 0;
                                }
                            }
                        }
                        if (property.isFlag(org.talend.daikon.properties.property.Property.Flags.ENCRYPT) && !oldConnection.isContextMode()) {
                            componentProperties.setValue(propsKey, CryptoHelper.getDefault().decrypt(String.valueOf(value)));
                            property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, property.getName());
                            modified = true;
                            changed = true;
                        }
                        if (!changed) {
                            property.setStoredValue(value);
                            property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, property.getName());
                            modified = true;
                        }
                    }
                }
            }
        }
    }
    return modified;
}
Also used : NamedThing(org.talend.daikon.NamedThing) Property(org.talend.core.model.properties.Property)

Example 44 with Property

use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.

the class NewGenericWizardMigrationTask method initProperty.

protected Property initProperty(ConnectionItem oldConnectionItem, ConnectionItem newConnectionItem) {
    if (oldConnectionItem == null || newConnectionItem == null) {
        return null;
    }
    Property oldProperty = oldConnectionItem.getProperty();
    Property newProperty = PropertiesFactory.eINSTANCE.createProperty();
    newProperty.setId(oldProperty.getId());
    newProperty.setLabel(oldProperty.getLabel());
    newProperty.setDisplayName(oldProperty.getDisplayName());
    newProperty.setDescription(oldProperty.getDescription());
    newProperty.setAuthor(oldProperty.getAuthor());
    newProperty.setCreationDate(oldProperty.getCreationDate());
    newProperty.setMaxInformationLevel(oldProperty.getMaxInformationLevel());
    newProperty.setModificationDate(oldProperty.getModificationDate());
    newProperty.setOldStatusCode(oldProperty.getOldStatusCode());
    newProperty.setPurpose(oldProperty.getPurpose());
    newProperty.setStatusCode(oldProperty.getStatusCode());
    newProperty.setVersion(oldProperty.getVersion());
    newProperty.setItem(newConnectionItem);
    newConnectionItem.setProperty(newProperty);
    return newProperty;
}
Also used : Property(org.talend.core.model.properties.Property)

Example 45 with Property

use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.

the class GenericConnPropertiesWizard method performFinish.

@Override
public boolean performFinish() {
    boolean done = super.performFinish();
    if (done) {
        Property property = object.getProperty();
        GenericConnectionItem gcItem = (GenericConnectionItem) property.getItem();
        boolean itemChanged = GenericConnectionUtil.synNamePropertyWithItem(gcItem);
        if (itemChanged) {
            try {
                ProxyRepositoryFactory.getInstance().save(gcItem);
            } catch (PersistenceException e) {
                done = false;
                ExceptionHandler.process(e);
            }
        }
    }
    return done;
}
Also used : PersistenceException(org.talend.commons.exception.PersistenceException) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) Property(org.talend.core.model.properties.Property)

Aggregations

Property (org.talend.core.model.properties.Property)147 PersistenceException (org.talend.commons.exception.PersistenceException)56 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)48 Item (org.talend.core.model.properties.Item)46 ProcessItem (org.talend.core.model.properties.ProcessItem)39 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)36 Node (org.talend.designer.core.ui.editor.nodes.Node)28 Process (org.talend.designer.core.ui.editor.process.Process)23 RepositoryNode (org.talend.repository.model.RepositoryNode)22 IElementParameter (org.talend.core.model.process.IElementParameter)21 ConnectionItem (org.talend.core.model.properties.ConnectionItem)21 IDynamicProperty (org.talend.core.ui.properties.tab.IDynamicProperty)21 ArrayList (java.util.ArrayList)20 Test (org.junit.Test)19 INode (org.talend.core.model.process.INode)19 IComponent (org.talend.core.model.components.IComponent)15 Connection (org.talend.core.model.metadata.builder.connection.Connection)14 IProcess2 (org.talend.core.model.process.IProcess2)14 List (java.util.List)12 IFile (org.eclipse.core.resources.IFile)12