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();
}
}
}
}
}
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 "";
}
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;
}
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];
}
Aggregations