use of com.amalto.workbench.webservices.WSAutoIncrement in project tmdm-studio-se by Talend.
the class ImportItemsWizard method parses.
protected void parses(boolean importFromArchieve, String zipFilePath, IProgressMonitor monitor) {
// init var for progressMonitor
int total = 500, zipCount = 200, readCount = 100;
int step = 1, interval = 1;
//
monitor.beginTask(Messages.ImportItemsWizard_7, total);
if (importFromArchieve) {
checkUpExchangeImport(true);
try {
Util.unZipFile(zipFilePath, importFolder, zipCount, monitor);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
monitor.worked(zipCount);
monitor.setTaskName(Messages.ImportItemsWizard_8);
InputStreamReader reader = null;
try {
// $NON-NLS-1$//$NON-NLS-2$
reader = new InputStreamReader(new FileInputStream(importFolder + "/exportitems.xml"), "UTF-8");
final Exports exports = (Exports) Unmarshaller.unmarshal(Exports.class, reader);
String[] orgSchemas = exports.getSchemas();
int idx = 0;
if (orgSchemas != null) {
for (String orgSchema : orgSchemas) {
String orgSchemaCpy = new String(orgSchema);
for (Map.Entry<String, String> pair : ICoreConstants.rolesConvert.oldRoleToNewRoleMap.entrySet()) {
orgSchemaCpy = orgSchemaCpy.replaceAll(pair.getKey().toString(), pair.getValue().toString());
}
if (!orgSchemaCpy.equals(orgSchema)) {
orgSchemas[idx] = orgSchemaCpy;
}
idx++;
}
}
try {
LocalTreeObjectRepository.getInstance().makeUpDocWithImportCategory(orgSchemas, serverRoot);
} catch (Exception e) {
}
// import autoincrement
if (exports.getAutoIncrement() != null) {
try {
service.getAutoIncrement(new WSAutoIncrement(exports.getAutoIncrement()));
} catch (Exception e) {
}
}
// new server root
final TreeParent reserverRoot = new TreeParent(serverRoot.getDisplayName(), null, TreeObject._SERVER_, serverRoot.getWsKey(), serverRoot.getWsObject());
reserverRoot.setUser(serverRoot.getUser());
// serverRoot=reserverRoot;
TreeParent clusters = new TreeParent(EXtentisObjects.DataCluster.getDisplayName(), reserverRoot, TreeObject.DATA_CLUSTER, null, null);
TreeParent models = new TreeParent(EXtentisObjects.DataMODEL.getDisplayName(), reserverRoot, TreeObject.DATA_MODEL, null, null);
TreeParent menus = new TreeParent(EXtentisObjects.Menu.getDisplayName(), reserverRoot, TreeObject.MENU, null, null);
TreeParent roles = new TreeParent(EXtentisObjects.Role.getDisplayName(), reserverRoot, TreeObject.ROLE, null, null);
TreeParent eventManager = new TreeParent(EXtentisObjects.EventManagement.getDisplayName(), reserverRoot, TreeObject.EVENT_MANAGEMENT, null, null);
TreeParent routingrules = new TreeParent(EXtentisObjects.RoutingRule.getDisplayName(), reserverRoot, TreeObject.ROUTING_RULE, null, null);
TreeParent storeprocedures = new TreeParent(EXtentisObjects.StoredProcedure.getDisplayName(), reserverRoot, TreeObject.STORED_PROCEDURE, null, null);
TreeParent transformers = new TreeParent(EXtentisObjects.Transformer.getDisplayName(), reserverRoot, TreeObject.TRANSFORMER, null, null);
TreeParent pictures = new TreeParent(EXtentisObjects.PICTURESRESOURCE.getDisplayName(), reserverRoot, TreeObject.PICTURES_RESOURCE, null, null);
// add by ymli
TreeParent workflow = new TreeParent(EXtentisObjects.Workflow.getDisplayName(), reserverRoot, TreeObject.WORKFLOW, null, null);
TreeParent views = new TreeParent(EXtentisObjects.View.getDisplayName(), reserverRoot, TreeObject.VIEW, null, null);
reserverRoot.addChild(clusters);
reserverRoot.addChild(models);
reserverRoot.addChild(menus);
reserverRoot.addChild(roles);
reserverRoot.addChild(storeprocedures);
eventManager.addChild(transformers);
eventManager.addChild(routingrules);
reserverRoot.addChild(eventManager);
reserverRoot.addChild(pictures);
reserverRoot.addChild(workflow);
reserverRoot.addChild(views);
monitor.worked(readCount);
// caculate step and interval
float val = (total - zipCount - readCount) / exports.getItems().length;
if (val > 0) {
interval = 1;
step = Math.round(val);
} else {
step = 1;
interval = Math.round(exports.getItems().length / (total - zipCount - readCount) + 0.5f);
}
// System.out.println("count:" + exports.getItems().length + "\tinterval:" + interval + "\tstep:" + step);
monitor.setTaskName(Messages.ImportItemsWizard_9);
//
int tmp = 1;
for (TreeObject obj : exports.getItems()) {
obj.setServerRoot(reserverRoot);
switch(obj.getType()) {
case TreeObject.DATA_CLUSTER:
clusters.addChild(obj);
break;
case TreeObject.DATA_MODEL:
models.addChild(obj);
break;
case TreeObject.MENU:
menus.addChild(obj);
break;
case TreeObject.ROLE:
roles.addChild(obj);
break;
case TreeObject.ROUTING_RULE:
routingrules.addChild(obj);
break;
case TreeObject.STORED_PROCEDURE:
storeprocedures.addChild(obj);
break;
case TreeObject.TRANSFORMER:
transformers.addChild(obj);
break;
case TreeObject.PICTURES_RESOURCE:
pictures.addChild(obj);
break;
case TreeObject.WORKFLOW_PROCESS:
workflow.addChild(obj);
break;
case TreeObject.VIEW:
views.addChild(obj);
break;
default:
if (obj.getItems() != null && obj.getItems().length > 0) {
for (int i = 0; i < obj.getItems().length; i++) {
if (obj.getItems()[i].split(Messages.ImportItemsWizard_10)[1] != null) {
dataClusterContent.put(obj.getItems()[i].split(Messages.ImportItemsWizard_11)[1], obj.getItems());
}
}
}
}
// update monitor
if (interval == 1) {
monitor.worked(step);
} else {
if (tmp >= interval) {
monitor.worked(step);
tmp = 1;
} else {
tmp++;
}
}
}
Display.getDefault().syncExec(new Runnable() {
public void run() {
treeViewer.setRoot(reserverRoot);
treeViewer.getViewer().setInput(null);
treeViewer.setCheckItems(Arrays.asList(exports.getItems()));
GridData gd = (GridData) treeViewer.getViewer().getControl().getLayoutData();
gd.heightHint = 300;
treeViewer.getViewer().getControl().getParent().layout(true);
treeViewer.getViewer().getControl().getShell().layout(true);
try {
Object[] checkNodes = treeViewer.getCheckNodes();
if (checkNodes != null) {
LocalTreeObjectRepository.getInstance().setOriginalXobjectsToImport((TreeObject[]) checkNodes);
}
} catch (Exception e) {
}
}
});
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (Exception e) {
}
monitor.done();
}
}
use of com.amalto.workbench.webservices.WSAutoIncrement in project tmdm-studio-se by Talend.
the class ExportItemsWizard method doexport.
public void doexport(Object[] selectedObjs, IProgressMonitor monitor) {
TreeObject[] objs = null;
if (selectedObjs.length > 0 && selectedObjs[0] instanceof TreeObject) {
objs = Arrays.asList(selectedObjs).toArray(new TreeObject[0]);
}
if (objs == null || objs.length == 0) {
return;
}
monitor.beginTask(Messages.ExportItemsWizard_Export, IProgressMonitor.UNKNOWN);
Exports eps = new Exports();
List<TreeObject> exports = new ArrayList<TreeObject>();
TMDMService service;
try {
service = Util.getMDMService(objs[0]);
try {
LocalTreeObjectRepository.getInstance().parseElementForOutput(objs);
} catch (Exception e) {
}
for (TreeObject obj : objs) {
StringWriter sw;
ArrayList<String> items;
String encodedID = null;
switch(obj.getType()) {
case TreeObject.DATA_CLUSTER:
monitor.subTask(Messages.ExportItemsWizard_2);
items = new ArrayList<String>();
// dataclusters
WSDataClusterPK pk = (WSDataClusterPK) obj.getWsKey();
try {
WSDataCluster cluster = service.getDataCluster(new WSGetDataCluster(pk));
// Marshal
sw = new StringWriter();
Marshaller.marshal(cluster, sw);
// $NON-NLS-1$
encodedID = URLEncoder.encode(cluster.getName(), "UTF-8");
// $NON-NLS-1$
writeString(sw.toString(), TreeObject.DATACONTAINER + "/" + encodedID);
// $NON-NLS-1$
items.add(TreeObject.DATACONTAINER + "/" + encodedID);
obj.setItems(items.toArray(new String[items.size()]));
exports.add(obj);
} catch (Exception e) {
}
monitor.worked(1);
// datacluster contents
monitor.subTask(Messages.bind(Messages.ExportItemsWizard_3, pk.getPk()));
exportCluster(exports, pk, service);
monitor.worked(1);
break;
case TreeObject.DATA_MODEL:
monitor.subTask(Messages.ExportItemsWizard_5);
items = new ArrayList<String>();
// datamodels
try {
WSDataModel model = service.getDataModel(new WSGetDataModel((WSDataModelPK) obj.getWsKey()));
sw = new StringWriter();
Marshaller.marshal(model, sw);
// $NON-NLS-1$
encodedID = URLEncoder.encode(model.getName(), "UTF-8");
// $NON-NLS-1$
writeString(sw.toString(), TreeObject.DATAMODEL_ + "/" + encodedID);
// $NON-NLS-1$
items.add(TreeObject.DATAMODEL_ + "/" + encodedID);
obj.setItems(items.toArray(new String[items.size()]));
exports.add(obj);
} catch (Exception e) {
}
monitor.worked(1);
break;
case TreeObject.MENU:
monitor.subTask(Messages.ExportItemsWizard_6);
// ExportItem exportItem=new ExportItem();
items = new ArrayList<String>();
// menu
try {
WSMenu menu = service.getMenu(new WSGetMenu((WSMenuPK) obj.getWsKey()));
// Marshal
sw = new StringWriter();
Marshaller.marshal(menu, sw);
// $NON-NLS-1$
encodedID = URLEncoder.encode(menu.getName(), "UTF-8");
// $NON-NLS-1$
writeString(sw.toString(), TreeObject.MENU_ + "/" + encodedID);
// $NON-NLS-1$
items.add(TreeObject.MENU_ + "/" + encodedID);
obj.setItems(items.toArray(new String[items.size()]));
exports.add(obj);
} catch (Exception e) {
}
monitor.worked(1);
break;
case TreeObject.PICTURES_RESOURCE:
monitor.subTask(Messages.ExportItemsWizard_7);
// ExportItem exportItem=new ExportItem();
items = new ArrayList<String>();
// picture
try {
String endpointIpAddress = obj.getEndpointIpAddress();
// $NON-NLS-1$
int index = endpointIpAddress.indexOf("/services/soap");
if (index != -1) {
endpointIpAddress = endpointIpAddress.substring(0, index);
}
String picUrl = endpointIpAddress + ResourcesUtil.getResourcesMapFromURI(endpointIpAddress + TreeObject.PICTURES_URI, objs[0]).get(obj.getDisplayName());
// Marshal
sw = new StringWriter();
byte[] content = HttpClientUtil.getByteArrayContentByHttpget(picUrl);
Marshaller.marshal(content, sw);
// $NON-NLS-1$
encodedID = URLEncoder.encode(obj.getDisplayName(), "UTF-8");
// $NON-NLS-1$
writeInputStream(new ByteArrayInputStream(content), TreeObject.PICTURES_ + "/" + encodedID);
// $NON-NLS-1$
items.add(TreeObject.PICTURES_ + "/" + encodedID);
obj.setItems(items.toArray(new String[items.size()]));
exports.add(obj);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
monitor.worked(1);
break;
case TreeObject.ROUTING_RULE:
monitor.subTask(Messages.ExportItemsWizard_10);
// ExportItem exportItem=new ExportItem();
items = new ArrayList<String>();
// routing rule
try {
WSRoutingRule RoutingRule = service.getRoutingRule(new WSGetRoutingRule((WSRoutingRulePK) obj.getWsKey()));
// Marshal
sw = new StringWriter();
Marshaller.marshal(RoutingRule, sw);
// $NON-NLS-1$
encodedID = URLEncoder.encode(RoutingRule.getName(), "UTF-8");
// $NON-NLS-1$
writeString(sw.toString(), TreeObject.ROUTINGRULE_ + "/" + encodedID);
// $NON-NLS-1$
items.add(TreeObject.ROUTINGRULE_ + "/" + encodedID);
obj.setItems(items.toArray(new String[items.size()]));
exports.add(obj);
} catch (Exception e) {
}
monitor.worked(1);
break;
case TreeObject.STORED_PROCEDURE:
monitor.subTask(Messages.ExportItemsWizard_11);
items = new ArrayList<String>();
// stored procedure
try {
WSStoredProcedure StoredProcedure = service.getStoredProcedure(new WSGetStoredProcedure((WSStoredProcedurePK) obj.getWsKey()));
// Marshal
sw = new StringWriter();
Marshaller.marshal(StoredProcedure, sw);
// $NON-NLS-1$
encodedID = URLEncoder.encode(StoredProcedure.getName(), "UTF-8");
// $NON-NLS-1$
writeString(sw.toString(), TreeObject.STOREDPROCEDURE_ + "/" + encodedID);
// $NON-NLS-1$
items.add(TreeObject.STOREDPROCEDURE_ + "/" + encodedID);
obj.setItems(items.toArray(new String[items.size()]));
exports.add(obj);
} catch (Exception e) {
}
monitor.worked(1);
break;
case TreeObject.TRANSFORMER:
monitor.subTask(Messages.ExportItemsWizard_13);
items = new ArrayList<String>();
// TODO:check the pk
try {
WSTransformerV2 transformer = service.getTransformerV2(new WSGetTransformerV2(new WSTransformerV2PK(((WSTransformerV2PK) obj.getWsKey()).getPk())));
// Marshal
sw = new StringWriter();
Marshaller.marshal(transformer, sw);
// $NON-NLS-1$
encodedID = URLEncoder.encode(transformer.getName(), "UTF-8");
// $NON-NLS-1$
writeString(sw.toString(), TreeObject.TRANSFORMER_ + "/" + encodedID);
// $NON-NLS-1$
items.add(TreeObject.TRANSFORMER_ + "/" + encodedID);
obj.setItems(items.toArray(new String[items.size()]));
exports.add(obj);
} catch (Exception e) {
}
monitor.worked(1);
break;
case TreeObject.VIEW:
monitor.subTask(Messages.ExportItemsWizard_15);
items = new ArrayList<String>();
// view
try {
WSView View = service.getView(new WSGetView((WSViewPK) obj.getWsKey()));
// Marshal
sw = new StringWriter();
Marshaller.marshal(View, sw);
// $NON-NLS-1$
encodedID = URLEncoder.encode(View.getName(), "UTF-8");
// $NON-NLS-1$
writeString(sw.toString(), TreeObject.VIEW_ + "/" + encodedID);
// $NON-NLS-1$
items.add(TreeObject.VIEW_ + "/" + encodedID);
obj.setItems(items.toArray(new String[items.size()]));
exports.add(obj);
} catch (Exception e) {
}
monitor.worked(1);
break;
default:
IExportItemsWizardAdapter exAdapter = ExAdapterManager.getAdapter(this, IExportItemsWizardAdapter.class);
if (exAdapter != null) {
exAdapter.doexport(service, obj.getType(), exports, obj, monitor);
}
break;
}
}
// store the content xml
eps.setItems(exports.toArray(new TreeObject[exports.size()]));
eps.setSchemas(LocalTreeObjectRepository.getInstance().outPutSchemas());
// export autoincrement
try {
WSAutoIncrement auto = service.getAutoIncrement(null);
if (auto != null && auto.getAutoincrement() != null) {
eps.setAutoIncrement(auto.getAutoincrement());
}
} catch (Exception e) {
}
StringWriter sw = new StringWriter();
try {
Marshaller.marshal(eps, sw);
// $NON-NLS-1$
writeString(sw.toString(), "exportitems.xml");
} catch (Exception e) {
}
monitor.done();
} catch (Exception e) {
}
}
Aggregations