Unmarshaller hierarhy save
This commit is contained in:
@@ -185,15 +185,15 @@ public class Addrobj implements Serializable {
|
||||
}
|
||||
|
||||
public void setEnddate(GregorianCalendar enddate) {
|
||||
this.enddate = dtf.newXMLGregorianCalendar(enddate);
|
||||
this.enddate = enddate!= null ? dtf.newXMLGregorianCalendar(enddate) : null;
|
||||
}
|
||||
|
||||
public void setStartdate(GregorianCalendar startdate) {
|
||||
this.startdate = dtf.newXMLGregorianCalendar(startdate);
|
||||
this.startdate = startdate != null ? dtf.newXMLGregorianCalendar(startdate) : null;
|
||||
}
|
||||
|
||||
public void setUpdatedate(GregorianCalendar updatedate) {
|
||||
this.updatedate = dtf.newXMLGregorianCalendar(updatedate);
|
||||
this.updatedate = updatedate != null ? dtf.newXMLGregorianCalendar(updatedate) : null;
|
||||
}
|
||||
|
||||
public Addrobj aoguid(String aoguid) {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class House implements Serializable {
|
||||
//@Type(type="uuid-char")
|
||||
@XmlAttribute(name = "AOGUID", required = true)
|
||||
//@Column(name = "aoguid")
|
||||
@ManyToOne(targetEntity = Addrobj.class)
|
||||
@ManyToOne(targetEntity = Addrobj.class, cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "aoguid", referencedColumnName = "aoguid")
|
||||
@XmlJavaTypeAdapter(AddrObjAdapter.class)
|
||||
public Addrobj aoguid;
|
||||
|
||||
@@ -6,6 +6,7 @@ import me.bearns.fias.domain.House;
|
||||
import me.bearns.fias.domain.Houses;
|
||||
import me.bearns.fias.repository.AddrobjRepository;
|
||||
import me.bearns.fias.repository.HouseRepository;
|
||||
import me.bearns.fias.xml.AddrObjAdapter;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -37,6 +38,9 @@ public class Catalog {
|
||||
Houses.class
|
||||
)
|
||||
);
|
||||
|
||||
//init AddrObjAdapter
|
||||
AddrObjAdapter.setRepository(ADDROBJ_REPOSITORY);
|
||||
}
|
||||
|
||||
public Item getByPrefix(String s){
|
||||
|
||||
@@ -45,7 +45,6 @@ public class UpdaterImpl implements UpdateHelper {
|
||||
@Autowired
|
||||
private static StreamSaver unmarshaller;
|
||||
|
||||
|
||||
//transaction from here
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void processUpdates(List<FiasVersion> updates, boolean reloadFlag) throws CommonException {
|
||||
@@ -124,12 +123,6 @@ public class UpdaterImpl implements UpdateHelper {
|
||||
final UnmarshallerParameters config = catalog.getByPrefix(name);
|
||||
|
||||
if(config!=null) {
|
||||
|
||||
final JpaRepository repository = config.getRepository();
|
||||
if(repository instanceof AddrobjRepository){
|
||||
AddrObjAdapter.setRepository((AddrobjRepository) repository);
|
||||
}
|
||||
|
||||
try (InputStream is = zipFile.getInputStream(entry)) {
|
||||
log.debug("Process '{}' in zip", name);
|
||||
unmarshaller.process(is, config, filter);
|
||||
|
||||
@@ -2,16 +2,12 @@ package me.bearns.fias.xml;
|
||||
|
||||
import me.bearns.fias.domain.Addrobj;
|
||||
import me.bearns.fias.repository.AddrobjRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AddrObjAdapter extends XmlAdapter<String, Addrobj> {
|
||||
|
||||
|
||||
private static AddrobjRepository repository;
|
||||
|
||||
@Override
|
||||
@@ -20,8 +16,11 @@ public class AddrObjAdapter extends XmlAdapter<String, Addrobj> {
|
||||
final UUID aoguid = UUID.fromString(v);
|
||||
final Addrobj addrobj = repository.findByAoguid(aoguid).orElseGet(Addrobj::new);
|
||||
//final Addrobj addrobj = new Addrobj(); //TODO FIX IT
|
||||
addrobj.aoguid = aoguid;
|
||||
addrobj.aoid = aoguid;
|
||||
if(addrobj.aoid == null) {
|
||||
addrobj.aoid = aoguid;
|
||||
addrobj.aoguid = aoguid;
|
||||
//repository.save(addrobj);
|
||||
}
|
||||
|
||||
return addrobj;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import me.bearns.fias.exceptions.CommonException;
|
||||
import me.bearns.fias.helper.XMLSourceHelper;
|
||||
import me.bearns.fias.helpers.Catalog;
|
||||
import me.bearns.fias.helpers.UnmarshallerParameters;
|
||||
import me.bearns.fias.helpers.UpdateHelper;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -28,6 +29,10 @@ public class StreamSaverTest {
|
||||
@Autowired
|
||||
private Catalog catalog;
|
||||
|
||||
@Autowired
|
||||
private UpdateHelper helper;
|
||||
|
||||
|
||||
@Test
|
||||
public void addrobjTest() throws CommonException {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user