Search in sources :

Example 1 with RepositoryHelper

use of org.talend.designer.business.diagram.custom.util.RepositoryHelper in project tdi-studio-se by Talend.

the class GmfPastCommand method cloneAssignmentForModel.

private void cloneAssignmentForModel(List<BusinessItem> nodes, List pChildren) {
    if (nodes == null || pChildren == null) {
        return;
    }
    int i = nodes.size();
    for (BusinessItem businessItem : getSortedBusinessItems(nodes)) {
        BusinessItem newItem = (BusinessItem) getEObject(businessItem);
        if (!addNew) {
            newItem.setBusinessProcess(businessItem.getBusinessProcess());
        }
        newItem.setHAlignment(businessItem.getHAlignment());
        newItem.setName(businessItem.getName());
        newItem.setVAlignment(businessItem.getVAlignment());
        List assignments = new ArrayList();
        boolean execute = false;
        int n = 0;
        for (Object object : businessItem.getAssignments()) {
            BusinessAssignment older = (BusinessAssignment) object;
            BusinessAssignment newAssignment = (BusinessAssignment) getEObject(older);
            newAssignment.setBusinessItem(newItem);
            newAssignment.setComment(older.getComment());
            if (!addNew) {
                newAssignment.setTalendItem(older.getTalendItem());
            } else {
                TalendItem item = older.getTalendItem();
                String talendId = null;
                if (item != null) {
                    talendId = item.getId();
                } else {
                    List idList = (List) itemIds.get(businessItem);
                    if (n < idList.size()) {
                        talendId = (String) idList.get(n);
                    }
                    n++;
                }
                RepositoryNode node = null;
                if (talendId.split(" - ").length == 1) {
                    //$NON-NLS-1$
                    node = RepositoryNodeUtilities.getRepositoryNode(talendId);
                } else {
                    node = RepositoryNodeUtilities.getMetadataTableFromConnection(talendId);
                    if (node == null) {
                        node = RepositoryNodeUtilities.getQueryFromConnection(talendId);
                    }
                }
                RepositoryHelper repositoryHelper = new RepositoryHelper();
                Repository repository = process.getLocalRepositoryCopy();
                if (repository == null) {
                    repository = repositoryHelper.createLocalRepositoryCopy(process);
                }
                TalendItem talendItem = repositoryHelper.createTalendItem(repository, node);
                newAssignment.setTalendItem(talendItem);
            }
            assignments.add(newAssignment);
        }
        if (assignments.size() > 0) {
            newItem.getAssignments().addAll(assignments);
        }
        if (i <= pChildren.size()) {
            View node = (View) pChildren.get(pChildren.size() - i);
            node.setElement(newItem);
            i--;
        }
        if (addNew) {
            this.process.getBusinessItems().add(newItem);
        }
    }
}
Also used : BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) ArrayList(java.util.ArrayList) RepositoryNode(org.talend.repository.model.RepositoryNode) View(org.eclipse.gmf.runtime.notation.View) Repository(org.talend.designer.business.model.business.Repository) ArrayList(java.util.ArrayList) List(java.util.List) EObject(org.eclipse.emf.ecore.EObject) TalendItem(org.talend.designer.business.model.business.TalendItem) InputBusinessItem(org.talend.designer.business.model.business.InputBusinessItem) TerminalBusinessItem(org.talend.designer.business.model.business.TerminalBusinessItem) ActorBusinessItem(org.talend.designer.business.model.business.ActorBusinessItem) DatabaseBusinessItem(org.talend.designer.business.model.business.DatabaseBusinessItem) BusinessItem(org.talend.designer.business.model.business.BusinessItem) GearBusinessItem(org.talend.designer.business.model.business.GearBusinessItem) EllipseBusinessItem(org.talend.designer.business.model.business.EllipseBusinessItem) DataBusinessItem(org.talend.designer.business.model.business.DataBusinessItem) DecisionBusinessItem(org.talend.designer.business.model.business.DecisionBusinessItem) DocumentBusinessItem(org.talend.designer.business.model.business.DocumentBusinessItem) ActionBusinessItem(org.talend.designer.business.model.business.ActionBusinessItem) ListBusinessItem(org.talend.designer.business.model.business.ListBusinessItem) RepositoryHelper(org.talend.designer.business.diagram.custom.util.RepositoryHelper)

Example 2 with RepositoryHelper

use of org.talend.designer.business.diagram.custom.util.RepositoryHelper in project tdi-studio-se by Talend.

the class CreateAssignmentCommand method doExecuteWithResult.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse
     * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
     */
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
    // PTODO mhelleboid check if assignment already exist
    RepositoryHelper repositoryHelper = new RepositoryHelper();
    Repository repository = businessItem.getBusinessProcess().getLocalRepositoryCopy();
    TalendItem talendItem = null;
    if (repository == null) {
        repository = repositoryHelper.createLocalRepositoryCopy(businessItem.getBusinessProcess());
    }
    for (Object item : getItems()) {
        BusinessAssignment assignment = BusinessFactory.eINSTANCE.createBusinessAssignment();
        talendItem = repositoryHelper.getTalendItem(repository, item);
        if (talendItem == null) {
            talendItem = repositoryHelper.createTalendItem(repository, item);
        }
        if (talendItem == null) {
            //$NON-NLS-1$
            return CommandResult.newErrorCommandResult(Messages.getString("CreateAssignmentCommand.CannotAssign"));
        }
        assignment.setBusinessItem(businessItem);
        assignment.setTalendItem(talendItem);
    }
    return CommandResult.newOKCommandResult();
}
Also used : Repository(org.talend.designer.business.model.business.Repository) BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) TalendItem(org.talend.designer.business.model.business.TalendItem) RepositoryHelper(org.talend.designer.business.diagram.custom.util.RepositoryHelper)

Aggregations

RepositoryHelper (org.talend.designer.business.diagram.custom.util.RepositoryHelper)2 BusinessAssignment (org.talend.designer.business.model.business.BusinessAssignment)2 Repository (org.talend.designer.business.model.business.Repository)2 TalendItem (org.talend.designer.business.model.business.TalendItem)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EObject (org.eclipse.emf.ecore.EObject)1 View (org.eclipse.gmf.runtime.notation.View)1 ActionBusinessItem (org.talend.designer.business.model.business.ActionBusinessItem)1 ActorBusinessItem (org.talend.designer.business.model.business.ActorBusinessItem)1 BusinessItem (org.talend.designer.business.model.business.BusinessItem)1 DataBusinessItem (org.talend.designer.business.model.business.DataBusinessItem)1 DatabaseBusinessItem (org.talend.designer.business.model.business.DatabaseBusinessItem)1 DecisionBusinessItem (org.talend.designer.business.model.business.DecisionBusinessItem)1 DocumentBusinessItem (org.talend.designer.business.model.business.DocumentBusinessItem)1 EllipseBusinessItem (org.talend.designer.business.model.business.EllipseBusinessItem)1 GearBusinessItem (org.talend.designer.business.model.business.GearBusinessItem)1 InputBusinessItem (org.talend.designer.business.model.business.InputBusinessItem)1 ListBusinessItem (org.talend.designer.business.model.business.ListBusinessItem)1 TerminalBusinessItem (org.talend.designer.business.model.business.TerminalBusinessItem)1