private JSONObject storeTaskFormInRepository( String formType, String taskName, String packageName, String formValue, Repository repository) throws Exception { repository.deleteAssetFromPath( packageName + "/" + taskName + TASKFORM_NAME_EXTENSION + "." + formType); AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Byte); builder .location(packageName) .name(taskName + TASKFORM_NAME_EXTENSION) .type(formType) .content(formValue.getBytes("UTF-8")); repository.createAsset(builder.getAsset()); Asset newFormAsset = repository.loadAssetFromPath( packageName + "/" + taskName + TASKFORM_NAME_EXTENSION + "." + formType); String uniqueId = newFormAsset.getUniqueId(); if (Base64Backport.isBase64(uniqueId)) { byte[] decoded = Base64.decodeBase64(uniqueId); try { uniqueId = new String(decoded, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } JSONObject retObj = new JSONObject(); retObj.put("formid", uniqueId); return retObj; }
private String getCustomEditorsJSON( IDiagramProfile profile, ServletContext servletContext, String uuid) { String retStr = ""; Repository repository = profile.getRepository(); try { Asset<String> customEditorAsset = repository.loadAssetFromPath( profile.getRepositoryGlobalDir(uuid) + "/" + CUSTOMEDITORS_NAME + ".json"); retStr = customEditorAsset.getAssetContent(); } catch (Exception e) { _logger.error("Error retriving custom editors info: " + e.getMessage()); } return retStr; }
private String getTaskFormFromRepository( String formType, String taskName, String packageName, Repository repository) { try { Asset<String> formAsset = repository.loadAssetFromPath( packageName + "/" + taskName + TASKFORM_NAME_EXTENSION + "." + formType); if (formType.equals(FORMMODELER_FILE_EXTENSION)) { String uniqueId = formAsset.getUniqueId(); if (Base64Backport.isBase64(uniqueId)) { byte[] decoded = Base64.decodeBase64(uniqueId); try { uniqueId = new String(decoded, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return formAsset.getName() + "." + formAsset.getAssetType() + "|" + uniqueId; } else { return formAsset.getAssetContent(); } } catch (NoSuchFileException anfe) { try { String formValue = ""; if (formType.equals(FORMMODELER_FILE_EXTENSION)) { formValue = formModelerService.buildEmptyFormXML( taskName + TASKFORM_NAME_EXTENSION + "." + formType); } AssetBuilder builder = AssetBuilderFactory.getAssetBuilder(Asset.AssetType.Byte); builder .location(packageName) .name(taskName + TASKFORM_NAME_EXTENSION) .type(formType) .content(formValue.getBytes("UTF-8")); repository.createAsset(builder.getAsset()); Asset<String> newFormAsset = repository.loadAssetFromPath( packageName + "/" + taskName + TASKFORM_NAME_EXTENSION + "." + formType); String uniqueId = newFormAsset.getUniqueId(); if (Base64Backport.isBase64(uniqueId)) { byte[] decoded = Base64.decodeBase64(uniqueId); try { uniqueId = new String(decoded, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } if (formType.equals(FORMMODELER_FILE_EXTENSION)) { return newFormAsset.getName() + "." + newFormAsset.getAssetType() + "|" + uniqueId; } else { return formValue; } } catch (Exception e) { e.printStackTrace(); _logger.error(e.getMessage()); } } return "false"; }