use of org.apache.ofbiz.entity.util.EntitySaxReader in project ofbiz-framework by apache.
the class WebToolsServices method parseEntityXmlFile.
public static Map<String, Object> parseEntityXmlFile(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 = Integer.valueOf(7200);
}
long rowProcessed = 0;
try {
EntitySaxReader reader = new EntitySaxReader(delegator);
reader.setUseTryInsertMethod(onlyInserts);
reader.setMaintainTxStamps(maintainTimeStamps);
reader.setTransactionTimeout(txTimeout.intValue());
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, "EntityImportParsingError", UtilMisc.toMap("errorString", ex.toString()), locale));
}
// send the notification
Map<String, Object> resp = UtilMisc.<String, Object>toMap("rowProcessed", rowProcessed);
return resp;
}
use of org.apache.ofbiz.entity.util.EntitySaxReader in project ofbiz-framework by apache.
the class EntityTestSuite method testEntitySaxReaderUpdate.
public void testEntitySaxReaderUpdate() throws Exception {
String xmlContentLoad = "<entity-engine-xml>" + "<TestingType testingTypeId=\"create-update\" description=\"create update\"/>" + "<TestingType testingTypeId=\"create-updated\" description=\"create update updated\"/>" + "<Testing testingId=\"create-update-T3\" testingTypeId=\"create-update\" testingName=\"Test 3\" testingSize=\"10\" testingDate=\"2010-01-01 00:00:00\"/>" + "<create-update>" + " <Testing testingId=\"create-update-T1\" testingTypeId=\"create-update\" testingName=\"First test update\" testingSize=\"20\" testingDate=\"2010-01-01 00:00:00\"/>" + " <Testing testingId=\"create-update-T3\" testingTypeId=\"create-updated\" testingName=\"Third test\" testingSize=\"30\" testingDate=\"2010-03-01 00:00:00\"/>" + "</create-update>" + "</entity-engine-xml>";
EntitySaxReader reader = new EntitySaxReader(delegator);
long numberLoaded = reader.parse(xmlContentLoad);
assertEquals("Update Entity loaded ", 5, numberLoaded);
GenericValue t1 = EntityQuery.use(delegator).from("Testing").where("testingId", "create-update-T1").queryOne();
GenericValue t3 = EntityQuery.use(delegator).from("Testing").where("testingId", "create-update-T3").queryOne();
assertNotNull("Update Testing(T1)", t1);
assertEquals("Update Testing(T1).testingTypeId", "create-update", t1.getString("testingTypeId"));
assertEquals("Update Testing(T1).testingName", "First test update", t1.getString("testingName"));
assertEquals("Update Testing(T1).testingSize", Long.valueOf(20), t1.getLong("testingSize"));
assertEquals("Update Testing(T1).testingDate", UtilDateTime.toTimestamp("01/01/2010 00:00:00"), t1.getTimestamp("testingDate"));
assertNotNull("Update Testing(T3)", t3);
assertEquals("Update Testing(T3).testingTypeId", "create-updated", t3.getString("testingTypeId"));
assertEquals("Update Testing(T3).testingName", "Third test", t3.getString("testingName"));
assertEquals("Update Testing(T3).testingSize", Long.valueOf(30), t3.getLong("testingSize"));
assertEquals("Update Testing(T3).testingDate", UtilDateTime.toTimestamp("03/01/2010 00:00:00"), t3.getTimestamp("testingDate"));
}
use of org.apache.ofbiz.entity.util.EntitySaxReader in project ofbiz-framework by apache.
the class EntityTestSuite method testEntitySaxReaderCreateSkip.
public void testEntitySaxReaderCreateSkip() throws Exception {
String xmlContentLoad = "<entity-engine-xml>" + "<TestingType testingTypeId=\"reader-create-skip\" description=\"reader create skip\"/>" + "<Testing testingId=\"reader-create-skip\" testingTypeId=\"reader-create-skip\" testingName=\"reader create skip\" testingSize=\"10\" testingDate=\"2010-01-01 00:00:00\"/>" + "</entity-engine-xml>";
EntitySaxReader reader = new EntitySaxReader(delegator);
long numberLoaded = reader.parse(xmlContentLoad);
xmlContentLoad = "<create>" + " <Testing testingId=\"reader-create-skip\" testingName=\"reader create skip updated\" testingSize=\"20\" testingDate=\"2012-02-02 02:02:02\"/>" + "</create>";
reader = new EntitySaxReader(delegator);
numberLoaded += reader.parse(xmlContentLoad);
assertEquals("Create Skip Entity loaded ", 3, numberLoaded);
GenericValue t1 = EntityQuery.use(delegator).from("Testing").where("testingId", "reader-create-skip").queryOne();
assertNotNull("Create Skip Testing(T1)", t1);
assertEquals("Create Skip Testing(T1).testingTypeId", "reader-create-skip", t1.getString("testingTypeId"));
assertEquals("Create Skip Testing(T1).testingName", "reader create skip", t1.getString("testingName"));
assertEquals("Create Skip Testing(T1).testingSize", Long.valueOf(10), t1.getLong("testingSize"));
assertEquals("Create Skip Testing(T1).testingDate", UtilDateTime.toTimestamp("01/01/2010 00:00:00"), t1.getTimestamp("testingDate"));
}
use of org.apache.ofbiz.entity.util.EntitySaxReader in project ofbiz-framework by apache.
the class EntityTestSuite method testEntitySaxReaderDelete.
public void testEntitySaxReaderDelete() throws Exception {
String xmlContentLoad = "<delete>" + " <Testing testingId=\"T1\"/>" + " <Testing testingId=\"T2\"/>" + " <Testing testingId=\"T3\"/>" + " <TestingType testingTypeId=\"JUNIT-TEST\"/>" + " <TestingType testingTypeId=\"JUNIT-TEST2\"/>" + "</delete>";
EntitySaxReader reader = new EntitySaxReader(delegator);
long numberLoaded = reader.parse(xmlContentLoad);
assertEquals("Delete Entity loaded ", 5, numberLoaded);
GenericValue t1 = EntityQuery.use(delegator).from("Testing").where("testingId", "T1").queryOne();
GenericValue t2 = EntityQuery.use(delegator).from("Testing").where("testingId", "T2").queryOne();
GenericValue t3 = EntityQuery.use(delegator).from("Testing").where("testingId", "T3").queryOne();
assertNull("Delete Testing(T1)", t1);
assertNull("Delete Testing(T2)", t2);
assertNull("Delete Testing(T3)", t3);
GenericValue testType = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "JUNIT-TEST").queryOne();
assertNull("Delete TestingType 1", testType);
testType = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "JUNIT-TEST2").queryOne();
assertNull("Delete TestingType 2", testType);
}
use of org.apache.ofbiz.entity.util.EntitySaxReader in project ofbiz-framework by apache.
the class EntityTestSuite method testEntitySaxReaderReplace.
public void testEntitySaxReaderReplace() throws Exception {
String xmlContentLoad = "<entity-engine-xml>" + "<TestingType testingTypeId=\"create-replace\" description=\"reader create skip\"/>" + "<Testing testingTypeId=\"create-replace\" testingId=\"create-replace-T1\" testingName=\"First test\" testingSize=\"10\" testingDate=\"2010-01-01 00:00:00\"/>" + "<create-replace>" + " <Testing testingTypeId=\"create-replace\" testingId=\"create-replace-T1\" testingName=\"First test replace\" />" + "</create-replace>" + "<Testing testingTypeId=\"create-replace\" testingId=\"create-replace-T2\" testingName=\"Second test update\" testingSize=\"20\" testingDate=\"2010-02-01 00:00:00\"/>" + "</entity-engine-xml>";
EntitySaxReader reader = new EntitySaxReader(delegator);
long numberLoaded = reader.parse(xmlContentLoad);
assertEquals("Replace Entity loaded ", 4, numberLoaded);
GenericValue t1 = EntityQuery.use(delegator).from("Testing").where("testingId", "create-replace-T1").queryOne();
GenericValue t2 = EntityQuery.use(delegator).from("Testing").where("testingId", "create-replace-T2").queryOne();
assertNotNull("Replace Testing(T1)", t1);
assertEquals("Replace Testing(T1).testingTypeId", "create-replace", t1.getString("testingTypeId"));
assertEquals("Replace Testing(T1).testingName", "First test replace", t1.getString("testingName"));
assertNull("Replace Testing(T1).testingSize", t1.getLong("testingSize"));
assertNull("Replace Testing(T1).testingDate", t1.getTimestamp("testingDate"));
assertNotNull("Replace Testing(T2)", t2);
assertEquals("Replace Testing(T2).testingTypeId", "create-replace", t2.getString("testingTypeId"));
assertEquals("Replace Testing(T2).testingName", "Second test update", t2.getString("testingName"));
assertEquals("Replace Testing(T2).testingSize", Long.valueOf(20), t2.getLong("testingSize"));
assertEquals("Replace Testing(T2).testingDate", UtilDateTime.toTimestamp("02/01/2010 00:00:00"), t2.getTimestamp("testingDate"));
}
Aggregations