Search in sources :

Example 66 with IProxyRepositoryFactory

use of org.talend.repository.model.IProxyRepositoryFactory in project tdi-studio-se by Talend.

the class JobletUtil method needReadOnlyJoblet.

public boolean needReadOnlyJoblet(JobletProcessItem jobletItem) {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart[] editors = page.getEditors();
    for (IEditorPart editor : editors) {
        if (editor instanceof AbstractMultiPageTalendEditor) {
            List<? extends INode> nodeList = ((AbstractMultiPageTalendEditor) editor).getProcess().getGraphicalNodes();
            for (INode node : nodeList) {
                if (((Node) node).isJoblet() && jobletItem.getProperty() != null) {
                    if (jobletItem.getProperty().getId().equals(node.getComponent().getProcess().getId())) {
                        boolean haveLock = jobletItem.getState().isLocked();
                        boolean isSvn = false;
                        ISVNProviderService service = null;
                        if (PluginChecker.isSVNProviderPluginLoaded()) {
                            service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
                        }
                        if (service != null && service.isProjectInSvnMode()) {
                            isSvn = service.isProjectInSvnMode();
                        }
                        if (isSvn) {
                            IProxyRepositoryService proxyService = (IProxyRepositoryService) GlobalServiceRegister.getDefault().getService(IProxyRepositoryService.class);
                            IProxyRepositoryFactory factory = proxyService.getProxyRepositoryFactory();
                            ERepositoryStatus repositoryStatus = factory.getStatus(jobletItem);
                            if (repositoryStatus == ERepositoryStatus.LOCK_BY_USER) {
                                haveLock = true;
                            }
                        }
                        if (haveLock) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : INode(org.talend.core.model.process.INode) ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) IProxyRepositoryService(org.talend.repository.model.IProxyRepositoryService) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISVNProviderService(org.talend.core.services.ISVNProviderService) IEditorPart(org.eclipse.ui.IEditorPart) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 67 with IProxyRepositoryFactory

use of org.talend.repository.model.IProxyRepositoryFactory in project tdi-studio-se by Talend.

the class DbTableController method getExistConnection.

/**
     * DOC zli Comment method "getExistConnection".
     * 
     * @return
     */
private DatabaseConnection getExistConnection() {
    String implicitRepositoryId = getImplicitRepositoryId();
    String statsLogPrositoryId = getStatsLogRepositoryId();
    if (implicitRepositoryId != null || statsLogPrositoryId != null) {
        // jobsetting view load the exist db info from current selected category
        String repId = null;
        if (EComponentCategory.EXTRA.equals(section)) {
            repId = implicitRepositoryId;
        } else if (EComponentCategory.STATSANDLOGS.equals(section)) {
            repId = statsLogPrositoryId;
        }
        if (repId != null) {
            IProxyRepositoryFactory proxyRepositoryFactory = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
            try {
                IRepositoryViewObject lastVersion = proxyRepositoryFactory.getLastVersion(repId);
                if (lastVersion != null) {
                    Item item = lastVersion.getProperty().getItem();
                    if (item instanceof DatabaseConnectionItem) {
                        DatabaseConnection connection = (DatabaseConnection) ((DatabaseConnectionItem) item).getConnection();
                        return connection;
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
    }
    return null;
}
Also used : Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 68 with IProxyRepositoryFactory

use of org.talend.repository.model.IProxyRepositoryFactory in project tdi-studio-se by Talend.

the class GenerateGrammarController method persistInRoutine.

/**
     * Persist item in routines
     * 
     * DOC ytao Comment method "persistInRoutine".
     * 
     * @param path, sub folder named with job id
     * @param label, java file name without suffix
     * @param initFile, File handler
     * @param name, job id as package name
     * @return
     */
private RoutineItem persistInRoutine(IPath inFolder, File fileToFill, String label) {
    // item property to be set
    Property property = PropertiesFactory.eINSTANCE.createProperty();
    property.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
    property.setVersion(VersionUtils.DEFAULT_VERSION);
    //$NON-NLS-1$
    property.setStatusCode("");
    // Label must match pattern ^[a-zA-Z\_]+[a-zA-Z0-9\_]*$
    // Must be composed with JAVA_PORJECT_NAME + JOB NAME + COMPONENT NAME,
    // since all projects share with the same routines
    property.setLabel(label);
    // add properties to item
    RoutineItem routineItem = PropertiesFactory.eINSTANCE.createRoutineItem();
    routineItem.setProperty(property);
    // get the content of java file as byte array.
    ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
    InputStream stream = null;
    try {
        stream = new FileInputStream(fileToFill);
        byte[] bytes = new byte[stream.available()];
        stream.read(bytes);
        byteArray.setInnerContent(bytes);
    } catch (IOException e) {
        ExceptionHandler.process(e);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    routineItem.setContent(byteArray);
    // persist item in routines
    IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    try {
        property.setId(repositoryFactory.getNextId());
        // create folder with name job id: routines/JOBID (seems from TOS)
        repositoryFactory.createParentFoldersRecursively(ERepositoryObjectType.getItemType(routineItem), inFolder);
        // add the item
        repositoryFactory.create(routineItem, inFolder);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return routineItem;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteArray(org.talend.core.model.properties.ByteArray) RoutineItem(org.talend.core.model.properties.RoutineItem) IOException(java.io.IOException) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) FileInputStream(java.io.FileInputStream) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) SystemException(org.talend.commons.exception.SystemException) IOException(java.io.IOException)

Example 69 with IProxyRepositoryFactory

use of org.talend.repository.model.IProxyRepositoryFactory in project tdi-studio-se by Talend.

the class ValidationRulesUtil method getComponentsFromItemId.

/**
     * DOC ycbai Comment method "getComponentsFromItemId". modify from method getAppropriateComponent() of
     * TalendEditorDropTargetListener.
     * 
     * @param itemId
     * @param type
     * @param quickCreateInput
     * @param quickCreateOutput
     * @return
     */
public static IComponent getComponentsFromItemId(String itemId, ERepositoryObjectType type, boolean quickCreateInput, boolean quickCreateOutput) {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    IRepositoryViewObject obj = null;
    try {
        obj = factory.getLastVersion(itemId);
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    if (obj == null) {
        return null;
    }
    Item item = obj.getProperty().getItem();
    if (item == null) {
        return null;
    }
    EDatabaseComponentName name = EDatabaseComponentName.getCorrespondingComponentName(item, type);
    String componentName = null;
    if (item instanceof JobletProcessItem) {
        // joblet
        componentName = item.getProperty().getLabel();
    } else if (name == null) {
        return null;
    } else {
        // tRunjob
        componentName = name.getDefaultComponentName();
    }
    // tRunJob is special from our rules
    if (name == EDatabaseComponentName.RunJob || item instanceof JobletProcessItem) {
        return ComponentsFactoryProvider.getInstance().get(componentName, ComponentCategory.CATEGORY_4_DI.getName());
    } else {
        // for database, file, webservices, saleforce ...
        List<IComponent> neededComponents = filterNeededComponents(item, type);
        IComponent component = chooseOneComponent(neededComponents, name, quickCreateInput, quickCreateOutput);
        return component;
    }
}
Also used : HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) WSDLSchemaConnectionItem(org.talend.core.model.properties.WSDLSchemaConnectionItem) Item(org.talend.core.model.properties.Item) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) EDatabaseComponentName(org.talend.designer.core.ui.editor.process.EDatabaseComponentName) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IComponent(org.talend.core.model.components.IComponent) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 70 with IProxyRepositoryFactory

use of org.talend.repository.model.IProxyRepositoryFactory in project tdi-studio-se by Talend.

the class ValidationRulesUtil method getRelatedValidationRuleObjs.

public static List<IRepositoryViewObject> getRelatedValidationRuleObjs(String schemaId) {
    List<IRepositoryViewObject> rulesObjs = new ArrayList<IRepositoryViewObject>();
    if (schemaId != null) {
        try {
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            List<IRepositoryViewObject> members = factory.getAll(ERepositoryObjectType.METADATA_VALIDATION_RULES);
            if (members != null && members.size() > 0) {
                for (IRepositoryViewObject member : members) {
                    if (member != null && member.getProperty() != null) {
                        Item item = member.getProperty().getItem();
                        if (item != null && item instanceof ValidationRulesConnectionItem) {
                            ValidationRulesConnectionItem validItem = (ValidationRulesConnectionItem) item;
                            ValidationRulesConnection connection = (ValidationRulesConnection) validItem.getConnection();
                            if (connection != null && !rulesObjs.contains(member)) {
                                rulesObjs.add(member);
                            }
                        }
                    }
                }
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    }
    return rulesObjs;
}
Also used : ValidationRulesConnection(org.talend.core.model.metadata.builder.connection.ValidationRulesConnection) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) WSDLSchemaConnectionItem(org.talend.core.model.properties.WSDLSchemaConnectionItem) Item(org.talend.core.model.properties.Item) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) XmlFileConnectionItem(org.talend.core.model.properties.XmlFileConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)251 PersistenceException (org.talend.commons.exception.PersistenceException)154 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)96 Item (org.talend.core.model.properties.Item)67 Property (org.talend.core.model.properties.Property)58 ArrayList (java.util.ArrayList)42 ConnectionItem (org.talend.core.model.properties.ConnectionItem)34 RepositoryNode (org.talend.repository.model.RepositoryNode)32 ProcessItem (org.talend.core.model.properties.ProcessItem)29 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)28 CoreException (org.eclipse.core.runtime.CoreException)23 LoginException (org.talend.commons.exception.LoginException)22 IRepositoryService (org.talend.repository.model.IRepositoryService)22 ERepositoryStatus (org.talend.commons.runtime.model.repository.ERepositoryStatus)21 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)21 IElementParameter (org.talend.core.model.process.IElementParameter)21 Connection (org.talend.core.model.metadata.builder.connection.Connection)20 List (java.util.List)18 IFile (org.eclipse.core.resources.IFile)18 Project (org.talend.core.model.general.Project)18