protected LoadAction getLoadAction( String dataClusterName, String typeName, String dataModelName, boolean needValidate, boolean needAutoGenPK) { // Test if the data cluster actually exists DataClusterPOJO dataCluster = getDataCluster(dataClusterName); if (dataCluster == null) { throw new IllegalArgumentException("Data cluster '" + dataClusterName + "' does not exist."); } LoadAction loadAction; if (needValidate || XSystemObjects.DC_PROVISIONING.getName().equals(dataClusterName)) { loadAction = new DefaultLoadAction(dataClusterName, dataModelName, needValidate); } else { loadAction = new OptimizedLoadAction(dataClusterName, typeName, dataModelName, needAutoGenPK); } if (log.isDebugEnabled()) { log.debug( "Load action selected for load: " + loadAction.getClass().getName() // $NON-NLS-1$ + " / needValidate:" + needValidate + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } return loadAction; }
@Override protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); // $NON-NLS-1$ response.setContentType("text/html; charset=UTF-8"); // $NON-NLS-1$ response.setCharacterEncoding("UTF-8"); // $NON-NLS-1$ // configure writer depending on logger configuration. PrintWriter writer = configureWriter(response); writer.write("<html><body>"); // $NON-NLS-1$ writer.write( "<p><b>Load data into MDM</b><br/>Check server log output to determine when load is completed</b></p>"); //$NON-NLS-1$ String dataClusterName = request.getParameter(PARAMETER_CLUSTER); String typeName = request.getParameter(PARAMETER_CONCEPT); String dataModelName = request.getParameter(PARAMETER_DATAMODEL); boolean needValidate = Boolean.valueOf(request.getParameter(PARAMETER_VALIDATE)); boolean needAutoGenPK = Boolean.valueOf(request.getParameter(PARAMETER_SMARTPK)); LoadAction loadAction = getLoadAction(dataClusterName, typeName, dataModelName, needValidate, needAutoGenPK); if (needValidate && !loadAction.supportValidation()) { throw new ServletException( new UnsupportedOperationException("XML Validation isn't supported")); // $NON-NLS-1$ } // Get xml server and key information XmlServer server; XSDKey keyMetadata; try { keyMetadata = getTypeKey(dataModelName, typeName); server = Util.getXmlServerCtrlLocal(); } catch (Exception e) { throw new ServletException(e); } SaverSession session = SaverSession.newSession(); SaverContextFactory contextFactory = session.getContextFactory(); DocumentSaverContext context = contextFactory.createBulkLoad( dataClusterName, dataModelName, keyMetadata, request.getInputStream(), loadAction, server); DocumentSaver saver = context.createSaver(); try { session.begin(dataClusterName); saver.save(session, context); session.end(); // End the load (might persist counter state in case of autogen pk). loadAction.endLoad(server); } catch (Exception e) { try { session.abort(); } catch (Exception rollbackException) { log.error("Ignoring rollback exception", rollbackException); // $NON-NLS-1$ } throw new ServletException(e); } writer.write("</body></html>"); // $NON-NLS-1$ }