Files in archive order
This commit is contained in:
@@ -26,8 +26,8 @@ public class Catalog {
|
||||
ADDROBJ_REPOSITORY,
|
||||
new QName("","Object"),
|
||||
Addrobj.class,
|
||||
AddressObjects.class
|
||||
)
|
||||
AddressObjects.class,
|
||||
10)
|
||||
);
|
||||
prefixList.add(
|
||||
new Item(
|
||||
@@ -35,8 +35,8 @@ public class Catalog {
|
||||
HOUSE_REPOSITORY,
|
||||
new QName("","House"),
|
||||
House.class,
|
||||
Houses.class
|
||||
)
|
||||
Houses.class,
|
||||
20)
|
||||
);
|
||||
|
||||
//init AddrObjAdapter
|
||||
@@ -58,18 +58,20 @@ public class Catalog {
|
||||
}
|
||||
|
||||
public class Item implements UnmarshallerParameters {
|
||||
private Item(String prefix, JpaRepository repository, QName qName, Class cls, Class parentCls) {
|
||||
private Item(String prefix, JpaRepository repository, QName qName, Class cls, Class parentCls, int priority) {
|
||||
this.prefix = prefix;
|
||||
this.repository = repository;
|
||||
this.qName = qName;
|
||||
this.cls = cls;
|
||||
this.parentCls = parentCls;
|
||||
this.priority = priority;
|
||||
}
|
||||
private final String prefix;
|
||||
private final JpaRepository repository;
|
||||
private final QName qName;
|
||||
private final Class cls;
|
||||
private final Class parentCls;
|
||||
private final int priority;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -91,5 +93,10 @@ public class Catalog {
|
||||
public Class getParentCls() {
|
||||
return parentCls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,5 @@ public interface UnmarshallerParameters {
|
||||
public QName getQName();
|
||||
public Class getCls();
|
||||
public Class getParentCls();
|
||||
public int getPriority();
|
||||
}
|
||||
|
||||
@@ -18,10 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Predicate;
|
||||
@@ -107,12 +104,18 @@ public class UpdaterImpl implements UpdateHelper {
|
||||
|
||||
private void processArchive(File file, Predicate filter) throws CommonException {
|
||||
|
||||
//AddrObj - first
|
||||
//House - next
|
||||
//Other - last
|
||||
|
||||
try(final ZipFile zipFile = new ZipFile(file)){
|
||||
|
||||
log.debug("Process Zip file");
|
||||
|
||||
final Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
|
||||
|
||||
SortedMap<UnmarshallerParameters, ZipArchiveEntry> map = new TreeMap<>((l,r) -> r.getPriority() - l.getPriority());
|
||||
|
||||
while (entries.hasMoreElements()){
|
||||
|
||||
final ZipArchiveEntry entry = entries.nextElement();
|
||||
@@ -123,15 +126,22 @@ public class UpdaterImpl implements UpdateHelper {
|
||||
final UnmarshallerParameters config = catalog.getByPrefix(name);
|
||||
|
||||
if(config!=null) {
|
||||
try (InputStream is = zipFile.getInputStream(entry)) {
|
||||
log.debug("Process '{}' in zip", name);
|
||||
unmarshaller.process(is, config, filter);
|
||||
}
|
||||
|
||||
log.debug("Queue {} for processing", name);
|
||||
map.put(config, entry);
|
||||
|
||||
} else {
|
||||
log.debug("Skip '{}'", name);
|
||||
}
|
||||
}
|
||||
|
||||
map.forEach((config, entry) -> {
|
||||
try (InputStream is = zipFile.getInputStream(entry)) {
|
||||
log.debug("Process '{}' in zip", entry.getName());
|
||||
unmarshaller.process(is, config, filter);
|
||||
}
|
||||
});
|
||||
|
||||
log.debug("Completed Zip file");
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package me.bearns.fias.xml;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.bearns.fias.domain.Addrobj;
|
||||
import me.bearns.fias.repository.AddrobjRepository;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
public class AddrObjAdapter extends XmlAdapter<String, Addrobj> {
|
||||
|
||||
private static AddrobjRepository repository;
|
||||
@@ -15,11 +17,12 @@ 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
|
||||
|
||||
if(addrobj.aoid == null) {
|
||||
addrobj.aoid = aoguid;
|
||||
addrobj.aoguid = aoguid;
|
||||
//repository.save(addrobj);
|
||||
//repository.save(addrobj); //TODO FIX IT
|
||||
log.warn("AddresObject Entity for UUID {} not found, create new.", v);
|
||||
}
|
||||
|
||||
return addrobj;
|
||||
@@ -38,6 +41,6 @@ public class AddrObjAdapter extends XmlAdapter<String, Addrobj> {
|
||||
}
|
||||
|
||||
public static void setRepository(AddrobjRepository repo){
|
||||
repository = repo;
|
||||
if(repository == null) repository = repo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user