Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Worked on SOR HealthInstitution and eliminated some todos

  • Loading branch information...
commit 7b63c62c4dfa2593c79fbd69c2abedf3546166ee 1 parent dc7739d
unknown authored
Showing with 170 additions and 231 deletions.
  1. BIN  db/sor_schema.mwb
  2. +6 −1 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/SORFullEventHandler.java
  3. +18 −5 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/SORXmlTagNames.java
  4. +8 −4 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/ClinicalSpeciality.java
  5. +3 −4 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/EanLocationCode.java
  6. +45 −104 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/HealthInstitution.java
  7. +13 −73 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/InstitutionOwner.java
  8. +27 −23 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/OrganizationalUnit.java
  9. +1 −2  ...ta-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/PostalAddressInformation.java
  10. +30 −4 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/SorNode.java
  11. +16 −8 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/SorStatus.java
  12. +1 −2  ...a-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/VirtualAddressInformation.java
  13. +2 −1  dodi/data-manager/src/test/java/com/trifork/stamdata/importer/FileParserIntegrationTest.java
View
BIN  db/sor_schema.mwb
Binary file not shown
View
7 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/SORFullEventHandler.java
@@ -34,6 +34,7 @@
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
+import com.trifork.stamdata.importer.jobs.sor.sor2.xmlmodel.ClinicalSpeciality;
import com.trifork.stamdata.importer.jobs.sor.sor2.xmlmodel.EanLocationCode;
import com.trifork.stamdata.importer.jobs.sor.sor2.xmlmodel.OrganizationalUnit;
import com.trifork.stamdata.importer.jobs.sor.sor2.xmlmodel.PostalAddressInformation;
@@ -88,6 +89,10 @@ else if (SORXmlTagNames.ADDRESS_POSTAL.equals(qName))
{
currentNode = new PostalAddressInformation(atts, currentNode, lastTag);
}
+ else if (SORXmlTagNames.CLINICAL_SPECIALITY.equals(qName))
+ {
+ currentNode = new ClinicalSpeciality(atts, currentNode, lastTag);
+ }
lastTag = qName;
super.startElement(uri, localName, qName, atts);
@@ -103,7 +108,7 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
if (currentNode.isUniqueKey()) {
try {
currentNode.compareAgainstDatabaseAndUpdateDirty(fetcher);
- currentNode.persist(persister);
+ currentNode.persistRecursive(persister);
if (parent != null) {
parent.removeChild(currentNode);
}
View
23 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/SORXmlTagNames.java
@@ -30,8 +30,6 @@
public static final String INSTITUTION_OWNER_ENTITY = "InstitutionOwnerEntity";
public static final String INSTITUTION_OWNER = "InstitutionOwner";
//
- public static final String SOR_IDENTIFIER = "SorIdentifier";
- public static final String ENTITY_NAME = "EntityName";
public static final String OWNER_TYPE = "OwnerType";
public static final String SOR_STATUS = "SorStatus";
@@ -46,6 +44,23 @@
public static final String SPECIALITY_CODE = "SpecialityCode";
public static final String SPECIALITY_TYPE = "SpecialityType";
};
+
+ public static final String HEALTH_INSTITUTION = "HealthInstitution";
+ public class HealthInstitution {
+ public static final String SOR_IDENTIFIER = "SorIdentifier";
+ public static final String ENTITY_NAME = "EntityName";
+ public static final String INSTITUTION_TYPE = "InstitutionType";
+ public static final String PHARMACY_IDENTIFIER = "PharmacyIdentifier";
+ public static final String SHAK_IDENTIFIER = "ShakIdentifier";
+ public static final String OPTIONAL_EAN_LOCATION_CODE = "OptionalEanLocationCode";
+ public static final String GEOGRAPHICAL_PARENT = "GeographicalParent";
+ public static final String POSTAL_ADDRESS_INFO = "PostalAddressInformation";
+ public static final String VISITING_ADDRESS_INFO = "VisitingAddressInformation";
+ public static final String VIRTUAL_ADDRESS_INFO = "VirtualAddressInformation";
+ public static final String SOR_STATUS = "SorStatus";
+ public static final String REPLACES_ENTITY_COLLECTION = "ReplacesEntityCollection"; // TODO
+ public static final String REPLACED_BY_ENTITY_COLLECTION = "ReplacedByEntityCollection"; // TODO
+ };
public static final String VIRTUAL_ADDRESS_INFO = "VirtualAddressInformation";
public class VirtualAddressInformation {
@@ -109,7 +124,7 @@
public static final String VISITING_ADDRESS_INFO = "VisitingAddressInformation";
public static final String ACTIVITY_ADDRESS_INFO = "ActivityAddressInformation";
public static final String VIRTUAL_ADDRESS_INFO = "VirtualAddressInformation";
- public static final String CLINICAL_SPECIALITY_COLLECTION = "ClinicalSpecialityCollection"; // TODO
+ public static final String CLINICAL_SPECIALITY_COLLECTION = "ClinicalSpecialityCollection";
public static final String SOR_STATUS = "SorStatus";
public static final String REPLACES_ENTITY_COLLECTION = "ReplacesEntityCollection"; // TODO
@@ -130,6 +145,4 @@
public static final String LOCAL_ATTRBIBUTE5 = "LocalAttribute1";
};
- // HEALTH_INSTITUTION
- public static final String HEALTH_INSTITUTION = "HealthInstitution";
}
View
12 .../data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/ClinicalSpeciality.java
@@ -42,6 +42,7 @@
public ClinicalSpeciality(Attributes attribs, SorNode parent, String parentTag) {
super(attribs, parent, parentTag);
+ persistDependsOnParent = true;
}
@Override
@@ -50,18 +51,21 @@ public boolean parseEndTag(String tagName, String tagValue) throws SAXException
return true;
}
if (SORXmlTagNames.ClinicalSpeciality.SPECIALITY_CODE.equals(tagName)) {
- builder.field("specialityCode", tagValue);
+ builder.field("specialityCode", Long.valueOf(tagValue));
} else if (SORXmlTagNames.ClinicalSpeciality.SPECIALITY_TYPE.equals(tagName)) {
- builder.field("specialityType", tagValue);
+ builder.field("specialityType", Long.valueOf(tagValue));
} else {
throw new SAXException("Encountered an unexpected tag '" + tagName + "' in SorStatus");
}
return false;
}
+ public void setOrganizationalOwner(Long ownerPID) {
+ builder.field("fkOrganizationalUnit", ownerPID);
+ }
+
@Override
- public void persist(RecordPersister persister) throws SQLException {
- super.persist(persister);
+ public void persistCurrentNode(RecordPersister persister) throws SQLException {
Long id = persister.persist(builder.build(), SorFullRecordSpecs.CLINICAL_SPECIALITY);
if (id == null)
{
View
7 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/EanLocationCode.java
@@ -85,7 +85,7 @@ public boolean parseEndTag(String tagName, String tagValue) throws SAXException
* Must happen right after persist has been called on all children, to
* make sure we insert an correct id
*/
- private void updateForeignKeys() {
+ private void updateForeignKeysOneToOne() {
for (SorNode node : children) {
if (node.getClass() == SorStatus.class) {
builder.field("fkSorStatus", ((SorStatus)node).getPID());
@@ -94,9 +94,8 @@ private void updateForeignKeys() {
}
@Override
- public void persist(RecordPersister persister) throws SQLException {
- super.persist(persister);
- updateForeignKeys();
+ public void persistCurrentNode(RecordPersister persister) throws SQLException {
+ updateForeignKeysOneToOne();
persister.persist(builder.build(), SorFullRecordSpecs.EAN_LOCATION_CODE_ENTITY);
}
View
149 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/HealthInstitution.java
@@ -26,109 +26,50 @@
package com.trifork.stamdata.importer.jobs.sor.sor2.xmlmodel;
-import java.util.List;
+import java.sql.SQLException;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+import com.trifork.stamdata.importer.jobs.sor.sor2.SORXmlTagNames;
+import com.trifork.stamdata.persistence.RecordBuilder;
+import com.trifork.stamdata.persistence.RecordFetcher;
+import com.trifork.stamdata.persistence.RecordPersister;
+import com.trifork.stamdata.specs.SorFullRecordSpecs;
+
+public class HealthInstitution extends SorNode {
+
+ private RecordBuilder builder = new RecordBuilder(SorFullRecordSpecs.HEALTH_INSTITUTION_RECORD_TYPE);
+
+ public HealthInstitution(Attributes attribs, SorNode parent,
+ String parentTag) {
+ super(attribs, parent, parentTag);
+ }
+
+ public boolean parseEndTag(String tagName, String tagValue) throws SAXException {
+ if (SORXmlTagNames.HEALTH_INSTITUTION.equals(tagName)) {
+ return true;
+ }
+ if (SORXmlTagNames.HealthInstitution.SOR_IDENTIFIER.equals(tagName)) {
+ builder.field("sorIdentifier", Long.valueOf(tagValue));
+ } else if (SORXmlTagNames.HealthInstitution.ENTITY_NAME.equals(tagName)) {
+ builder.field("entityName", tagValue);
+ } else if (SORXmlTagNames.HealthInstitution.INSTITUTION_TYPE.equals(tagName)) {
+ builder.field("institutionType", Long.valueOf(tagValue));
+ }
+ return false;
+ }
+
+ @Override
+ public void persistCurrentNode(RecordPersister persister)
+ throws SQLException {
+
+ }
+
+ @Override
+ public void compareAgainstDatabaseAndUpdateDirty(RecordFetcher fetcher)
+ throws SQLException {
+
+ }
-public class HealthInstitution {
- private long sorIdentifier; //required
- private String entityName; //required - String up to 60 chars
- private long institutionType; //required
- private String pharmacyIdentifier; //String up to 20 chars, can be null
- private String shakIdentifier; //String 4-7 characters, can be null
-
- private PostalAddressInformation postalAddressInformation;
- private PostalAddressInformation visitingAddressInformation;
- private VirtualAddressInformation virtualAddressInformation;
-
- private SorStatus sorStatus;//required
-
- private List<Long> replacesEntityCollection; //can be null - contains list of sorIDentifiers
- private List<Long> replacedByEntityCollection; //can be null - contains list of sorIDentifiers
-
- public String getEntityName() {
- return entityName;
- }
-
- public void setEntityName(String entityName) {
- this.entityName = entityName;
- }
-
- public long getInstitutionType() {
- return institutionType;
- }
-
- public void setInstitutionType(long institutionType) {
- this.institutionType = institutionType;
- }
-
- public String getPharmacyIdentifier() {
- return pharmacyIdentifier;
- }
-
- public void setPharmacyIdentifier(String pharmacyIdentifier) {
- this.pharmacyIdentifier = pharmacyIdentifier;
- }
-
- public PostalAddressInformation getPostalAddressInformation() {
- return postalAddressInformation;
- }
-
- public void setPostalAddressInformation(PostalAddressInformation postalAddressInformation) {
- this.postalAddressInformation = postalAddressInformation;
- }
-
- public List<Long> getReplacedByEntityCollection() {
- return replacedByEntityCollection;
- }
-
- public void setReplacedByEntityCollection(List<Long> replacedByEntityCollection) {
- this.replacedByEntityCollection = replacedByEntityCollection;
- }
-
- public List<Long> getReplacesEntityCollection() {
- return replacesEntityCollection;
- }
-
- public void setReplacesEntityCollection(List<Long> replacesEntityCollection) {
- this.replacesEntityCollection = replacesEntityCollection;
- }
-
- public String getShakIdentifier() {
- return shakIdentifier;
- }
-
- public void setShakIdentifier(String shakIdentifier) {
- this.shakIdentifier = shakIdentifier;
- }
-
- public long getSorIdentifier() {
- return sorIdentifier;
- }
-
- public void setSorIdentifier(long sorIdentifier) {
- this.sorIdentifier = sorIdentifier;
- }
-
- public SorStatus getSorStatus() {
- return sorStatus;
- }
-
- public void setSorStatus(SorStatus sorStatus) {
- this.sorStatus = sorStatus;
- }
-
- public VirtualAddressInformation getVirtualAddressInformation() {
- return virtualAddressInformation;
- }
-
- public void setVirtualAddressInformation(VirtualAddressInformation virtualAddressInformation) {
- this.virtualAddressInformation = virtualAddressInformation;
- }
-
- public PostalAddressInformation getVisitingAddressInformation() {
- return visitingAddressInformation;
- }
-
- public void setVisitingAddressInformation(PostalAddressInformation visitingAddressInformation) {
- this.visitingAddressInformation = visitingAddressInformation;
- }
}
View
86 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/InstitutionOwner.java
@@ -25,89 +25,29 @@
package com.trifork.stamdata.importer.jobs.sor.sor2.xmlmodel;
+import java.sql.SQLException;
-public class InstitutionOwner {
+import org.xml.sax.Attributes;
- private long sorIdentifier;
+import com.trifork.stamdata.persistence.RecordFetcher;
+import com.trifork.stamdata.persistence.RecordPersister;
- private String entityName;
-
- private long ownerType;
- private EanLocationCode eanLocationCode;
+public class InstitutionOwner extends SorNode {
- private PostalAddressInformation postalAddressInformation;
-
- private VirtualAddressInformation virtualAddressInformation;
-
- private SorStatus sorStatus;
-
- public String getEntityName() {
- return entityName;
- }
-
- public void setEntityName(String entityName) {
- this.entityName = entityName;
- }
-
- public long getOwnerType() {
- return ownerType;
- }
-
- public void setOwnerType(long ownerType) {
- this.ownerType = ownerType;
- }
-
- public EanLocationCode getEanLocationCode() {
- return eanLocationCode;
- }
-
- public void setEanLocationCode(EanLocationCode eanLocationCode) {
- this.eanLocationCode = eanLocationCode;
- }
-
- public PostalAddressInformation getPostalAddressInformation() {
- return postalAddressInformation;
- }
-
- public void setPostalAddressInformation(
- PostalAddressInformation postalAddressInformation) {
- this.postalAddressInformation = postalAddressInformation;
- }
-
- public VirtualAddressInformation getVirtualAddressInformation() {
- return virtualAddressInformation;
- }
-
- public void setVirtualAddressInformation(
- VirtualAddressInformation virtualAddressInformation) {
- this.virtualAddressInformation = virtualAddressInformation;
+ public InstitutionOwner(Attributes attribs, SorNode parent, String parentTag) {
+ super(attribs, parent, parentTag);
}
- public SorStatus getSorStatus() {
- return sorStatus;
- }
-
- public void setSorStatus(SorStatus sorStatus) {
- this.sorStatus = sorStatus;
- }
-
- public long getSorIdentifier() {
- return sorIdentifier;
- }
-
- public void setSorIdentifier(long sorIdentifier) {
- this.sorIdentifier = sorIdentifier;
+ @Override
+ public void persistCurrentNode(RecordPersister persister)
+ throws SQLException {
}
@Override
- public String toString() {
- return "InstitutionOwner [sorIdentifier=" + sorIdentifier
- + ", entityName=" + entityName + ", ownerType=" + ownerType
- + ", eanLocationCode=" + eanLocationCode
- + ", postalAddressInformation=" + postalAddressInformation
- + ", virtualAddressInformation=" + virtualAddressInformation
- + ", sorStatus=" + sorStatus + "]";
+ public void compareAgainstDatabaseAndUpdateDirty(RecordFetcher fetcher)
+ throws SQLException {
}
+
}
View
50 .../data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/OrganizationalUnit.java
@@ -65,25 +65,16 @@ public boolean parseEndTag(String tagName, String tagValue) throws SAXException
builder.field("shakIdentifier", tagValue);
} else if (SORXmlTagNames.OrganizationalUnit.PROVIDER_IDENTIFIER.equals(tagName)) {
builder.field("providerIdentifier", tagValue);
- } else if (SORXmlTagNames.OrganizationalUnit.OPTIONAL_EAN_LOCATION_CODE.equals(tagName)) {
} else if (SORXmlTagNames.OrganizationalUnit.EAN_ENTITY_INHERITED_INDICATOR.equals(tagName)) {
boolean f = Boolean.valueOf(tagValue);
if (f)
builder.field("eanLocationCodeInheritedIndicator", "1");
else
builder.field("eanLocationCodeInheritedIndicator", "0");
- } else if (SORXmlTagNames.OrganizationalUnit.GEOGRAPHICAL_PARENT.equals(tagName)) {
} else if (SORXmlTagNames.OrganizationalUnit.GEOGRAPHICAL_PARENT_RELATION.equals(tagName)) {
builder.field("geographicalParentRelation", Long.valueOf(tagValue));
} else if (SORXmlTagNames.OrganizationalUnit.GEOGRAPHICAL_PARENT_SOR_IDENTIFIER.equals(tagName)) {
builder.field("geographicalParentSorIdentifier", Long.valueOf(tagValue));
- } else if (SORXmlTagNames.OrganizationalUnit.POSTAL_ADDRESS_INFO.equals(tagName)) {
- } else if (SORXmlTagNames.OrganizationalUnit.VISITING_ADDRESS_INFO.equals(tagName)) {
- } else if (SORXmlTagNames.OrganizationalUnit.ACTIVITY_ADDRESS_INFO.equals(tagName)) {
- } else if (SORXmlTagNames.OrganizationalUnit.VIRTUAL_ADDRESS_INFO.equals(tagName)) {
- } else if (SORXmlTagNames.OrganizationalUnit.CLINICAL_SPECIALITY_COLLECTION.equals(tagName)) {
- // TODO
- System.out.println("TODO : " + tagName);
} else if (SORXmlTagNames.OrganizationalUnit.SOR_STATUS.equals(tagName)) {
builder.field("fkSorStatus", Long.valueOf(tagValue));
} else if (SORXmlTagNames.OrganizationalUnit.REPLACES_ENTITY_COLLECTION.equals(tagName)) {
@@ -91,7 +82,7 @@ public boolean parseEndTag(String tagName, String tagValue) throws SAXException
System.out.println("TODO : " + tagName);
} else if (SORXmlTagNames.OrganizationalUnit.REPLACED_BY_ENTITY_COLLECTION.equals(tagName)) {
// TODO fkReplacedByCollection
- System.out.println("TODO : " + tagName);
+ System.out.println("TODO : " + tagName);
} else if (SORXmlTagNames.OrganizationalUnit.AMBULANT_ACTIVITY_INDICATOR.equals(tagName)) {
boolean f = Boolean.valueOf(tagValue);
if (f)
@@ -120,9 +111,17 @@ public boolean parseEndTag(String tagName, String tagValue) throws SAXException
builder.field("localAttribute4", tagValue);
} else if (SORXmlTagNames.OrganizationalUnit.LOCAL_ATTRBIBUTE5.equals(tagName)) {
builder.field("localAttribute5", tagValue);
+ } else if (SORXmlTagNames.OrganizationalUnit.GEOGRAPHICAL_PARENT.equals(tagName) ||
+ SORXmlTagNames.OrganizationalUnit.ORGANIZATIONAL_UNIT_INFO.equals(tagName)||
+ SORXmlTagNames.OrganizationalUnit.POSTAL_ADDRESS_INFO.equals(tagName) ||
+ SORXmlTagNames.OrganizationalUnit.VISITING_ADDRESS_INFO.equals(tagName) ||
+ SORXmlTagNames.OrganizationalUnit.ACTIVITY_ADDRESS_INFO.equals(tagName) ||
+ SORXmlTagNames.OrganizationalUnit.VIRTUAL_ADDRESS_INFO.equals(tagName) ||
+ SORXmlTagNames.OrganizationalUnit.CLINICAL_SPECIALITY_COLLECTION.equals(tagName) ||
+ SORXmlTagNames.OrganizationalUnit.OPTIONAL_EAN_LOCATION_CODE.equals(tagName)) {
+ // Do nothing
} else {
- // TODO back in when sub nodes are implemented
- //throw new SAXException("Encountered an unexpected tag '" + tagName + "' in SorStatus");
+ throw new SAXException("Encountered an unexpected tag '" + tagName + "' in OrganizationalUnit");
}
return false;
}
@@ -131,7 +130,7 @@ public boolean parseEndTag(String tagName, String tagValue) throws SAXException
* Must happen right after persist has been called on all children, to
* make sure we insert an correct id
*/
- private void updateForeignKeys() {
+ private void updateForeignKeysOneToOne() {
// This is not pretty to look at but we need to
// get those relation in order somewhere
for (SorNode node : children) {
@@ -155,12 +154,20 @@ private void updateForeignKeys() {
}
}
+ private void updateForeignKeysOneToMany() {
+ for (SorNode node : children) {
+ if (node.getClass() == ClinicalSpeciality.class) {
+ ((ClinicalSpeciality)node).setOrganizationalOwner(getPID());
+ }
+ }
+ }
+
@Override
- public void persist(RecordPersister persister) throws SQLException {
- updateForeignKeys();
+ public void persistCurrentNode(RecordPersister persister) throws SQLException {
+ updateForeignKeysOneToOne();
setPID(persister.persist(builder.build(), SorFullRecordSpecs.ORGANIZATIONAL_UNIT));
- //
- super.persist(persister);
+ updateForeignKeysOneToMany();
+
SorNode parent = getParentNode();
// Update parent organizational units to point to us
if (parent != null && parent.getClass() == OrganizationalUnit.class) {
@@ -170,7 +177,7 @@ public void persist(RecordPersister persister) throws SQLException {
public void compareAgainstDatabaseAndUpdateDirty(RecordFetcher fetcher) throws SQLException {
// Always set dirty, and reset below if we are sure we are not updated
- dirty = true;
+ boolean dirty = true;
Record fetched = fetcher.fetchCurrent(builder.getFieldValue("sorIdentifier").toString(), SorFullRecordSpecs.ORGANIZATIONAL_UNIT);
if (fetched != null) {
Object sorStatusId = fetched.get("fkSorStatus");
@@ -179,16 +186,13 @@ public void compareAgainstDatabaseAndUpdateDirty(RecordFetcher fetcher) throws S
SorStatus status = (SorStatus)node;
status.setPID((Long)sorStatusId);
status.compareAgainstDatabaseAndUpdateDirty(fetcher);
- if (!status.dirty) {
+ if (!status.isDirty()) {
dirty = false;
}
}
}
}
- // If we are dirty we so are our children
- for (SorNode node : children) {
- node.dirty = dirty;
- }
+ setDirty(dirty);
}
@Override
View
3  ...manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/PostalAddressInformation.java
@@ -86,8 +86,7 @@ public boolean parseEndTag(String tagName, String tagValue) throws SAXException
}
@Override
- public void persist(RecordPersister persister) throws SQLException {
- super.persist(persister);
+ public void persistCurrentNode(RecordPersister persister) throws SQLException {
Long id = persister.persist(builder.build(), SorFullRecordSpecs.POSTAL_ADDRESS_INFORMATION);
if (id == null)
{
View
34 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/SorNode.java
@@ -42,18 +42,31 @@
private Long PID;
- protected boolean dirty;
- private boolean hasUniqueKey;
+ private boolean dirty;
+
+ protected boolean hasUniqueKey;
+ protected boolean persistDependsOnParent;
public SorNode(Attributes attribs, SorNode parent, String parentTag) {
+ persistDependsOnParent = false;
this.parentNode = parent;
this.setParentTag(parentTag);
dirty = false;
}
- public void persist(RecordPersister persister) throws SQLException {
+ public void persistRecursive(RecordPersister persister) throws SQLException {
+ if (!dirty)
+ return;
+ System.out.println("We are persisting why?");
+ // First save all children that do not depend on parent
+ for (SorNode node : children) {
+ if (!node.persistDependsOnParent)
+ node.persistRecursive(persister);
+ }
+ persistCurrentNode(persister);
for (SorNode node : children) {
- node.persist(persister);
+ if (node.persistDependsOnParent)
+ node.persistRecursive(persister);
}
}
@@ -61,6 +74,8 @@ public SorNode getParentNode() {
return parentNode;
}
+ abstract public void persistCurrentNode(RecordPersister persister) throws SQLException;
+
abstract public void compareAgainstDatabaseAndUpdateDirty(RecordFetcher fetcher) throws SQLException;
public boolean parseEndTag(String tagName, String tagValue) throws SAXException {
@@ -79,6 +94,17 @@ public void removeChild(SorNode child) {
public String toString() {
return "XmlNode [children=" + children + "]";
}
+
+ protected boolean isDirty() {
+ return dirty;
+ }
+
+ protected void setDirty(boolean dirty) {
+ this.dirty = dirty;
+ for (SorNode node : children) {
+ node.setDirty(dirty);
+ }
+ }
public boolean isUniqueKey() {
return hasUniqueKey;
View
24 dodi/data-manager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/SorStatus.java
@@ -43,7 +43,7 @@
public SorStatus(Attributes attribs, SorNode parent, String parentTag) {
super(attribs, parent, parentTag);
- this.setHasUniqueKey(false);
+ hasUniqueKey = false;
}
@Override
@@ -66,18 +66,25 @@ public boolean parseEndTag(String tagName, String tagValue) throws SAXException
}
@Override
- public void persist(RecordPersister persister) throws SQLException {
- super.persist(persister);
- Long id = persister.persist(builder.build(), SorFullRecordSpecs.SOR_STATUS);
- if (id == null)
+ public void persistCurrentNode(RecordPersister persister) throws SQLException {
+ if (this.isDirty())
{
- throw new SQLException("MySql did not respond with an Id of the row inserted in SorStatus table");
+ Long id = persister.persist(builder.build(), SorFullRecordSpecs.SOR_STATUS);
+ if (id == null)
+ {
+ throw new SQLException("MySql did not respond with an Id of the row inserted in SorStatus table");
+ }
+ setPID(id);
+ setDirty(false);
+ }
+ else
+ {
+ System.out.println("Trying to persist something that is not dirty");
}
- setPID(id);
}
public void compareAgainstDatabaseAndUpdateDirty(RecordFetcher fetcher) throws SQLException {
- dirty = true;
+ boolean dirty = true;
// We rely on primaryKey being set before this is called
String updatedAtInXml = (String) builder.getFieldValue("updatedAt");
if (getPID() != null) {
@@ -95,6 +102,7 @@ public void compareAgainstDatabaseAndUpdateDirty(RecordFetcher fetcher) throws S
throw new SQLException("Could not located Sor Status");
}
}
+ setDirty(dirty);
}
@Override
View
3  ...anager/src/main/java/com/trifork/stamdata/importer/jobs/sor/sor2/xmlmodel/VirtualAddressInformation.java
@@ -66,8 +66,7 @@ public boolean parseEndTag(String tagName, String tagValue) throws SAXException
}
@Override
- public void persist(RecordPersister persister) throws SQLException {
- super.persist(persister);
+ public void persistCurrentNode(RecordPersister persister) throws SQLException {
Long id = persister.persist(builder.build(), SorFullRecordSpecs.VIRTUAL_ADDRESS_INFORMATION);
if (id == null)
{
View
3  dodi/data-manager/src/test/java/com/trifork/stamdata/importer/FileParserIntegrationTest.java
@@ -72,10 +72,11 @@ public final void before() throws Exception
statement.execute("TRUNCATE TABLE Import");
statement.execute("TRUNCATE TABLE YderregisterPerson");
statement.execute("TRUNCATE TABLE Sikrede");
- statement.execute("TRUNCATE TABLE SORSorStatus");
+/* statement.execute("TRUNCATE TABLE SORSorStatus");
statement.execute("TRUNCATE TABLE SORInstitutionOwner");
statement.execute("TRUNCATE TABLE SOROrganizationalUnit");
statement.execute("TRUNCATE TABLE SOREanLocationCode");
+ statement.execute("TRUNCATE TABLE SORClinicalspeciality");*/
statement.close();
}
Please sign in to comment.
Something went wrong with that request. Please try again.