Search in sources :

Example 1 with WSPutItemWithReport

use of com.amalto.workbench.webservices.WSPutItemWithReport in project tmdm-studio-se by Talend.

the class NewItemHandler method createItemRecord.

public boolean createItemRecord(final TMDMService service, final Shell ashell, final WSDataClusterPK wsDataClusterPK, boolean isMaster) {
    if (service == null || wsDataClusterPK == null) {
        throw new IllegalArgumentException();
    }
    final Shell shell = ashell != null ? ashell : Display.getCurrent().getActiveShell();
    try {
        // $NON-NLS-1$
        String xml = "<NewItem><NewElement></NewElement></NewItem>";
        // $NON-NLS-1$
        WSDataModelPKArray dataModelPKs = service.getDataModelPKs(new WSRegexDataModelPKs("*"));
        List<WSDataModelPK> dmPKs = dataModelPKs.getWsDataModelPKs();
        List<String> dataModels = new ArrayList<String>();
        if (dmPKs != null) {
            for (WSDataModelPK pk : dmPKs) {
                if (!"XMLSCHEMA---".equals(pk.getPk())) {
                    // $NON-NLS-1$
                    dataModels.add(pk.getPk());
                }
            }
        }
        final DataContainerDOMViewDialog d = new DataContainerDOMViewDialog(shell, service, Util.parse(xml), dataModels, DOMViewDialog.SOURCE_VIEWER, null, isMaster);
        d.addListener(new Listener() {

            public void handleEvent(Event event) {
                if (event.button == DOMViewDialog.BUTTON_SAVE) {
                    // attempt to save
                    try {
                        WSPutItem putItem = new WSPutItem(false, wsDataClusterPK, // $NON-NLS-1$
                        "".equals(d.getDataModelName()) ? // $NON-NLS-1$
                        null : new WSDataModelPK(d.getDataModelName()), d.getXML());
                        // $NON-NLS-1$
                        WSPutItemWithReport item = new WSPutItemWithReport(d.isBeforeVerification(), "genericUI", putItem);
                        if (d.isTriggerProcess()) {
                            service.putItemWithReport(item);
                        } else {
                            service.putItem(putItem);
                        }
                        created = true;
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        MessageDialog.openError(shell, Messages.DataClusterBrowserMainPage_100, Messages.bind(Messages.DataClusterBrowserMainPage_101, Util.formatErrorMessage(e.getLocalizedMessage())));
                        return;
                    }
                }
                d.close();
            }
        });
        d.setBlockOnOpen(true);
        d.open();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        if (!Util.handleConnectionException(shell, e, null)) {
            MessageDialog.openError(shell, Messages._Error, Messages.bind(Messages.DataClusterBrowserMainPage_103, e.getLocalizedMessage()));
        }
    }
    return created;
}
Also used : Listener(org.eclipse.swt.widgets.Listener) WSPutItem(com.amalto.workbench.webservices.WSPutItem) ArrayList(java.util.ArrayList) Shell(org.eclipse.swt.widgets.Shell) DataContainerDOMViewDialog(com.amalto.workbench.dialogs.datacontainer.DataContainerDOMViewDialog) WSDataModelPKArray(com.amalto.workbench.webservices.WSDataModelPKArray) WSRegexDataModelPKs(com.amalto.workbench.webservices.WSRegexDataModelPKs) Event(org.eclipse.swt.widgets.Event) WSPutItemWithReport(com.amalto.workbench.webservices.WSPutItemWithReport) WSDataModelPK(com.amalto.workbench.webservices.WSDataModelPK)

Aggregations

DataContainerDOMViewDialog (com.amalto.workbench.dialogs.datacontainer.DataContainerDOMViewDialog)1 WSDataModelPK (com.amalto.workbench.webservices.WSDataModelPK)1 WSDataModelPKArray (com.amalto.workbench.webservices.WSDataModelPKArray)1 WSPutItem (com.amalto.workbench.webservices.WSPutItem)1 WSPutItemWithReport (com.amalto.workbench.webservices.WSPutItemWithReport)1 WSRegexDataModelPKs (com.amalto.workbench.webservices.WSRegexDataModelPKs)1 ArrayList (java.util.ArrayList)1 Event (org.eclipse.swt.widgets.Event)1 Listener (org.eclipse.swt.widgets.Listener)1 Shell (org.eclipse.swt.widgets.Shell)1