/** * Returns the locale match list for a string given the language * * @param literal Code * @param codeLang Language * @return Service * @throws AWException Error retrieving locale matches */ public ServiceData getLocaleMatches(String literal, String codeLang) throws AWException { ServiceData serviceData = new ServiceData(); DataList data = findStringInFile(codeLang.toUpperCase(), literal); serviceData.setDataList(data); return serviceData; }
/** * Check file exists * * @param fileName File name * @return Check */ public ServiceData checkFile(String fileName) { ServiceData serviceData = new ServiceData(); String userHome = System.getProperty(USER_HOME); String selectsPath = userHome + SELECTS_PATH; String filePath = selectsPath + AweConstants.FILE_SEPARATOR + fileName + ".txt"; // Instantiate selects files path File folder = new File(selectsPath); // Check if path exists and create it if (!folder.exists()) { folder.mkdir(); } File file = new File(filePath); // Check if file already exists if (file.exists()) { serviceData.addVariable("MESSAGE_TYPE", AnswerType.ERROR.toString()); serviceData.addVariable("MESSAGE_TITLE", getLocale("WARNING_TITLE_DUPLICATED_FILE")); serviceData.addVariable("MESSAGE_DESCRIPTION", getLocale("WARNING_MESSAGE_DUPLICATED_FILE")); return serviceData; } serviceData.setType(AnswerType.OK); return serviceData; }
/** * Adds a client action to the list * * @param clientAction Client action to be added * @return this */ public ServiceData addClientAction(ClientAction clientAction) { this.getClientActionList().add(clientAction); return this; }
/** * Translate from one language to other * * @param text Text to translate * @param fromLanguage Source language * @param toLanguage Target language * @return Translation * @throws AWException Error translating text */ public ServiceData translate(String text, String fromLanguage, String toLanguage) throws AWException { ServiceData serDat = new ServiceData(); String result = getTranslation(text, fromLanguage, toLanguage); String[] arr = { result }; serDat.setData(arr); return serDat; }
/** * Delete columns from grid * * @return clientActionList */ public ServiceData deleteColumns() { // Variable initialization ServiceData serviceData = new ServiceData(); // Columns List<Column> columns = new ArrayList<>(); Column column = new Column(); column.setId("NONE"); columns.add(column); // Add columns to the multiselect grid ClientAction addColumnsGrid = new ClientAction("replace-columns"); addColumnsGrid.setTarget(SELECTED_GRID); addColumnsGrid.addParameter("columns", new CellData(columns)); serviceData.addClientAction(addColumnsGrid); return serviceData; }
ServiceData serviceData = new ServiceData(); serviceData.setTitle(getElements().getLocale("OK_TITLE_LOCAL_UPDATED")); serviceData.setMessage(getElements().getLocale("OK_MESSAGE_LOCAL_UPDATED", code)); serviceData.addClientAction(updateCell); serviceData.addClientAction(updateCell);
ServiceData serviceData = new ServiceData(); serviceData.setTitle(getElements().getLocale("OK_TITLE_NEW_LOCAL")); serviceData.setMessage(getElements().getLocale("OK_MESSAGE_NEW_LOCAL", code)); } else { serviceData.setTitle(getElements().getLocale("WARNING_TITLE_NEW_LOCAL")); serviceData.setMessage(getElements().getLocale("WARNING_MESSAGE_LOCAL_ALREADY_EXISTS", code)); serviceData.setType(AnswerType.WARNING);
/** * Updates user working directory * * @param path Path * @return Service data * @throws AWException Error setting path */ public ServiceData setPath(String path) throws AWException { ServiceData serviceData = new ServiceData(); // Update path updatePath(path); serviceData.setTitle(getElements().getLocale("CONFIRM_TITLE_UPDATE_WRK_DIR")) .setMessage(getElements().getLocale("CONFIRM_MESSAGE_UPDATE_WRK_DIR")); return serviceData; } }
/** * GoTo annotation on methods * * @param proceedingJoinPoint Join point * * @throws AWException Error on pointcut */ @Around ("com.almis.awe.annotation.aspect.GoToAnnotation.annotatedMethod()") public Object goToMethodProcessor(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); GoTo goToAnnotation = org.springframework.core.annotation.AnnotationUtils.getAnnotation(methodSignature.getMethod(), GoTo.class); Object result = proceedingJoinPoint.proceed(); if (result instanceof ServiceData) { if (!goToAnnotation.screenName().isEmpty()) { ServiceData resultObj = (ServiceData) result; ClientAction clientAction = generateClientAction(goToAnnotation); resultObj.addClientAction(clientAction); return resultObj; } } else if (result instanceof ClientAction && !goToAnnotation.screenName().isEmpty()) { return generateClientAction(goToAnnotation); } return result; }
/** * Save select file * * @param fileName File name * @param selects Select * @return Selected file * @throws AWException Error storing file */ public ServiceData saveSelectFile(String fileName, String selects) throws AWException { ServiceData serviceData = new ServiceData(); String userHome = System.getProperty(USER_HOME); String selectsPath = userHome + SELECTS_PATH; String filePath = selectsPath + AweConstants.FILE_SEPARATOR + fileName + ".txt"; // Instantiate selects files path File folder = new File(selectsPath); // Check if path exists and create it if (!folder.exists()) { folder.mkdir(); } // Whatever the file path is. File statText = new File(filePath); try (FileOutputStream is = new FileOutputStream(statText); OutputStreamWriter osw = new OutputStreamWriter(is)) { Writer w = new BufferedWriter(osw); w.write(selects); } catch (IOException exc) { throw new AWException(getLocale("ERROR_TITLE_WRITING_SELECTS"), getLocale("ERROR_MESSAGE_WRITING_SELECTS"), exc); } return serviceData; }
/** * Adds a variable to the map * * @param name Variable name * @param variable Variable value (as CellData) * @return this */ public ServiceData addVariable(String name, CellData variable) { this.getVariableMap().put(name, variable); return this; }
/** * Switch the languages * * @param fromLanguage Source language * @param toLanguage Target language * @param fromTarget Source target * @param toTarget Target target * @return Languages changed */ public ServiceData switchLanguages(String fromLanguage, String toLanguage, String fromTarget, String toTarget) { ServiceData serviceData = new ServiceData(); JsonNodeFactory factory = JsonNodeFactory.instance; ArrayNode from = factory.arrayNode(); ArrayNode to = factory.arrayNode(); // Add the values from.add(toLanguage); to.add(fromLanguage); // Select value action ClientAction fromAction = new ClientAction(SELECT); fromAction.addParameter(VALUES, new CellData(from)); fromAction.setTarget(fromTarget); // Select format action ClientAction toAction = new ClientAction(SELECT); toAction.addParameter(VALUES, new CellData(to)); toAction.setTarget(toTarget); // Add actions to list serviceData.addClientAction(fromAction); serviceData.addClientAction(toAction); return serviceData; }
/** * Delete literal * @param code Code * @return Deletion message * @throws AWException Error deleting locale */ public ServiceData deleteLiteral(String code) throws AWException { ServiceData serviceData = new ServiceData(); // Get existing locals Map<String, Map<String, String>> localeList = getElements().getLocales(); // * Iterate by language for (String codeLang : localeList.keySet()) { // Get language storeDeletedLocale(codeLang, code); } serviceData.setTitle(getElements().getLocale("OK_TITLE_REMOVED_LOCAL")); serviceData.setMessage(getElements().getLocale("OK_MESSAGE_REMOVED_LOCAL", code)); return serviceData; }
/** * Returns using language * @return Used language */ public ServiceData getUsingLanguage() { getLogger().log(LiteralsService.class, Level.INFO, "getUsingLanguage"); ServiceData serviceData = new ServiceData(); String codeLang = getElements().getProperty("var.glb.lan"); String[] labval = { "ENUM_LAN_" + codeLang, codeLang.toLowerCase() }; serviceData.setData(labval); return serviceData; }
return ((ServiceData) result).addClientAction(downloadAction); } else if (result instanceof ClientAction) { return downloadAction;
/** * Get variable from the map * * @param name Variable name * @return this */ public CellData getVariable(String name) { return getVariableMap().get(name); }
/** * Fill grid with data * * @param rsMetaData Metadata * @param datalist Datalist * @return Client actions * @throws AWException Error filling grid */ private ServiceData fillGrid(ResultSetMetaData rsMetaData, DataList datalist) throws AWException { // Variable initialization ServiceData serviceData = new ServiceData(); try { // Build column structure List<Column> columns = getColumnList(rsMetaData); // Add columns to the multiselect grid ClientAction addColumnsGrid = new ClientAction("replace-columns"); addColumnsGrid.setTarget(SELECTED_GRID); addColumnsGrid.addParameter("columns", new CellData(columns)); // Fill Grid ClientAction fillGrid = new ClientAction("fill"); fillGrid.setTarget(SELECTED_GRID); fillGrid.addParameter("datalist", datalist); // Set variables serviceData.addClientAction(addColumnsGrid); serviceData.addClientAction(fillGrid); } catch (AWException exc) { throw new AWException(getLocale("ERROR_TITLE_SESSION_EXPIRED"), getLocale("ERROR_MESSAGE_SESSION_EXPIRED"), exc); } return serviceData; }
/** * Get existing select files * * @return Selected file * @throws AWException Error retrieving file */ public ServiceData getSelectFile() throws AWException { ServiceData serviceData = new ServiceData(); String userHome = System.getProperty(USER_HOME); String selectsPath = userHome + SELECTS_PATH; List<String> keys = new ArrayList<>(); File folder = new File(selectsPath); if (!folder.exists()) { folder.mkdir(); } File[] listOfFiles = folder.listFiles(); for (File listOfFile : listOfFiles) { if (listOfFile.isFile()) { keys.add(listOfFile.getName()); } } builder.addColumn("label", keys, STRING); builder.addColumn("value", keys, STRING); serviceData.setDataList(builder.build()); return serviceData; }
/** * Adds a variable to the map * * @param name Variable name * @param value Variable value * @return this */ public ServiceData addVariable(String name, String value) { this.getVariableMap().put(name, new CellData(value)); return this; }
/** * Specific build that returns a service data with a screen client action. * * @return * * @throws AWException */ public ServiceData build() throws AWException { ServiceData serviceData = new ServiceData(); //Generate screen Screen screen = (Screen) build(new Screen()); //Override screen in cache aweElements.setScreen(screen); //Modify menu options with the new screen Menu menu = generateOptionMenu(screen); //Override menu in cache aweElements.setMenu(getMenuType(), menu); // Override menu in cache ClientAction clientAction = new ClientAction("screen"); clientAction.setTarget(screen.getId()); serviceData.addClientAction(clientAction); return serviceData; }