Added: ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonEvents.java?rev=1862206&view=auto ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonEvents.java (added) +++ ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonEvents.java Thu Jun 27 11:49:22 2019 @@ -0,0 +1,159 @@ +package org.apache.ofbiz.webtools; + +import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.GeneralException; +import org.apache.ofbiz.entity.Delegator; +import org.apache.ofbiz.entity.GenericEntityException; +import org.apache.ofbiz.entity.GenericValue; +import org.apache.ofbiz.entity.condition.EntityExpr; +import org.apache.ofbiz.entity.model.ModelEntity; +import org.apache.ofbiz.entity.model.ModelReader; +import org.apache.ofbiz.entity.transaction.TransactionUtil; +import org.apache.ofbiz.entity.util.EntityListIterator; +import org.apache.ofbiz.security.Security; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.Collection; +import java.util.Iterator; +import java.util.TreeSet; + +public class EntityJsonEvents { + + public static final String module = EntityJsonEvents.class.getName(); + public static final String err_resource = "WebtoolsErrorUiLabels"; + + public static String downloadJsonData(HttpServletRequest request, HttpServletResponse response) { + HttpSession session = request.getSession(); + ServletContext application = session.getServletContext(); + Delegator delegator = (Delegator) request.getAttribute("delegator"); + GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); + Security security = (Security) request.getAttribute("security"); + boolean isFirst = true; + if (security.hasPermission("ENTITY_MAINT", session)) { + TreeSet passedEntityNames = (TreeSet) session.getAttribute("jsonrawdump_entitylist"); + session.removeAttribute("jsonrawdump_entitylist"); + EntityExpr entityDateCond = (EntityExpr) session.getAttribute("entityDateCond"); + session.removeAttribute("entityDateCond"); + try { + if (passedEntityNames != null) { + + ModelReader reader = delegator.getModelReader(); + Collection ec = reader.getEntityNames(); + TreeSet entityNames = new TreeSet(ec); + + long numberWritten = 0; + byte[] outputByte = new byte[4096]; + + response.setContentType("text/plain;charset=UTF-8"); + response.setHeader("Content-Disposition", "attachment; filename=DownloadEntityData.json"); + + if (passedEntityNames.size() > 0) { + StringBuilder textBuilder = new StringBuilder(); + textBuilder.append("["); + + boolean beganTransaction = false; + try { + beganTransaction = TransactionUtil.begin(); + + Iterator i = passedEntityNames.iterator(); + while (i.hasNext()) { + String curEntityName = (String) i.next(); + + ModelEntity me = reader.getModelEntity(curEntityName); + EntityListIterator values = null; + if (me.getNoAutoStamp() == true) { + values = delegator.find(curEntityName, null, null, null, null, null); + } else { + values = delegator.find(curEntityName, entityDateCond, null, null, null, null); + } + + GenericValue value = null; + if(!isFirst) { + textBuilder.append(','); + } + textBuilder.append('{'); + textBuilder.append("\""); + textBuilder.append(curEntityName); + textBuilder.append("\""); + textBuilder.append(":"); + textBuilder.append("\n\t"); + textBuilder.append("["); + int numberOfValues = 0; + while ((value = (GenericValue) values.next()) != null) { + EntityJsonHelper.writeJsonText(textBuilder, value); + numberWritten++; + numberOfValues++; + if (numberOfValues < values.getResultsSizeAfterPartialList()) { + textBuilder.append(","); + } + textBuilder.append("\n\t"); + } + textBuilder.append("]"); + textBuilder.append("\n"); + textBuilder.append("}"); + values.close(); + isFirst = false; + } + //TransactionUtil.commit(beganTransaction); + } catch (GenericEntityException e) { + String errMsg = "Failure in operation, rolling back transaction"; + Debug.logError(e, errMsg, module); + try { + // only rollback the transaction if we started one... + TransactionUtil.rollback(beganTransaction, errMsg, e); + } catch (GenericEntityException e2) { + Debug.logError(e2, "Could not rollback transaction: " + e2.toString(), module); + } + // after rolling back, rethrow the exception + //throw e; + return "error"; + } finally { + // only commit the transaction if we started one... this will throw an exception if it fails + if (beganTransaction) { + try { + TransactionUtil.commit(beganTransaction); + } catch (GenericEntityException e2) { + Debug.logError(e2, "Could not commit transaction: " + e2.toString(), module); + request.setAttribute("_ERROR_MESSAGE_", "Could not commit transaction: " + e2.toString()); + return "error"; + } + } + } + + textBuilder.append("]"); + String text = textBuilder.toString(); + PrintWriter writer = response.getWriter(); + writer.write(text); + writer.flush(); + writer.close(); + } + } else { + String errMsg = "No entityName list was found in the session, go back to the export page and try again."; + request.setAttribute("_ERROR_MESSAGE_", errMsg); + return "error"; + } + } catch (GeneralException e) { + String errMsg = "Error downloading json data: " + e.toString(); + Debug.logError(e, errMsg, module); + request.setAttribute("_ERROR_MESSAGE_", errMsg); + return "error"; + } catch (IOException e) { + String errMsg = "Error downloading json data : " + e.toString(); + Debug.logError(e, errMsg, module); + request.setAttribute("_ERROR_MESSAGE_", errMsg); + return "error"; + } + } else { + String errMsg = "You do not have permission to use this page (ENTITY_MAINT needed)"; + request.setAttribute("_ERROR_MESSAGE_", errMsg); + return "error"; + } + return "success"; + } +} Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonEvents.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonEvents.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonEvents.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonHelper.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonHelper.java?rev=1862206&view=auto ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonHelper.java (added) +++ ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonHelper.java Thu Jun 27 11:49:22 2019 @@ -0,0 +1,198 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ofbiz.webtools; + +import org.apache.ofbiz.base.util.Base64; +import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.UtilIO; +import org.apache.ofbiz.base.util.UtilValidate; +import org.apache.ofbiz.entity.GenericEntity; +import org.apache.ofbiz.entity.GenericValue; +import org.apache.ofbiz.entity.model.ModelField; + +import java.io.PrintWriter; +import java.text.StringCharacterIterator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +public class EntityJsonHelper { + + public static final String module = EntityJsonHelper.class.getName(); + + /** + * Writes JSON text for each field of the entity + * @param writer A PrintWriter to write to + */ + public static void writeJsonText(PrintWriter writer, GenericValue value) { + Map<String, String> fieldMap = new HashMap<>(); + + Iterator<ModelField> modelFields = value.getModelEntity().getFieldsIterator(); + while (modelFields.hasNext()) { + ModelField modelField = modelFields.next(); + String name = modelField.getName(); + + String type = modelField.getType(); + if (type != null && "blob".equals(type)) { + Object obj = value.get(name); + boolean b1 = obj instanceof byte[]; + if (b1) { + byte[] binData = (byte[]) obj; + String strData = new String(Base64.base64Encode(binData), UtilIO.getUtf8()); + if (UtilValidate.isNotEmpty(strData)) { + fieldMap.put(name, strData); + } + } else { + Debug.logWarning("Field:" + name + " is not of type 'byte[]'. obj: " + obj, module); + } + } else { + String valueStr = value.getString(name); + if (UtilValidate.isNotEmpty(valueStr)) { + valueStr = escapeJson(valueStr); + fieldMap.put(name, valueStr); + } + } + } + writer.println('{'); + if (fieldMap.size() != 0) { + int index = 0; + for (Map.Entry<String, String> fieldEntry : fieldMap.entrySet()) { + ++index; + writer.print("\""); + writer.print(fieldEntry.getKey()); + writer.print("\""); + writer.print(":"); + writer.print("\""); + writer.print(fieldEntry.getValue()); + writer.print("\""); + if (index < fieldMap.size()) { + writer.print(","); + } + } + } + writer.print("}"); + } + + /** + * Writes JSON text for each field of the entity + * @param textBuilder A StringBuilder to write to entity to be writter + */ + public static void writeJsonText(StringBuilder textBuilder, GenericValue value) { + Map<String, String> fieldMap = new HashMap<>(); + + Iterator<ModelField> modelFields = value.getModelEntity().getFieldsIterator(); + while (modelFields.hasNext()) { + ModelField modelField = modelFields.next(); + String name = modelField.getName(); + + String type = modelField.getType(); + if (type != null && "blob".equals(type)) { + Object obj = value.get(name); + boolean b1 = obj instanceof byte[]; + if (b1) { + byte[] binData = (byte[]) obj; + String strData = new String(Base64.base64Encode(binData), UtilIO.getUtf8()); + if (UtilValidate.isNotEmpty(strData)) { + fieldMap.put(name, strData); + } + } else { + Debug.logWarning("Field:" + name + " is not of type 'byte[]'. obj: " + obj, module); + } + } else { + String valueStr = value.getString(name); + if (UtilValidate.isNotEmpty(valueStr)) { + valueStr = escapeJson(valueStr); + fieldMap.put(name, valueStr); + } + } + } + textBuilder.append('{'); + if (fieldMap.size() != 0) { + int index = 0; + for (Map.Entry<String, String> fieldEntry : fieldMap.entrySet()) { + ++index; + textBuilder.append("\""); + textBuilder.append(fieldEntry.getKey()); + textBuilder.append("\""); + textBuilder.append(":"); + textBuilder.append("\""); + textBuilder.append(fieldEntry.getValue()); + textBuilder.append("\""); + if (index < fieldMap.size()) { + textBuilder.append(","); + } + } + } + textBuilder.append("}"); + } + + public static String escapeJson(String aText) { + if (UtilValidate.isEmpty(aText)) { + return aText; + } + String result = aText.replace("\"", """); + result = org.apache.commons.text.StringEscapeUtils.escapeJson(aText); + + /*String result = new String(); + StringCharacterIterator iterator = new StringCharacterIterator(aText); + char character = iterator.current(); + while (character != StringCharacterIterator.DONE) { + switch (character) { + case '\\': + result = result + "\\\\"; + character = iterator.next(); + break; + case '/': + result = result + "\\\\/"; + character = iterator.next(); + break; + case 0x8: //backspace, \b + result = result + "\\\\b"; + character = iterator.next(); + break; + case 0xC: // form feed, \f + result = result + "\\\\f"; + character = iterator.next(); + break; + case 0xA: // newline, \n + result = result + "\\\\n"; + character = iterator.next(); + break; + case 0xD: // carriage return, \r + result = result + "\\\\r"; + character = iterator.next(); + break; + case 0x9:// tab, \t + result = result + "\\\\t"; + character = iterator.next(); + break; + case '"': + //result = result + "\\\""; + result = result + """; + character = iterator.next(); + break; + default: + result = result + character; + character = iterator.next(); + break; + } + }*/ + return result.toString(); + } +} Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonHelper.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonHelper.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/EntityJsonHelper.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java?rev=1862206&r1=1862205&r2=1862206&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/WebToolsServices.java Thu Jun 27 11:49:22 2019 @@ -80,6 +80,7 @@ import org.apache.ofbiz.entity.transacti import org.apache.ofbiz.entity.transaction.TransactionUtil; import org.apache.ofbiz.entity.util.EntityDataAssert; import org.apache.ofbiz.entity.util.EntityDataLoader; +import org.apache.ofbiz.entity.util.EntityJsonReader; import org.apache.ofbiz.entity.util.EntityListIterator; import org.apache.ofbiz.entity.util.EntityQuery; import org.apache.ofbiz.entity.util.EntitySaxReader; @@ -312,6 +313,226 @@ public class WebToolsServices { return resp; } + /** + * + * @param dctx + * @param context + * @return + */ + public static Map<String, Object> entityImportJson(DispatchContext dctx, Map<String, ? extends Object> context) { + GenericValue userLogin = (GenericValue) context.get("userLogin"); + LocalDispatcher dispatcher = dctx.getDispatcher(); + Locale locale = (Locale) context.get("locale"); + List<String> messages = new LinkedList<>(); + + String filename = (String)context.get("filename"); + String fmfilename = (String)context.get("fmfilename"); + String fulltext = (String)context.get("fulltext"); + boolean isUrl = (String)context.get("isUrl") != null; + String onlyInserts = (String)context.get("onlyInserts"); + String maintainTimeStamps = (String)context.get("maintainTimeStamps"); + String createDummyFks = (String)context.get("createDummyFks"); + String checkDataOnly = (String) context.get("checkDataOnly"); + Map<String, Object> placeholderValues = UtilGenerics.checkMap(context.get("placeholderValues")); + + Integer txTimeout = (Integer)context.get("txTimeout"); + if (txTimeout == null) { + txTimeout = 7200; + } + URL url = null; + + // ############################# + // The filename to parse is prepared + // ############################# + if (UtilValidate.isNotEmpty(filename)) { + try { + url = isUrl?FlexibleLocation.resolveLocation(filename):UtilURL.fromFilename(filename); + } catch (MalformedURLException mue) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "WebtoolsInvalidFileName", UtilMisc.toMap("filename", filename, "errorString", mue.getMessage()), locale)); + } catch (Exception exc) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "WebtoolsErrorReadingFileName", UtilMisc.toMap("filename", filename, "errorString", exc.getMessage()), locale)); + } + } + + // ############################# + // FM Template + // ############################# + if (UtilValidate.isNotEmpty(fmfilename) && (UtilValidate.isNotEmpty(fulltext) || url != null)) { + File fmFile = new File(fmfilename); + if (!fmFile.exists()) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "WebtoolsErrorReadingTemplateFile", UtilMisc.toMap("filename", fmfilename, "errorString", "Template file not found."), locale)); + } + try { + DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + InputSource ins = url != null ? new InputSource(url.openStream()) : new InputSource(new StringReader(fulltext)); + Document doc; + try { + doc = documentBuilder.parse(ins); + } finally { + if (ins.getByteStream() != null) { + ins.getByteStream().close(); + } + if (ins.getCharacterStream() != null) { + ins.getCharacterStream().close(); + } + } + StringWriter outWriter = new StringWriter(); + Map<String, Object> fmcontext = new HashMap<>(); + fmcontext.put("doc", doc); + FreeMarkerWorker.renderTemplate(fmFile.toURI().toURL().toString(), fmcontext, outWriter); + fulltext = outWriter.toString(); + } catch (Exception ex) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "WebtoolsErrorProcessingTemplateFile", UtilMisc.toMap("filename", fmfilename, "errorString", ex.getMessage()), locale)); + } + } + + // ############################# + // The parsing takes place + // ############################# + if (fulltext != null || url != null) { + try { + Map<String, Object> inputMap = UtilMisc.toMap("onlyInserts", onlyInserts, + "createDummyFks", createDummyFks, + "checkDataOnly", checkDataOnly, + "maintainTimeStamps", maintainTimeStamps, + "txTimeout", txTimeout, + "placeholderValues", placeholderValues, + "userLogin", userLogin); + if (fulltext != null) { + inputMap.put("xmltext", fulltext); + } else { + inputMap.put("url", url); + } + Map<String, Object> outputMap = dispatcher.runSync("parseEntityJsonFile", inputMap); + if (ServiceUtil.isError(outputMap)) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "WebtoolsErrorParsingFile", UtilMisc.toMap("errorString", ServiceUtil.getErrorMessage(outputMap)), locale)); + } else { + Long numberRead = (Long)outputMap.get("rowProcessed"); + messages.add(UtilProperties.getMessage(resource, "EntityImportRowProcessed", UtilMisc.toMap("numberRead", numberRead.toString()), locale)); + } + } catch (GenericServiceException gsex) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EntityImportJsonParsingError", UtilMisc.toMap("errorString", gsex.getMessage()), locale)); + } catch (Exception ex) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EntityImportJsonParsingError", UtilMisc.toMap("errorString", ex.getMessage()), locale)); + } + } else { + messages.add(UtilProperties.getMessage(resource, "EntityImportNoJsonFileSpecified", locale)); + } + + // send the notification + Map<String, Object> resp = UtilMisc.toMap("messages", (Object) messages); + return resp; + } + + /** + * + * @param dctx + * @param context + * @return + */ + public static Map<String, Object> entityImportDirJson(DispatchContext dctx, Map<String, ? extends Object> context) { + GenericValue userLogin = (GenericValue) context.get("userLogin"); + LocalDispatcher dispatcher = dctx.getDispatcher(); + Locale locale = (Locale) context.get("locale"); + List<String> messages = new LinkedList<>(); + + String path = (String) context.get("path"); + String onlyInserts = (String) context.get("onlyInserts"); + String maintainTimeStamps = (String) context.get("maintainTimeStamps"); + String createDummyFks = (String) context.get("createDummyFks"); + boolean deleteFiles = (String) context.get("deleteFiles") != null; + String checkDataOnly = (String) context.get("checkDataOnly"); + Map<String, Object> placeholderValues = UtilGenerics.checkMap(context.get("placeholderValues")); + + Integer txTimeout = (Integer)context.get("txTimeout"); + Long filePause = (Long)context.get("filePause"); + + if (txTimeout == null) { + txTimeout = 7200; + } + if (filePause == null) { + filePause = 0L; + } + + if (UtilValidate.isNotEmpty(path)) { + long pauseLong = filePause; + File baseDir = new File(path); + + if (baseDir.isDirectory() && baseDir.canRead()) { + File[] fileArray = baseDir.listFiles(); + List<File> files = new LinkedList<>(); + for (File file: fileArray) { + if (file.getName().toUpperCase().endsWith("JSON")) { + files.add(file); + } + } + + int passes=0; + int initialListSize = files.size(); + int lastUnprocessedFilesCount = 0; + List<File> unprocessedFiles = new LinkedList<>(); + while (files.size()>0 && + files.size() != lastUnprocessedFilesCount) { + lastUnprocessedFilesCount = files.size(); + unprocessedFiles = new LinkedList<>(); + for (File f: files) { + Map<String, Object> parseEntityXmlFileArgs = UtilMisc.toMap("onlyInserts", onlyInserts, + "createDummyFks", createDummyFks, + "checkDataOnly", checkDataOnly, + "maintainTimeStamps", maintainTimeStamps, + "txTimeout", txTimeout, + "placeholderValues", placeholderValues, + "userLogin", userLogin); + + try { + URL furl = f.toURI().toURL(); + parseEntityXmlFileArgs.put("url", furl); + Map<String, Object> outputMap = dispatcher.runSync("parseEntityJsonFile", parseEntityXmlFileArgs); + Long numberRead = (Long) outputMap.get("rowProcessed"); + messages.add(UtilProperties.getMessage(resource, "EntityImportNumberOfEntityToBeProcessed", UtilMisc.toMap("numberRead", numberRead.toString(), "fileName", f.getName()), locale)); + if (deleteFiles) { + messages.add(UtilProperties.getMessage(resource, "EntityImportDeletFile", UtilMisc.toMap("fileName", f.getName()), locale)); + f.delete(); + } + } catch (Exception e) { + unprocessedFiles.add(f); + messages.add(UtilProperties.getMessage(resource, "EntityImportFailedFile", UtilMisc.toMap("fileName", f.getName()), locale)); + } + // pause in between files + if (pauseLong > 0) { + Debug.logInfo("Pausing for [" + pauseLong + "] seconds - " + UtilDateTime.nowTimestamp(), module); + try { + Thread.sleep((pauseLong * 1000)); + } catch (InterruptedException ie) { + Debug.logInfo("Pause finished - " + UtilDateTime.nowTimestamp(), module); + } + } + } + files = unprocessedFiles; + passes++; + messages.add(UtilProperties.getMessage(resource, "EntityImportPassedFile", UtilMisc.toMap("passes", passes), locale)); + Debug.logInfo("Pass " + passes + " complete", module); + } + lastUnprocessedFilesCount=unprocessedFiles.size(); + messages.add("---------------------------------------"); + messages.add(UtilProperties.getMessage(resource, "EntityImportSucceededNumberFile", UtilMisc.toMap("succeeded", (initialListSize-lastUnprocessedFilesCount), "total", initialListSize), locale)); + messages.add(UtilProperties.getMessage(resource, "EntityImportFailedNumberFile", UtilMisc.toMap("failed", lastUnprocessedFilesCount, "total", initialListSize), locale)); + messages.add("---------------------------------------"); + messages.add(UtilProperties.getMessage(resource, "EntityImportFailedFileList", locale)); + for (File file: unprocessedFiles) { + messages.add(file.toString()); + } + } else { + messages.add(UtilProperties.getMessage(resource, "EntityImportPathNotFound", locale)); + } + } else { + messages.add(UtilProperties.getMessage(resource, "EntityImportPathNotSpecified", locale)); + } + // send the notification + Map<String, Object> resp = UtilMisc.toMap("messages", (Object) messages); + return resp; + } + public static Map<String, Object> entityImportReaders(DispatchContext dctx, Map<String, Object> context) { String readers = (String) context.get("readers"); String overrideDelegator = (String) context.get("overrideDelegator"); @@ -463,6 +684,46 @@ public class WebToolsServices { return resp; } + public static Map<String, Object> parseEntityJsonFile(DispatchContext dctx, Map<String, ? extends Object> context) { + Delegator delegator = dctx.getDelegator(); + Locale locale = (Locale) context.get("locale"); + URL url = (URL) context.get("url"); + String xmltext = (String) context.get("xmltext"); + + if (url == null && xmltext == null) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EntityImportNoXmlFileOrTextSpecified", locale)); + } + boolean onlyInserts = (String) context.get("onlyInserts") != null; + boolean maintainTimeStamps = (String) context.get("maintainTimeStamps") != null; + boolean createDummyFks = (String) context.get("createDummyFks") != null; + boolean checkDataOnly = (String) context.get("checkDataOnly") != null; + Integer txTimeout = (Integer) context.get("txTimeout"); + Map<String, Object> placeholderValues = UtilGenerics.checkMap(context.get("placeholderValues")); + + if (txTimeout == null) { + txTimeout = 7200; + } + + long rowProcessed = 0; + try { + EntityJsonReader reader = new EntityJsonReader(delegator); + reader.setUseTryInsertMethod(onlyInserts); + reader.setMaintainTxStamps(maintainTimeStamps); + reader.setTransactionTimeout(txTimeout); + reader.setCreateDummyFks(createDummyFks); + reader.setCheckDataOnly(checkDataOnly); + reader.setPlaceholderValues(placeholderValues); + + long numberRead = (url != null ? reader.parse(url) : reader.parse(xmltext)); + rowProcessed = numberRead; + } catch (Exception ex) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EntityImportJsonParsingError", UtilMisc.toMap("errorString", ex.toString()), locale)); + } + // send the notification + Map<String, Object> resp = UtilMisc.<String, Object>toMap("rowProcessed", rowProcessed); + return resp; + } + public static Map<String, Object> entityExportAll(DispatchContext dctx, Map<String, ? extends Object> context) { Delegator delegator = dctx.getDelegator(); Locale locale = (Locale) context.get("locale"); @@ -536,6 +797,110 @@ public class WebToolsServices { continue; } fileNumber++; + } catch (GenericTransactionException e) { + Debug.logError(e, module); + results.add(e.getLocalizedMessage()); + } + } + } else { + results.add("Path not found or no write access."); + } + } else { + results.add("No path specified, doing nothing."); + } + // send the notification + Map<String, Object> resp = UtilMisc.<String, Object>toMap("results", results); + return resp; + } + + public static Map<String, Object> entityExportAllJson(DispatchContext dctx, Map<String, ? extends Object> context) { + Delegator delegator = dctx.getDelegator(); + Locale locale = (Locale) context.get("locale"); + String outpath = (String) context.get("outpath"); // mandatory + Timestamp fromDate = (Timestamp) context.get("fromDate"); + Integer txTimeout = (Integer) context.get("txTimeout"); + if (txTimeout == null) { + txTimeout = 7200; + } + + List<String> results = new LinkedList<>(); + + if (UtilValidate.isNotEmpty(outpath)) { + File outdir = new File(outpath); + if (!outdir.exists()) { + outdir.mkdir(); + } + if (outdir.isDirectory() && outdir.canWrite()) { + Set<String> passedEntityNames; + try { + ModelReader reader = delegator.getModelReader(); + Collection<String> ec = reader.getEntityNames(); + passedEntityNames = new TreeSet<>(ec); + } catch (Exception exc) { + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EntityImportErrorRetrievingEntityNames", locale)); + } + int fileNumber = 1; + + for (String curEntityName : passedEntityNames) { + long numberWritten = 0; + ModelEntity me = delegator.getModelEntity(curEntityName); + if (me instanceof ModelViewEntity) { + results.add("[" + fileNumber + "] [vvv] " + curEntityName + " skipping view entity"); + continue; + } + List<EntityCondition> conds = new LinkedList<>(); + if (UtilValidate.isNotEmpty(fromDate)) { + conds.add(EntityCondition.makeCondition("createdStamp", EntityOperator.GREATER_THAN_EQUAL_TO, fromDate)); + } + EntityQuery eq = EntityQuery.use(delegator).from(curEntityName).where(conds).orderBy(me.getPkFieldNames()); + + try { + boolean beganTx = TransactionUtil.begin(); + // some databases don't support cursors, or other problems may happen, so if there is an error here log it and move on to get as much as possible + //Don't bother writing the file if there's nothing to put into it + try (EntityListIterator values = eq.queryIterator()) { + GenericValue value = values.next(); + if (value != null) { + int curValueCount = 0; + try (PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outdir, curEntityName + ".json")), "UTF-8")))) { + writer.println("["); + writer.print("{"); + boolean isFirst = true; + do { + if (isFirst) { + writer.print('"'); + writer.print(curEntityName); + writer.print('"'); + writer.print(':'); + writer.print('['); + isFirst = false; + } + EntityJsonHelper.writeJsonText(writer, value); + curValueCount++; + numberWritten++; + if(curValueCount < values.getResultsSizeAfterPartialList()) { + writer.println(','); + } + if (numberWritten % 500 == 0) { + TransactionUtil.commit(beganTx); + beganTx = TransactionUtil.begin(); + } + } while ((value = values.next()) != null); + writer.println("]}"); + writer.print("]"); + } catch (UnsupportedEncodingException | FileNotFoundException e) { + results.add("[" + fileNumber + "] [xxx] Error when writing " + curEntityName + ": " + e); + } + results.add("[" + fileNumber + "] [" + numberWritten + "] " + curEntityName + " wrote " + numberWritten + " records"); + } else { + results.add("[" + fileNumber + "] [---] " + curEntityName + " has no records, not writing file"); + } + TransactionUtil.commit(beganTx); + } catch (GenericEntityException entityEx) { + results.add("[" + fileNumber + "] [xxx] Error when writing " + curEntityName + ": " + entityEx); + continue; + } + fileNumber++; } catch (GenericTransactionException e) { Debug.logError(e, module); results.add(e.getLocalizedMessage()); Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/template/Main.ftl URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/template/Main.ftl?rev=1862206&r1=1862205&r2=1862206&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webtools/template/Main.ftl (original) +++ ofbiz/ofbiz-framework/trunk/framework/webtools/template/Main.ftl Thu Jun 27 11:49:22 2019 @@ -80,6 +80,12 @@ under the License. <li><a href="<@ofbizUrl>EntityImport</@ofbizUrl>">${uiLabelMap.PageTitleEntityImport}</a></li> <li><a href="<@ofbizUrl>EntityImportDir</@ofbizUrl>">${uiLabelMap.PageTitleEntityImportDir}</a></li> <li><a href="<@ofbizUrl>EntityImportReaders</@ofbizUrl>">${uiLabelMap.PageTitleEntityImportReaders}</a></li> + + <li><h3>${uiLabelMap.WebtoolsEntityJSONTools}</h3></li> + <li><a href="<@ofbizUrl>jsondsdump</@ofbizUrl>">${uiLabelMap.PageTitleEntityExportJson}</a></li> + <li><a href="<@ofbizUrl>EntityExportAllJson</@ofbizUrl>">${uiLabelMap.PageTitleEntityExportAllJson}</a></li> + <li><a href="<@ofbizUrl>EntityImportJson</@ofbizUrl>">${uiLabelMap.PageTitleEntityImportJson}</a></li> + <li><a href="<@ofbizUrl>EntityImportDirJson</@ofbizUrl>">${uiLabelMap.PageTitleEntityImportDirJson}</a></li> </#if> <#if security.hasPermission("SERVICE_MAINT", session)> <li><h3>${uiLabelMap.WebtoolsServiceEngineTools}</h3></li> Added: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityExportAllJson.ftl URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityExportAllJson.ftl?rev=1862206&view=auto ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityExportAllJson.ftl (added) +++ ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityExportAllJson.ftl Thu Jun 27 11:49:22 2019 @@ -0,0 +1,66 @@ +<#-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<div class="page-title"><span>${uiLabelMap.WebtoolsExportJSONFromDataSource}</span></div> +<p>${uiLabelMap.WebtoolsJSONExportInfo}</p> +<#if results?has_content> + <hr /> + <h2>${uiLabelMap.WebtoolsResults}:</h2> + <#list results as result> + <p>${result}</p> + </#list> +</#if> +<hr /> +<form class="basic-form" method="post" action="<@ofbizUrl>entityExportAllJson</@ofbizUrl>"> + <table class="basic-table" cellspacing="0"> + <tbody> + </tr> + <td class="label"> + <label>${uiLabelMap.WebtoolsOutputDirectory}</label> + </td> + <td> + <input type="text" size="25" name="outpath" value="${outpath!}" /> + </td> + </tr> + <tr> + <td class="label"> + <label>${uiLabelMap.CommonFromDate}</label> + </td> + <td> + <@htmlTemplate.renderDateTimeField name="fromDate" event="" action="" className="" alert="" title="Format: yyyy-MM-dd HH:mm:ss.SSS" value="" size="25" maxlength="30" id="fromDate" dateType="date" shortDateInput=false timeDropdownParamName="" defaultDateTimeString="" localizedIconTitle="" timeDropdown="" timeHourName="" classString="" hour1="" hour2="" timeMinutesName="" minutes="" isTwelveHour="" ampmName="" amSelected="" pmSelected="" compositeType="" formName=""/> + </td> + </tr> + <tr> + <td class="label"> + ${uiLabelMap.WebtoolsTimeoutSeconds}: + </td> + <td> + <input type="text" size="6" value="${txTimeout?default('7200')}" name="txTimeout"/> + </td> + </tr> + <tr> + <td class="label"> + </td> + <td colspan="4"> + <input type="submit" value="${uiLabelMap.WebtoolsExport}" /> + </td> + </tr> + </tbody> + </table> +</form> Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityExportAllJson.ftl ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityExportAllJson.ftl ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityExportAllJson.ftl ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportDirJson.ftl URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportDirJson.ftl?rev=1862206&view=auto ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportDirJson.ftl (added) +++ ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportDirJson.ftl Thu Jun 27 11:49:22 2019 @@ -0,0 +1,78 @@ +<#-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<div class="page-title"><span>${uiLabelMap.WebtoolsImportToDataSource}</span></div> +<p>${uiLabelMap.WebtoolsJSONImportInfo}</p> +<hr /> + + <form class="basic-form" method="post" action="<@ofbizUrl>entityImportDirJson</@ofbizUrl>"> + <table class="basic-table" cellspacing="0"> + <tbody> + <tr> + <td class="label"> + <label>${uiLabelMap.WebtoolsAbsolutePath}:</label> + </td> + <td> + <input type="text" size="60" name="path" value="${path!}"/> + </td> + </tr> + <tr> + <td class="label"> + </td> + <td> + <label><input type="checkbox" name="onlyInserts" <#if onlyInserts??>checked="checked"</#if>/>${uiLabelMap.WebtoolsOnlyInserts}</label> + <label><input type="checkbox" name="maintainTimeStamps" <#if keepStamps??>checked="checked"</#if>/>${uiLabelMap.WebtoolsMaintainTimestamps}</label> + <label><input type="checkbox" name="createDummyFks" <#if createDummyFks??>checked="checked"</#if>/>${uiLabelMap.WebtoolsCreateDummyFks}</label> + <label><input type="checkbox" name="deleteFiles" <#if (deleteFiles??)>checked="checked"</#if>/>${uiLabelMap.WebtoolsDeleteFiles}</label> + <label><input type="checkbox" name="checkDataOnly" <#if checkDataOnly??>checked="checked"</#if>/>${uiLabelMap.WebtoolsCheckDataOnly}</label> + </td> + </tr> + <tr> + <td class="label"> + <label>${uiLabelMap.WebtoolsTimeoutSeconds}</label> + </td> + <td> + <input type="text" size="6" value="${txTimeoutStr?default("7200")}" name="txTimeout"/> + </td> + </tr> + <tr> + <td class="label"> + <label>${uiLabelMap.WebtoolsPause}</label> + </td> + <td> + <input type="text" size="6" value="${filePauseStr?default("0")}" name="filePause"/><br /> + </td> + </tr> + <tr> + <td class="label"> + </td> + <td colspan="4"> + <input type="submit" value="${uiLabelMap.WebtoolsImportFile}"/> + </td> + </tr> + </tbody> + </table> + </form> + <#if messages??> + <hr /> + <h1>${uiLabelMap.WebtoolsResults}:</h1> + <#list messages as message> + <p>${message}</p> + </#list> + </#if> Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportDirJson.ftl ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportDirJson.ftl ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportDirJson.ftl ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportJson.ftl URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportJson.ftl?rev=1862206&view=auto ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportJson.ftl (added) +++ ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportJson.ftl Thu Jun 27 11:49:22 2019 @@ -0,0 +1,101 @@ +<#-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<div class="page-title"><span>${uiLabelMap.WebtoolsJsonImportToDataSource}</span></div> +<p>${uiLabelMap.WebtoolsJSONImportInfo}</p> +<hr /> + + <form class="basic-form" method="post" action="<@ofbizUrl>entityImportJson</@ofbizUrl>"> + <table class="basic-table" cellspacing="0"> + <tbody> + <tr> + <td class="label"> + <label>${uiLabelMap.WebtoolsAbsoluteFileNameOrUrl}</label> + </td> + <td> + <input type="text" size="60" name="filename" value="${filename!}"/> + </td> + </tr> + <tr> + <td class="label"> + <label>${uiLabelMap.WebtoolsAbsoluteFTLFilename}</label> + </td> + <td> + <input type="text" size="40" name="fmfilename" value="${fmfilename!}"/> + </td> + </tr> + <tr> + <td class="label"> + </td> + <td> + <label><input type="checkbox" name="isUrl" <#if isUrl??>checked="checked"</#if>/>${uiLabelMap.WebtoolsIsURL}</label> + <label><input type="checkbox" name="onlyInserts" <#if onlyInserts??>checked="checked"</#if>/>${uiLabelMap.WebtoolsOnlyInserts}</label> + <label><input type="checkbox" name="maintainTimeStamps" <#if keepStamps??>checked="checked"</#if>/>${uiLabelMap.WebtoolsMaintainTimestamps}</label> + <label><input type="checkbox" name="createDummyFks" <#if createDummyFks??>checked="checked"</#if>/>${uiLabelMap.WebtoolsCreateDummyFks}</label> + <label><input type="checkbox" name="checkDataOnly" <#if checkDataOnly??>checked="checked"</#if>/>${uiLabelMap.WebtoolsCheckDataOnly}</label> + </td> + </tr> + <tr> + <td class="label"> + <label>${uiLabelMap.WebtoolsTimeoutSeconds}</label> + </td> + <td> + <input type="text" size="6" value="${txTimeoutStr?default("7200")}" name="txTimeout"/> + </td> + </tr> + <tr> + <td class="label"> + </td> + <td colspan="4"> + <input type="submit" value="${uiLabelMap.WebtoolsImportFile}"/> + </td> + </tr> + </tbody> + </table> + </form> + <form class="basic-form" method="post" action="<@ofbizUrl>entityImportJson</@ofbizUrl>"> + <table class="basic-table" cellspacing="0"> + <tbody> + <tr> + <td class="label"> + <label>${uiLabelMap.WebtoolsCompleteJsonData}</label> + </td> + <td> + <textarea rows="20" cols="85" name="fulltext">${fulltext?default("")}</textarea> + </td> + </tr> + <tr> + </tr> + <tr> + <td class="label"> + </td> + <td colspan="4"> + <input type="submit" value="${uiLabelMap.WebtoolsImportText}"/> + </td> + </tr> + </tbody> + </table> + </form> + <#if messages??> + <hr /> + <h3>${uiLabelMap.WebtoolsResults}:</h3> + <#list messages as message> + <p>${message}</p> + </#list> + </#if> Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportJson.ftl ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportJson.ftl ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/EntityImportJson.ftl ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/JsonDsDump.ftl URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/JsonDsDump.ftl?rev=1862206&view=auto ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/JsonDsDump.ftl (added) +++ ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/JsonDsDump.ftl Thu Jun 27 11:49:22 2019 @@ -0,0 +1,139 @@ +<#-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<#if tobrowser?? && tobrowser> +<h1>${uiLabelMap.WebtoolsExportJSONFromDataSource}</h1> +<br /> +<p>This page can be used to export data from the database in JSON format.</p> +<hr /> +<#if security.hasPermission("ENTITY_MAINT", session)> + <a href="<@ofbizUrl>jsondsrawdump</@ofbizUrl>" class="buttontext" target="_blank">Click Here to Get Data (or save to file)</a> +<#else> + <div>You do not have permission to use this page (ENTITY_MAINT needed)</div> +</#if> +<#else> +<#macro displayButtonBar> + <div class="button-bar"> + <input type="submit" value="${uiLabelMap.WebtoolsExport}"/> + <a href="<@ofbizUrl>jsondsdump?checkAll=true</@ofbizUrl>" class="smallSubmit">${uiLabelMap.WebtoolsCheckAll}</a> + <a href="<@ofbizUrl>jsondsdump</@ofbizUrl>" class="smallSubmit">${uiLabelMap.WebtoolsUnCheckAll}</a> + </div> +</#macro> + +<div class="page-title"><span>${uiLabelMap.PageTitleEntityExportJson}</span></div> +<p>${uiLabelMap.WebtoolsJSONExportInfo}</p> +<hr /> + +<#if security.hasPermission("ENTITY_MAINT", session)> + <h2>${uiLabelMap.WebtoolsResults}:</h2> + <#if parameters.filename?has_content && (numberOfEntities?number > 0)> + <p>${uiLabelMap.WebtoolsWroteJSONForAllDataIn}</p> + <p>${uiLabelMap.WebtoolsWroteNRecordsToJSONFile}</p> + <#elseif parameters.outpath?has_content && (numberOfEntities?number > 0)> + <#list results as result> + <p>${result}</p> + </#list> + <#else> + <p>${uiLabelMap.WebtoolsNoFilenameSpecified}</p> + </#if> + + <hr /> + + <h2>${uiLabelMap.WebtoolsExport}:</h2> + <form method="post" action="<@ofbizUrl>jsondsdump</@ofbizUrl>" name="entityExport"> + <table class="basic-table"> + <tr> + <td class="label">${uiLabelMap.WebtoolsOutputDirectory}</td> + <td><input type="text" size="60" name="outpath" value="${parameters.outpath!}"/></td> + </tr> + <tr> + <td class="label">${uiLabelMap.WebtoolsMaxRecordsPerFile}</td> + <td><input type="text" size="10" name="maxrecords"/></td> + </tr> + <tr> + <td class="label">${uiLabelMap.WebtoolsSingleFilename}</td> + <td><input type="text" size="60" name="filename" value="${parameters.filename!}"/></td> + </tr> + <tr> + <td class="label">${uiLabelMap.WebtoolsRecordsUpdatedSince}</td> + <td> + <@htmlTemplate.renderDateTimeField name="entityFrom" event="" action="" className="" alert="" title="Format: yyyy-MM-dd HH:mm:ss.SSS" value="" size="25" maxlength="30" id="entityFrom1" dateType="date" shortDateInput=false timeDropdownParamName="" defaultDateTimeString="" localizedIconTitle="" timeDropdown="" timeHourName="" classString="" hour1="" hour2="" timeMinutesName="" minutes="" isTwelveHour="" ampmName="" amSelected="" pmSelected="" compositeType="" formName=""/> + </td> + </tr> + <tr> + <td class="label">${uiLabelMap.WebtoolsRecordsUpdatedBefore} </td> + <td> + <@htmlTemplate.renderDateTimeField name="entityThru" event="" action="" className="" alert="" title="Format: yyyy-MM-dd HH:mm:ss.SSS" value="" size="25" maxlength="30" id="entityThru1" dateType="date" shortDateInput=false timeDropdownParamName="" defaultDateTimeString="" localizedIconTitle="" timeDropdown="" timeHourName="" classString="" hour1="" hour2="" timeMinutesName="" minutes="" isTwelveHour="" ampmName="" amSelected="" pmSelected="" compositeType="" formName=""/> + </td> + </tr> + <tr> + <td class="label">${StringUtil.wrapString(uiLabelMap.WebtoolsOutToBrowser)}</td> + <td><input type="checkbox" name="tobrowser"<#if tobrowser?has_content> checked="checked"</#if> /></td> + </tr> + <tr> + <td class="label"></td> + <td><@displayButtonBar/></td> + </tr> + <tr> + <td class="label"><label>${uiLabelMap.WebtoolsEntitySyncDump}</label></td> + <td><input type="text" name="entitySyncId" size="30" value="${entitySyncId!}"/></td> + </tr> + <tr> + <td class="label"> + <label>${uiLabelMap.WebtoolsPreConfiguredSet}:<label> + </td> + <td> + <select name="preConfiguredSetName"> + <option value="">${uiLabelMap.CommonNone}</option> + <option value="CatalogExport">${uiLabelMap.WebtoolsPreConfiguredSet1}</option> + <option value="Product1">${uiLabelMap.WebtoolsPreConfiguredSet2}</option> + <option value="Product2">${uiLabelMap.WebtoolsPreConfiguredSet3}</option> + <option value="Product3">${uiLabelMap.WebtoolsPreConfiguredSet4}</option> + <option value="Product4">${uiLabelMap.WebtoolsPreConfiguredSet5}</option> + </select> + </td> + </tr> + </table> + <br /> + + <h2>${uiLabelMap.WebtoolsEntityNames}:</h2> + <table> + <tr> + <#assign entCount = 0> + <#assign checkAll = parameters.checkAll?default("false")> + <#list modelEntities as modelEntity> + <#if entCount % 3 == 0 && entCount != 0> + </tr><tr> + </#if> + <#assign entCount = entCount + 1> + <#assign check = checkAll/> + <#if "true" == checkAll && "org.apache.ofbiz.entity.model.ModelViewEntity" == modelEntity.getClass().getName()> + <#assign check = "false"/> + </#if> + <#assign curEntityName = modelEntity.getEntityName()/> + <td><input type="checkbox" name="entityName" value="${curEntityName}"<#if check="true"> checked="checked"</#if>/>${curEntityName}</td> + </#list> + </tr> + </table> + + <@displayButtonBar/> + </form> +<#else> + <div>${uiLabelMap.WebtoolsPermissionMaint}</div> +</#if> +</#if> Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/JsonDsDump.ftl ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/JsonDsDump.ftl ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/ofbiz-framework/trunk/framework/webtools/template/entity/JsonDsDump.ftl ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/webapp/webtools/WEB-INF/controller.xml URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/webapp/webtools/WEB-INF/controller.xml?rev=1862206&r1=1862205&r2=1862206&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webtools/webapp/webtools/WEB-INF/controller.xml (original) +++ ofbiz/ofbiz-framework/trunk/framework/webtools/webapp/webtools/WEB-INF/controller.xml Thu Jun 27 11:49:22 2019 @@ -426,6 +426,27 @@ under the License. <response name="success" type="view" value="EntityImport"/> <response name="error" type="view" value="EntityImport"/> </request-map> + <request-map uri="EntityImportJson"><security https="true" auth="true"/><response name="success" type="view" value="EntityImportJson"/></request-map> + <request-map uri="entityImportJson"> + <security https="true" auth="true"/> + <event type="service" path="" invoke="entityImportJson"/> + <response name="success" type="view" value="EntityImportJson"/> + <response name="error" type="view" value="EntityImportJson"/> + </request-map> + <request-map uri="EntityExportAllJson"><security https="true" auth="true"/><response name="success" type="view" value="EntityExportAllJson"/><response name="error" type="view" value="EntityExportAllJson"/></request-map> + <request-map uri="entityExportAllJson"> + <security https="true" auth="true"/> + <event type="service" path="" invoke="entityExportAllJson"/> + <response name="success" type="view" value="EntityExportAllJson"/> + <response name="error" type="view" value="EntityExportAllJson"/> + </request-map> + <request-map uri="EntityImportDirJson"><security https="true" auth="true"/><response name="success" type="view" value="EntityImportDirJson"/></request-map> + <request-map uri="entityImportDirJson"> + <security https="true" auth="true"/> + <event type="service" path="" invoke="entityImportDirJson"/> + <response name="success" type="view" value="EntityImportDir"/> + <response name="error" type="view" value="EntityImportDir"/> + </request-map> <request-map uri="EntityImportReaders"><security https="true" auth="true"/><response name="success" type="view" value="EntityImportReaders"/></request-map> <request-map uri="entityImportReaders"> <security https="true" auth="true"/> @@ -441,6 +462,15 @@ under the License. <security https="true" auth="true"/> <response name="success" type="view" value="xmldsrawdump"/> </request-map> + <request-map uri="jsondsdump"> + <security https="true" auth="true"/> + <response name="success" type="view" value="jsondsdump"/> + </request-map> + <request-map uri="jsondsrawdump"> + <security https="true" auth="true"/> + <event type="java" path="org.apache.ofbiz.webtools.EntityJsonEvents" invoke="downloadJsonData" /> + <response name="success" type="view" value="jsondsdump"/> + </request-map> <!-- EntitySync requests --> <request-map uri="EntitySyncStatus"><security https="true" auth="true"/><response name="success" type="view" value="EntitySyncStatus"/></request-map> @@ -600,7 +630,9 @@ under the License. <view-map name="checkdb" type="screen" page="component://webtools/widget/EntityScreens.xml#CheckDb"/> <view-map name="xmldsdump" type="screen" page="component://webtools/widget/EntityScreens.xml#xmldsdump"/> + <view-map name="jsondsdump" type="screen" page="component://webtools/widget/EntityScreens.xml#jsondsdump"/> <view-map name="xmldsrawdump" page="template/entity/xmldsrawdump.jsp"/> + <view-map name="jsondsrawdump" page="template/entity/jsondsrawdump.jsp"/> <view-map name="FindUtilCache" type="screen" page="component://webtools/widget/CacheScreens.xml#FindUtilCache"/> <view-map name="FindUtilCacheElements" type="screen" page="component://webtools/widget/CacheScreens.xml#FindUtilCacheElements"/> @@ -639,9 +671,12 @@ under the License. <view-map name="EntitySQLProcessor" type="screen" page="component://webtools/widget/EntityScreens.xml#EntitySQLProcessor"/> <view-map name="ConnectionPoolStatus" type="screen" page="component://webtools/widget/EntityScreens.xml#ConnectionPoolStatus"/> <view-map name="EntityExportAll" type="screen" page="component://webtools/widget/EntityScreens.xml#EntityExportAll"/> + <view-map name="EntityExportAllJson" type="screen" page="component://webtools/widget/EntityScreens.xml#EntityExportAllJson"/> <view-map name="ProgramExport" type="screen" page="component://webtools/widget/EntityScreens.xml#ProgramExport"/> <view-map name="EntityImportDir" type="screen" page="component://webtools/widget/EntityScreens.xml#EntityImportDir"/> + <view-map name="EntityImportDirJson" type="screen" page="component://webtools/widget/EntityScreens.xml#EntityImportDirJson"/> <view-map name="EntityImport" type="screen" page="component://webtools/widget/EntityScreens.xml#EntityImport"/> + <view-map name="EntityImportJson" type="screen" page="component://webtools/widget/EntityScreens.xml#EntityImportJson"/> <view-map name="EntityImportReaders" type="screen" page="component://webtools/widget/EntityScreens.xml#EntityImportReaders"/> <!-- cert views --> Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/widget/EntityScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/widget/EntityScreens.xml?rev=1862206&r1=1862205&r2=1862206&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webtools/widget/EntityScreens.xml (original) +++ ofbiz/ofbiz-framework/trunk/framework/webtools/widget/EntityScreens.xml Thu Jun 27 11:49:22 2019 @@ -71,6 +71,27 @@ under the License. </widgets> </section> </screen> + <screen name="EntityExportAllJson"> + <section> + <actions> + <set field="titleProperty" value="PageTitleEntityExportAllJson"/> + <set field="tabButtonItem" value="entityExportAllJson"/> + <set field="parameters.TRANSACTION_TIMEOUT" value="7200"/> + <set field="results" from-field="parameters.results"/> + </actions> + <widgets> + <decorator-screen name="CommonImportExportDecorator" location="${parameters.mainDecoratorLocation}"> + <decorator-section name="body"> + <screenlet> + <platform-specific> + <html><html-template location="component://webtools/template/entity/EntityExportAllJson.ftl"/></html> + </platform-specific> + </screenlet> + </decorator-section> + </decorator-screen> + </widgets> + </section> + </screen> <screen name="ProgramExport"> <section> <actions> @@ -116,6 +137,28 @@ under the License. </widgets> </section> </screen> + <screen name="EntityImportDirJson"> + <section> + <actions> + <set field="titleProperty" value="PageTitleEntityImportDirJson"/> + <set field="tabButtonItem" value="entityImportDirJson"/> + <set field="parameters.TRANSACTION_TIMEOUT" value="7200"/> + + <set field="messages" from-field="parameters.messages"/> + </actions> + <widgets> + <decorator-screen name="CommonImportExportDecorator" location="${parameters.mainDecoratorLocation}"> + <decorator-section name="body"> + <screenlet> + <platform-specific> + <html><html-template location="component://webtools/template/entity/EntityImportDirJson.ftl"/></html> + </platform-specific> + </screenlet> + </decorator-section> + </decorator-screen> + </widgets> + </section> + </screen> <screen name="EntityImport"> <section> <actions> @@ -138,6 +181,28 @@ under the License. </widgets> </section> </screen> + <screen name="EntityImportJson"> + <section> + <actions> + <set field="titleProperty" value="PageTitleEntityImportJson"/> + <set field="tabButtonItem" value="entityImportJson"/> + <set field="parameters.TRANSACTION_TIMEOUT" value="7200"/> + + <set field="messages" from-field="parameters.messages"/> + </actions> + <widgets> + <decorator-screen name="CommonImportExportDecorator" location="${parameters.mainDecoratorLocation}"> + <decorator-section name="body"> + <screenlet> + <platform-specific> + <html><html-template location="component://webtools/template/entity/EntityImportJson.ftl"/></html> + </platform-specific> + </screenlet> + </decorator-section> + </decorator-screen> + </widgets> + </section> + </screen> <screen name="EntityImportReaders"> <section> <actions> @@ -474,6 +539,28 @@ under the License. </screenlet> </decorator-section> </decorator-screen> + </widgets> + </section> + </screen> + + <screen name="jsondsdump"> + <section> + <actions> + <property-map resource="WebtoolsUiLabels" map-name="uiLabelMap" global="true"/> + <set field="titleProperty" value="PageTitleEntityExportJson"/> + <set field="tabButtonItem" value="jsonDsDump"/> + <set field="entityFrom" from-field="parameters.entityFrom" type="Timestamp"/> + <set field="entityThru" from-field="parameters.entityThru" type="Timestamp"/> + <script location="component://webtools/groovyScripts/entity/JsonDsDump.groovy"/> + </actions> + <widgets> + <decorator-screen name="CommonImportExportDecorator" location="${parameters.mainDecoratorLocation}"> + <decorator-section name="body"> + <screenlet> + <platform-specific><html><html-template location="component://webtools/template/entity/JsonDsDump.ftl"/></html></platform-specific> + </screenlet> + </decorator-section> + </decorator-screen> </widgets> </section> </screen> Modified: ofbiz/ofbiz-framework/trunk/framework/webtools/widget/Menus.xml URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webtools/widget/Menus.xml?rev=1862206&r1=1862205&r2=1862206&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webtools/widget/Menus.xml (original) +++ ofbiz/ofbiz-framework/trunk/framework/webtools/widget/Menus.xml Thu Jun 27 11:49:22 2019 @@ -98,6 +98,18 @@ under the License. <menu-item name="entityImportReaders" title="${uiLabelMap.PageTitleEntityImportReaders}"> <link target="EntityImportReaders"/> </menu-item> + <menu-item name="jsonDsDump" title="${uiLabelMap.PageTitleEntityExportJson}"> + <link target="jsondsdump"/> + </menu-item> + <menu-item name="entityExportAllJson" title="${uiLabelMap.PageTitleEntityExportAllJson}"> + <link target="EntityExportAllJson"/> + </menu-item> + <menu-item name="entityImportJson" title="${uiLabelMap.PageTitleEntityImportJson}"> + <link target="EntityImportJson"/> + </menu-item> + <menu-item name="entityImportDirJson" title="${uiLabelMap.PageTitleEntityImportDirJson}"> + <link target="EntityImportDirJson"/> + </menu-item> </menu> <menu name="ServiceTabBar" extends="CommonTabBarMenu" extends-resource="component://common/widget/CommonMenus.xml" |
Free forum by Nabble | Edit this page |