Search in sources :

Example 1 with TranslationException

use of com.centurylink.mdw.common.exception.TranslationException in project mdw-designer by CenturyLinkCloud.

the class DesignerProxy method getVariableInfo.

/**
 * Must be called from the UI thread.
 */
public VariableTypeVO getVariableInfo(final VariableInstanceInfo varInstInfo) {
    String varType = varInstInfo.getType();
    VariableTranslator varTrans = getVariableTranslator(varType);
    final VariableTypeVO varTypeVO = new VariableTypeVO(0L, varType, varTrans == null ? null : varTrans.getClass().getName());
    if (varInstInfo.getStringValue() != null && varTypeVO.isJavaObjectType()) {
        BusyIndicator.showWhile(MdwPlugin.getShell().getDisplay(), new Runnable() {

            public void run() {
                DocumentReference docRef = new DocumentReference(varInstInfo.getStringValue());
                try {
                    Object obj = new JavaObjectTranslator().realToObject(getDocument(docRef).getContent());
                    varTypeVO.setVariableType(obj.getClass().getName());
                    varTypeVO.setUpdateable(obj instanceof SelfSerializable);
                } catch (TranslationException ex) {
                    if (MdwPlugin.getSettings().isLogConnectErrors())
                        PluginMessages.log(ex);
                    try {
                        if (!project.checkRequiredVersion(6, 1, 1)) {
                            String path = "DocumentValue?format=xml&id=" + docRef.getDocumentId() + "&type=" + varTypeVO.getVariableType();
                            String resp = getRestfulServer().invokeResourceService(path);
                            Resource res = Resource.Factory.parse(resp, Compatibility.namespaceOptions());
                            for (Parameter param : res.getParameterList()) {
                                if ("className".equals(param.getName()))
                                    varTypeVO.setVariableType(param.getStringValue());
                                else if ("isUpdateable".equals(param.getName()))
                                    varTypeVO.setUpdateable(Boolean.parseBoolean(param.getStringValue()));
                            }
                        }
                    } catch (Exception ex2) {
                        throw new RuntimeException(ex2.getMessage(), ex2);
                    }
                }
            }
        });
    }
    return varTypeVO;
}
Also used : JavaObjectTranslator(com.centurylink.mdw.common.translator.impl.JavaObjectTranslator) Resource(com.centurylink.mdw.service.Resource) VariableTranslator(com.centurylink.mdw.common.translator.VariableTranslator) TranslationException(com.centurylink.mdw.common.exception.TranslationException) JSONException(org.json.JSONException) TranslationException(com.centurylink.mdw.common.exception.TranslationException) AuthenticationException(com.centurylink.mdw.auth.AuthenticationException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) ValidationException(com.centurylink.mdw.designer.utils.ValidationException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) ZipException(java.util.zip.ZipException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) VariableTypeVO(com.centurylink.mdw.model.value.variable.VariableTypeVO) SelfSerializable(com.centurylink.mdw.common.translator.SelfSerializable) Parameter(com.centurylink.mdw.service.Parameter) JSONObject(org.json.JSONObject) DocumentReference(com.centurylink.mdw.model.value.variable.DocumentReference)

Example 2 with TranslationException

use of com.centurylink.mdw.common.exception.TranslationException in project mdw-designer by CenturyLinkCloud.

the class DesignerProxy method getVariableValue.

/**
 * Must be called from the UI thread.
 */
public String getVariableValue(final Shell shell, final VariableInstanceInfo varInstInfo, final boolean tryServer) {
    final StringBuilder valueHolder = new StringBuilder();
    BusyIndicator.showWhile(shell.getDisplay(), new Runnable() {

        public void run() {
            String value = varInstInfo.getStringValue();
            if (value != null) {
                boolean isDoc = isDocumentVariable(varInstInfo.getType(), value);
                if (isDoc) {
                    DocumentReference docRef = new DocumentReference(value);
                    DocumentVO docVo = getDocument(docRef);
                    if (docVo != null) {
                        value = docVo.getContent();
                        boolean isJavaObj = Object.class.getName().equals(varInstInfo.getType());
                        if (isJavaObj) {
                            try {
                                value = new JavaObjectTranslator().realToObject(value).toString();
                            } catch (TranslationException ex) {
                                if (MdwPlugin.getSettings().isLogConnectErrors())
                                    PluginMessages.log(ex);
                                if (tryServer) {
                                    try {
                                        String path = "DocumentValues/" + docRef.getDocumentId();
                                        if (!project.checkRequiredVersion(6, 1, 1))
                                            path = "DocumentValue?id=" + docRef.getDocumentId() + "&type=" + varInstInfo.getType() + "&format=text";
                                        value = getRestfulServer().invokeResourceService(path);
                                    } catch (Exception ex2) {
                                        throw new RuntimeException(ex2.getMessage(), ex2);
                                    }
                                } else {
                                    value = "<Double-click to retrieve>";
                                }
                            }
                        }
                    }
                }
                valueHolder.append(value);
            }
        }
    });
    return valueHolder.toString();
}
Also used : JavaObjectTranslator(com.centurylink.mdw.common.translator.impl.JavaObjectTranslator) DocumentVO(com.centurylink.mdw.model.value.variable.DocumentVO) TranslationException(com.centurylink.mdw.common.exception.TranslationException) DocumentReference(com.centurylink.mdw.model.value.variable.DocumentReference) JSONException(org.json.JSONException) TranslationException(com.centurylink.mdw.common.exception.TranslationException) AuthenticationException(com.centurylink.mdw.auth.AuthenticationException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) ValidationException(com.centurylink.mdw.designer.utils.ValidationException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) ZipException(java.util.zip.ZipException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException)

Aggregations

AuthenticationException (com.centurylink.mdw.auth.AuthenticationException)2 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)2 TranslationException (com.centurylink.mdw.common.exception.TranslationException)2 JavaObjectTranslator (com.centurylink.mdw.common.translator.impl.JavaObjectTranslator)2 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)2 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)2 DocumentReference (com.centurylink.mdw.model.value.variable.DocumentReference)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 RemoteException (java.rmi.RemoteException)2 ZipException (java.util.zip.ZipException)2 XmlException (org.apache.xmlbeans.XmlException)2 JSONException (org.json.JSONException)2 SelfSerializable (com.centurylink.mdw.common.translator.SelfSerializable)1 VariableTranslator (com.centurylink.mdw.common.translator.VariableTranslator)1 DocumentVO (com.centurylink.mdw.model.value.variable.DocumentVO)1 VariableTypeVO (com.centurylink.mdw.model.value.variable.VariableTypeVO)1 Parameter (com.centurylink.mdw.service.Parameter)1 Resource (com.centurylink.mdw.service.Resource)1 JSONObject (org.json.JSONObject)1