import java.io.InputStream;
import java.util.List;
import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
// The modified Nuxeo ImportCommand from nuxeo's shell:
@Produces({ "application/xml" })
@Consumes({ "application/xml" })
public class ImportsResource extends AbstractCollectionSpaceResourceImpl<PoxPayloadIn, PoxPayloadOut> {
+
+ private final static Logger logger = LoggerFactory.getLogger(TemplateExpander.class);
public static final String SERVICE_NAME = "imports";
public static final String SERVICE_PATH = "/" + SERVICE_NAME;
private static final int DEFAULT_TX_TIMOUT = 600; // timeout period in
- // seconds
/*
* ASSUMPTION: All Nuxeo services of a given tenancy store their stuff in
}
String requestFilename = requestFile.getCanonicalPath();
InputSource inputSource = new InputSource(requestFilename);
- System.out.println("############## REQUEST_FILENAME: "
+ if (logger.isTraceEnabled()) {
+ logger.trace("############## REQUEST_FILENAME: "
+ requestFilename);
+ }
return inputSource;
}
"Could not create file in requestDir: " + requestDir);
}
String requestFilename = requestFile.getCanonicalPath();
- System.out.println("############## REQUEST_FILENAME: "
+ if (logger.isTraceEnabled()) {
+ logger.trace("############## REQUEST_FILENAME: "
+ requestFilename);
+ }
return requestFilename;
}
public static void expandXmlPayloadToDir(String tenantId,
String inputFilename, String templateDir, String outputDir)
throws Exception {
- System.out.println("############## TEMPLATE_DIR: " + templateDir);
- System.out.println("############## OUTPUT_DIR:" + outputDir);
+ if (logger.isTraceEnabled()) {
+ logger.trace("############## TEMPLATE_DIR: " + templateDir);
+ logger.trace("############## OUTPUT_DIR:" + outputDir);
+ }
File file = new File(inputFilename);
FileInputStream is = new FileInputStream(file);
InputSource inputSource = new InputSource(is);
public static void expandXmlPayloadToDir(String tenantId,
InputSource inputSource, String templateDir, String outputDir)
throws Exception {
- System.out.println("############## TEMPLATE_DIR: " + templateDir);
- System.out.println("############## OUTPUT_DIR:" + outputDir);
+ if (logger.isTraceEnabled()) {
+ logger.trace("############## TEMPLATE_DIR: " + templateDir);
+ logger.trace("############## OUTPUT_DIR:" + outputDir);
+ }
TemplateExpander.expandInputSource(tenantId, templateDir, outputDir,
inputSource, "/imports/import");
// TemplateExpander.expandInputSource(templateDir, outputDir,
try {
InputStream fileStream = null;
String preamble = partFormData.getPreamble();
- System.out.println("Preamble type is:" + preamble);
+ if (logger.isTraceEnabled()) {
+ logger.trace("Preamble type is:" + preamble);
+ }
Map<String, List<InputPart>> partsMap = partFormData
.getFormDataMap();
List<InputPart> fileParts = partsMap.get("file");
int timeout = this.getTimeoutParam(ui);
for (InputPart part : fileParts) {
String mediaType = part.getMediaType().toString();
- System.out.println("Media type is:" + mediaType);
+ if (logger.isTraceEnabled()) {
+ logger.trace("Media type is:" + mediaType);
+ }
if (mediaType.equalsIgnoreCase(MediaType.APPLICATION_XML)
|| mediaType.equalsIgnoreCase(MediaType.TEXT_XML)) {
// FIXME For an alternate approach, potentially preferable,
File zipfile = FileUtils.createTmpFile(fileStream,
getServiceName() + "_");
String zipfileName = zipfile.getCanonicalPath();
- System.out.println("Imports zip file saved to:"
- + zipfileName);
+ if (logger.isTraceEnabled()) {
+ logger.trace("Imports zip file saved to:"
+ + zipfileName);
+ }
String baseOutputDir = FileTools.createTmpDir("imports-")
.getCanonicalPath();
File indir = new File(baseOutputDir + "/in");
indir.mkdir();
ZipTools.unzip(zipfileName, indir.getCanonicalPath());
- String result = "\r\n<zipResult>Zipfile " + zipfileName
- + "extracted to: " + indir.getCanonicalPath()
- + "</zipResult>";
- System.out.println(result);
-
+ String result = "\r\n<zipResult>Zipfile " + zipfileName
+ + "extracted to: " + indir.getCanonicalPath()
+ + "</zipResult>";
+ if (logger.isTraceEnabled()) {
+ logger.trace(result);
+ }
long start = System.currentTimeMillis();
// TODO: now call import service...
resultBuf.append(result);
+ " <input name='file' type='file' accept='application/xml,text/xml' />\n"
+ " <br />\n"
+ " <input type='submit' value='Upload File' />\n"
- + " </form>\n" + " </body>\n" + "</html>\n";
+ + " </form>\n"
+ + " </body>\n"
+ + "</html>\n";
@GET
@Produces("text/html")
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.xml.sax.InputSource;
/** This class expands variables in templates specifically for the imports service.
*/
public class TemplateExpander {
+ private final static Logger logger = LoggerFactory.getLogger(TemplateExpander.class);
+
private static final String DEFAULT_WRAPPER_TEMPLATE_FILENAME = "service-document.xml";
private static Map<String,String> docTypeSvcNameRegistry = new HashMap<String,String>();
private static XPath xpath = XPathFactory.newInstance().newXPath();
InputSource input = new InputSource(new StringReader(xmlFragmentWrapped));
value = xpath.evaluate(xpathExpr, input);
} catch (XPathExpressionException e) {
- System.out.println(e.getMessage());
+ logger.error(e.getMessage());
}
return value;
TemplateExpander.createDocInWorkspace(TENANT_ID, fragment, serviceName, serviceType,
perRecordAttributes, TEMPLATE_DIR, OUPUT_DIR, CSID);
} catch (Exception e){
- System.err.println("ERROR calling expandXmlPayloadToDir"+e);
+ logger.error("ERROR calling expandXmlPayloadToDir"+e);
e.printStackTrace();
}
}
public void onEndDocument(Document document, int fragmentCount){
- System.out.println("====TemplateExpander DONE============\r\n"+ XmlTools.prettyPrint(document)+"================");
+ if (logger.isTraceEnabled()) {
+ logger.trace("====TemplateExpander DONE============\r\n"+ XmlTools.prettyPrint(document)+"================");
+ }
}
//============helper methods==============================================================
}
private void dump(Document context, String currentPath, int fragmentIndex, String fragment){
- System.out.println("====Path============\r\n"+currentPath+'['+fragmentIndex+']');
- System.out.println("====Context=========\r\n"+ XmlTools.prettyPrint(context));
- System.out.println("====Fragment========\r\n"+fragment+"\r\n===================\r\n");
+ if (logger.isTraceEnabled()) {
+ logger.trace("====Path============\r\n"+currentPath+'['+fragmentIndex+']');
+ logger.trace("====Context=========\r\n"+ XmlTools.prettyPrint(context));
+ logger.trace("====Fragment========\r\n"+fragment+"\r\n===================\r\n");
+ }
}
}
import java.util.HashMap;\r
import java.util.Map;\r
import java.util.TreeSet;\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
import org.collectionspace.services.nuxeo.client.java.NuxeoClientEmbedded;\r
import org.collectionspace.services.nuxeo.client.java.NuxeoConnectorEmbedded;\r
import org.nuxeo.ecm.core.api.DocumentModel;\r
import org.nuxeo.ecm.core.io.impl.DocumentPipeImpl;\r
import org.nuxeo.ecm.core.io.impl.plugins.DocumentModelWriter;\r
// we use our own override of this: import org.nuxeo.ecm.core.io.impl.plugins.XMLDirectoryReader;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
\r
// based loosely on package org.nuxeo.ecm.shell.commands.io.ImportCommand;\r
public class ImportCommand {\r
- private static final Log logger = LogFactory.getLog(ImportCommand.class);\r
+ \r
+ private final Logger logger = LoggerFactory.getLogger(ImportCommand.class);\r
\r
public String run(String src, String dest, int timeOut) throws Exception {\r
File file = new File(src);\r
NuxeoClientEmbedded client = NuxeoConnectorEmbedded.getInstance().getClient();\r
RepositoryInstance repoSession = client.openRepository(timeOut);\r
try {\r
- String msg = String.format("Start of import is Local time: %tT", Calendar.getInstance());\r
- logger.debug(msg);\r
- System.out.println(msg);\r
+ if (logger.isDebugEnabled()) {\r
+ String msg = String.format("Start of import is Local time: %tT", Calendar.getInstance());\r
+ logger.debug(msg);\r
+ }\r
return importTree(repoSession, file, dest);\r
} catch (Exception e) {\r
throw e;\r
} finally {\r
+ if (logger.isDebugEnabled()) {\r
String msg = String.format("End of import is Local time: %tT", Calendar.getInstance());\r
logger.debug(msg);\r
- System.out.println(msg);\r
+ }\r
client.releaseRepository(repoSession);\r
}\r
}\r
Integer numRecordsImportedForDocType = new Integer(0);\r
int totalRecordsImported = 0;\r
try {\r
- System.out.println("importTree reading file: "+file+(file!=null ? " exists? "+file.exists() : " file param is null"));\r
+ if (logger.isInfoEnabled()) {\r
+ logger.info("importTree reading file: "+file+(file!=null ? " exists? "+file.exists() : " file param is null"));\r
+ }\r
reader = new LoggedXMLDirectoryReader(file); //our overload of XMLDirectoryReader.\r
writer = new DocumentModelWriter(repoSession, toPath, 10);\r
DocumentPipe pipe = new DocumentPipeImpl(10);\r
if (failed != null) {\r
String msg = "The Import service encountered an exception: " + failed.getLocalizedMessage();\r
logger.error(msg, failed);\r
- System.err.println(msg);\r
}\r
}\r
return dump.toString();\r
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.nuxeo.ecm.core.io.impl.AbstractDocumentReader;
import org.nuxeo.ecm.core.io.impl.ExportedDocumentImpl;
import org.nuxeo.runtime.services.streaming.FileSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class LoggedXMLDirectoryReader extends AbstractDocumentReader {
+
+ private final Logger logger = LoggerFactory.getLogger(LoggedXMLDirectoryReader.class);
+
protected Document loadXML(File file) throws IOException {
String filename = file.getCanonicalPath();
- System.out.println("~~~~~~~~~~~~~~~~~~~ LoggedXMLDirectoryReader :: "+filename);
+
+ if (logger.isTraceEnabled()) {
+ logger.trace("~~~~~~~~~~~~~~~~~~~ LoggedXMLDirectoryReader :: "+filename);
+ }
BufferedInputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(file));
- System.out.println("~~~~~~~~~~~~~~~~~~~ LoggedXMLDirectoryReader :: "+filename+" :: DONE");
+ if (logger.isTraceEnabled()) {
+ logger.trace("~~~~~~~~~~~~~~~~~~~ LoggedXMLDirectoryReader :: "+filename+" :: DONE");
+ }
reportList.add("READ: "+filename);
return new SAXReader().read(in);
} catch (DocumentException e) {
IOException ioe = new IOException("Failed to read file document "
+ file + ": " + e.getMessage());
ioe.setStackTrace(e.getStackTrace());
- System.out.println("~~~~~~~~~~~~~~~~~~~ LoggedXMLDirectoryReader :: "+filename+" :: ERROR");
+ logger.error("~~~~~~~~~~~~~~~~~~~ LoggedXMLDirectoryReader :: "+filename+" :: ERROR");
reportList.add("ERROR: "+filename);
throw ioe;
} finally {