fix UpdaterImpl for new UnmarshallerParameters interface
This commit is contained in:
@@ -5,6 +5,8 @@ import me.bearns.fias.exceptions.CommonException;
|
||||
import me.bearns.fias.exceptions.DownloadException;
|
||||
import me.bearns.fias.exceptions.UnzipException;
|
||||
import me.bearns.fias.repository.FiasVersionRepository;
|
||||
import me.bearns.fias.util.Catalog;
|
||||
import me.bearns.fias.util.UnmarshallerParameters;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -31,6 +33,9 @@ public class FiasUpdater implements Updater {
|
||||
@Autowired
|
||||
private static OnlineVersion clientStub;
|
||||
|
||||
@Autowired
|
||||
private static Catalog catalog;
|
||||
|
||||
@Override
|
||||
public void update() throws CommonException {
|
||||
|
||||
@@ -117,9 +122,11 @@ public class FiasUpdater implements Updater {
|
||||
|
||||
final ZipEntry entry = entries.nextElement();
|
||||
|
||||
if(check(entry)) { //todo
|
||||
final UnmarshallerParameters config = catalog.getByPrefix(entry.getName());
|
||||
|
||||
if(config!=null) { //todo
|
||||
try (InputStream is = zipFile.getInputStream(entry)) {
|
||||
unmarshaller.process(is, null, null);
|
||||
unmarshaller.process(is, config, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,9 +138,4 @@ public class FiasUpdater implements Updater {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean check(ZipEntry entry){
|
||||
//todo
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
package me.bearns.fias.service;
|
||||
|
||||
import me.bearns.fias.util.CatalogItem;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import me.bearns.fias.util.UnmarshallerParameters;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface StreamSaver {
|
||||
|
||||
public void process(InputStream is, CatalogItem conf, Predicate filter);
|
||||
public void process(InputStream is, UnmarshallerParameters conf, Predicate filter);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package me.bearns.fias.service;
|
||||
|
||||
import me.bearns.fias.util.CatalogItem;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import me.bearns.fias.util.UnmarshallerParameters;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
@@ -10,17 +9,15 @@ import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.events.Attribute;
|
||||
import javax.xml.stream.events.StartElement;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@Component
|
||||
public class StreamSaverImpl implements StreamSaver{
|
||||
@Override
|
||||
public void process(InputStream is, CatalogItem conf, Predicate filter) {
|
||||
public void process(InputStream is, UnmarshallerParameters conf, Predicate filter) {
|
||||
|
||||
try {
|
||||
// create xml event reader for input stream
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
package me.bearns.fias.util;
|
||||
|
||||
import me.bearns.fias.repository.FiasVersionRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class Catalog {
|
||||
|
||||
private final HashMap<String,Item> prefixMap = new HashMap<>();
|
||||
private final List<Item> prefixList = new ArrayList<>();
|
||||
|
||||
public Catalog(FiasVersionRepository FIASJPA_REPOSITORY) {
|
||||
prefixMap.put(
|
||||
"AS_ADDROBJ_",
|
||||
prefixList.add(
|
||||
new Item(
|
||||
"AS_ADDROBJ_",
|
||||
null,
|
||||
new QName("","Object"),
|
||||
null,
|
||||
null
|
||||
)
|
||||
);
|
||||
prefixMap.put(
|
||||
"AS_HOUSE_",
|
||||
prefixList.add(
|
||||
new Item(
|
||||
"AS_HOUSE_",
|
||||
null,
|
||||
new QName("","House"),
|
||||
null,
|
||||
@@ -35,17 +35,24 @@ public class Catalog {
|
||||
}
|
||||
|
||||
public Item getByPrefix(String s){
|
||||
return prefixMap.get(s);
|
||||
if(s!=null) {
|
||||
|
||||
for (Item item : prefixList) {
|
||||
if (s.startsWith(item.prefix)) return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public class Item implements CatalogItem{
|
||||
private Item(JpaRepository repository, QName qName, Class cls, Class parentCls) {
|
||||
public class Item implements UnmarshallerParameters {
|
||||
private Item(String prefix, JpaRepository repository, QName qName, Class cls, Class parentCls) {
|
||||
this.prefix = prefix;
|
||||
this.repository = repository;
|
||||
this.qName = qName;
|
||||
this.cls = cls;
|
||||
this.parentCls = parentCls;
|
||||
}
|
||||
|
||||
private final String prefix;
|
||||
private final JpaRepository repository;
|
||||
private final QName qName;
|
||||
private final Class cls;
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
public interface CatalogItem {
|
||||
public interface UnmarshallerParameters {
|
||||
public JpaRepository getRepository();
|
||||
public QName getQName();
|
||||
public Class getCls();
|
||||
Reference in New Issue
Block a user