comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java @ 4724:c30152f77f77

ImportRiver: Refactoring, use description and year of da66parser.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 27 Dec 2012 16:14:41 +0100
parents 6016b9aa827a
children b0adce0592c9
comparison
equal deleted inserted replaced
4723:83304d3651ec 4724:c30152f77f77
885 } 885 }
886 }); 886 });
887 } 887 }
888 888
889 889
890 /** Add cross sections with description, years and lines to
891 * store. */
892 private void addCrossSections(CrossSectionParser parser) {
893 String description = parser.getDescription();
894 Integer year = parser.getYear();
895 ImportTimeInterval ti = year != null
896 ? new ImportTimeInterval(yearToDate(year))
897 : null;
898
899 List<ImportCrossSectionLine> lines =
900 new ArrayList<ImportCrossSectionLine>();
901
902 for (Map.Entry<Double, List<XY>> entry: parser.getData().entrySet()) {
903 Double km = entry.getKey();
904 List<XY> points = entry.getValue();
905 lines.add(new ImportCrossSectionLine(km, points));
906 }
907
908 crossSections.add(new ImportCrossSection(
909 ImportRiver.this, description, ti, lines));
910 }
911
912
890 /** Create a DA66 Parser and parse the da66 files found. */ 913 /** Create a DA66 Parser and parse the da66 files found. */
891 // TODO this is a copy of parsePRFs, extract interfaces (e.g. CrossSectionParser). 914 // TODO this is a copy of parsePRFs, extract interfaces (e.g. CrossSectionParser).
892 public void parseDA66s() { 915 public void parseDA66s() {
893 if (Config.INSTANCE.skipDA66s()) { 916 if (Config.INSTANCE.skipDA66s()) {
894 log.info("skip parsing DA66s"); 917 log.info("skip parsing DA66s");
918 941
919 @Override 942 @Override
920 public void parsed(CrossSectionParser parser) { 943 public void parsed(CrossSectionParser parser) {
921 log.debug("callback from DA66 parser"); 944 log.debug("callback from DA66 parser");
922 945
923 // TODO populate with real-world data 946 addCrossSections(parser);
924 String description = "dummy";//parser.getDescription();
925 Integer year = 2012;//parser.getYear();
926 ImportTimeInterval ti = year != null
927 ? new ImportTimeInterval(yearToDate(year))
928 : null;
929
930 List<ImportCrossSectionLine> lines =
931 new ArrayList<ImportCrossSectionLine>();
932
933 for (Map.Entry<Double, List<XY>> entry: parser.getData().entrySet()) {
934 Double km = entry.getKey();
935 List<XY> points = entry.getValue();
936 lines.add(new ImportCrossSectionLine(km, points));
937 }
938
939 crossSections.add(new ImportCrossSection(
940 ImportRiver.this, description, ti, lines));
941 } 947 }
942 }); 948 });
943 } 949 }
944 950
945 /** Create a PRFParser and let it parse the prf files found. */ 951 /** Create a PRFParser and let it parse the prf files found. */
973 979
974 @Override 980 @Override
975 public void parsed(CrossSectionParser parser) { 981 public void parsed(CrossSectionParser parser) {
976 log.debug("callback from PRF parser"); 982 log.debug("callback from PRF parser");
977 983
978 String description = parser.getDescription(); 984 addCrossSections(parser);
979 Integer year = parser.getYear();
980 ImportTimeInterval ti = year != null
981 ? new ImportTimeInterval(yearToDate(year))
982 : null;
983
984 List<ImportCrossSectionLine> lines =
985 new ArrayList<ImportCrossSectionLine>();
986
987 for (Map.Entry<Double, List<XY>> entry: parser.getData().entrySet()) {
988 Double km = entry.getKey();
989 List<XY> points = entry.getValue();
990 lines.add(new ImportCrossSectionLine(km, points));
991 }
992
993 crossSections.add(new ImportCrossSection(
994 ImportRiver.this, description, ti, lines));
995 } 985 }
996 }); 986 });
997 } 987 }
998 988
999 public static Date yearToDate(int year) { 989 public static Date yearToDate(int year) {

http://dive4elements.wald.intevation.org