Search in sources :

Example 1 with VersionRevision

use of org.talend.designer.components.exchange.model.VersionRevision in project tdi-studio-se by Talend.

the class MyExtensionAction method run.

public void run(IIntroSite site, Properties params) {
    if (params != null) {
        Object actionType = params.get(ContentConstants.KEY_TYPE);
        if (ContentConstants.UPLOAD_MY_EXTENSION.equals(actionType)) {
            try {
                String values = (String) params.get(ContentConstants.EXTENSIONVALUES);
                if (values != null) {
                    List<VersionRevision> versionRevisions = ExchangeManager.getInstance().getVersionRevisions();
                    ComponentExtension extension = ExchangeFactory.eINSTANCE.createComponentExtension();
                    setValuesForExension(extension, values, versionRevisions);
                    ExchangeManager.getInstance().setSelectedExtension(extension);
                    InsertionExtensionAction uploadAction = new InsertionExtensionAction(extension);
                    uploadAction.run();
                }
            } catch (JSONException e) {
                ExceptionHandler.process(e);
            }
        } else if (ContentConstants.UPDATE_MY_EXTENSION.equals(actionType) || ContentConstants.MODIFY_MY_EXTENSION.equals(actionType)) {
            try {
                String values = (String) params.get(ContentConstants.EXTENSIONVALUES);
                if (values != null) {
                    List<VersionRevision> versionRevisions = ExchangeManager.getInstance().getVersionRevisions();
                    ComponentExtension selectedExtension = ExchangeManager.getInstance().getSelectedExtension();
                    setValuesForExension(selectedExtension, values, versionRevisions);
                    if (ContentConstants.UPDATE_MY_EXTENSION.equals(actionType)) {
                        UploadRevisionAction uploadAction = new UploadRevisionAction(selectedExtension);
                        uploadAction.run();
                    } else {
                        ModifyExtensionAction modifyAction = new ModifyExtensionAction();
                        modifyAction.run();
                    }
                }
            } catch (JSONException e) {
                ExceptionHandler.process(e);
            }
        } else if (ContentConstants.UPLOAD_NEW_VERSION_ACTION.equals(actionType) || ContentConstants.MODIFY_ACTION.equals(actionType)) {
            Object object = params.get(ContentConstants.KEY_EXTENSION_ID);
            String key = null;
            if (object instanceof String) {
                key = (String) object;
            }
            ComponentExtension componentExtension = MyExchangeContentProvider.componentMap.get(key);
            if (componentExtension != null) {
                ExchangeManager.getInstance().setSelectedExtension(componentExtension);
                if (ContentConstants.UPLOAD_NEW_VERSION_ACTION.equals(actionType)) {
                    ExchangeManager.getInstance().generateXHTMLPage(ContentConstants.UL_UPLOAD_EXTENSION_VERSION, new String[] { ContentConstants.LAST_AVAILABLE_VERSION });
                } else {
                    ExchangeManager.getInstance().generateXHTMLPage(ContentConstants.UL_MODIFY_MY_EXTENSION_PAGE, new String[] { ContentConstants.EXTENSION_LABEL });
                }
            }
        } else if (ContentConstants.DELETE_ACTION.equals(actionType)) {
            Object object = params.get(ContentConstants.KEY_EXTENSION_ID);
            String key = null;
            if (object instanceof String) {
                key = (String) object;
            }
            ComponentExtension componentExtension = MyExchangeContentProvider.componentMap.get(key);
            ExchangeManager.getInstance().setSelectedExtension(componentExtension);
            if (componentExtension != null) {
                final DeleteExtensionAction delAction = new DeleteExtensionAction(componentExtension);
                if (delAction != null) {
                    delAction.run();
                }
            }
        }
    }
}
Also used : UploadRevisionAction(org.talend.designer.components.exchange.ui.actions.UploadRevisionAction) ModifyExtensionAction(org.talend.designer.components.exchange.ui.actions.ModifyExtensionAction) InsertionExtensionAction(org.talend.designer.components.exchange.ui.actions.InsertionExtensionAction) JSONException(org.talend.utils.json.JSONException) JSONObject(org.talend.utils.json.JSONObject) ComponentExtension(org.talend.designer.components.exchange.model.ComponentExtension) List(java.util.List) VersionRevision(org.talend.designer.components.exchange.model.VersionRevision) DeleteExtensionAction(org.talend.designer.components.exchange.ui.actions.DeleteExtensionAction)

Example 2 with VersionRevision

use of org.talend.designer.components.exchange.model.VersionRevision in project tdi-studio-se by Talend.

the class MyExtensionAction method filterVersionRevisionsToString.

private String filterVersionRevisionsToString(String status, String version, List<VersionRevision> fVersionRevisions) {
    if (fVersionRevisions == null || fVersionRevisions.isEmpty()) {
        return "";
    }
    StringBuffer sb = new StringBuffer();
    if (status.equals("all")) {
        for (VersionRevision ver : fVersionRevisions) {
            sb.append(ver.getVersionId());
            sb.append(",");
        }
        return sb.substring(0, sb.length() - 1);
    } else if (status.equals("older")) {
        for (VersionRevision ver : fVersionRevisions) {
            if (ver.getVersionName().equalsIgnoreCase(version)) {
                break;
            }
            sb.append(ver.getVersionId());
            sb.append(",");
        }
        return sb.substring(0, sb.length() - 1);
    } else if (status.equals("newer")) {
        boolean newerb = false;
        for (VersionRevision ver : fVersionRevisions) {
            if (ver.getVersionName().equalsIgnoreCase(version)) {
                newerb = true;
            }
            if (newerb) {
                sb.append(ver.getVersionId());
                sb.append(",");
            }
        }
        return sb.substring(0, sb.length() - 1);
    } else if (status.equals("except")) {
        for (VersionRevision ver : fVersionRevisions) {
            if (!ver.getVersionName().equalsIgnoreCase(version)) {
                sb.append(ver.getVersionId());
                sb.append(",");
            }
        }
        return sb.substring(0, sb.length() - 1);
    } else if (status.equals("only")) {
        for (VersionRevision ver : fVersionRevisions) {
            if (ver.getVersionName().equalsIgnoreCase(version)) {
                sb.append(ver.getVersionId());
                break;
            }
        }
        return sb.toString();
    }
    return "";
}
Also used : VersionRevision(org.talend.designer.components.exchange.model.VersionRevision)

Example 3 with VersionRevision

use of org.talend.designer.components.exchange.model.VersionRevision in project tdi-studio-se by Talend.

the class ExchangeWebService method searchVersionRevisionJSONArray.

/**
     * 
     * DOC hcyi Comment method "searchVersionRevisionJSONArray".
     * 
     * @param typeExtension
     * @return
     */
public static List<VersionRevision> searchVersionRevisionJSONArray(String typeExtension) {
    List<VersionRevision> fVersionRevisions = new ArrayList<VersionRevision>();
    JSONObject tokenMessage = new JSONObject();
    try {
        tokenMessage.put("typeExtension", typeExtension);
        JSONObject token = new us.monoid.json.JSONObject();
        token.put("extension", tokenMessage);
        String u = exchangeWSServer + "listVersionRevision.php?data=" + token;
        JSONObject resultObj = readJsonFromUrl(u);
        if (resultObj != null) {
            JSONObject p = (JSONObject) resultObj.get("listVersion");
            JSONArray resultArry = p.getJSONArray("version");
            if (resultArry != null) {
                for (int i = 0; i < resultArry.length(); i++) {
                    JSONObject extensionObj = resultArry.getJSONObject(i);
                    if (extensionObj != null) {
                        VersionRevision versionRevision = ExchangeFactory.eINSTANCE.createVersionRevision();
                        versionRevision.setVersionId(extensionObj.getString("id_version"));
                        versionRevision.setVersionName(extensionObj.getString("version"));
                        fVersionRevisions.add(versionRevision);
                    }
                }
            }
        }
    } catch (JSONException e) {
    //
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return fVersionRevisions;
}
Also used : JSONObject(us.monoid.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(us.monoid.json.JSONArray) JSONException(us.monoid.json.JSONException) VersionRevision(org.talend.designer.components.exchange.model.VersionRevision) IOException(java.io.IOException) JSONException(us.monoid.json.JSONException) IOException(java.io.IOException)

Example 4 with VersionRevision

use of org.talend.designer.components.exchange.model.VersionRevision in project tdi-studio-se by Talend.

the class ExchangeUtils method getVersionList.

public static String[] getVersionList(List<VersionRevision> fVersionRevisions) {
    versionMap.clear();
    try {
        //$NON-NLS-1$
        Pattern pattern = Pattern.compile("(\\d+\\.\\d+).*");
        for (VersionRevision info : fVersionRevisions) {
            String name = info.getVersionName();
            Matcher matcher = pattern.matcher(name);
            if (matcher.matches()) {
                versionMap.put(matcher.group(1), String.valueOf(info.getVersionId()));
            }
        }
        // sort version
        List<String> versions = new ArrayList<String>(versionMap.keySet());
        Collections.sort(versions, new Comparator<String>() {

            @Override
            public int compare(String o1, String o2) {
                Version ver1 = new Version(o1);
                Version ver2 = new Version(o2);
                return ver2.compareTo(ver1);
            }
        });
        return versions.toArray(new String[versions.size()]);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return new String[0];
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Version(org.osgi.framework.Version) ArrayList(java.util.ArrayList) VersionRevision(org.talend.designer.components.exchange.model.VersionRevision) IOException(java.io.IOException)

Aggregations

VersionRevision (org.talend.designer.components.exchange.model.VersionRevision)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Version (org.osgi.framework.Version)1 ComponentExtension (org.talend.designer.components.exchange.model.ComponentExtension)1 DeleteExtensionAction (org.talend.designer.components.exchange.ui.actions.DeleteExtensionAction)1 InsertionExtensionAction (org.talend.designer.components.exchange.ui.actions.InsertionExtensionAction)1 ModifyExtensionAction (org.talend.designer.components.exchange.ui.actions.ModifyExtensionAction)1 UploadRevisionAction (org.talend.designer.components.exchange.ui.actions.UploadRevisionAction)1 JSONException (org.talend.utils.json.JSONException)1 JSONObject (org.talend.utils.json.JSONObject)1 JSONArray (us.monoid.json.JSONArray)1 JSONException (us.monoid.json.JSONException)1 JSONObject (us.monoid.json.JSONObject)1