comparison artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java @ 7697:640342d9ab8a

(issue1649) Remove broken getWKms from RiverUtils and use WDifferencesState instead This was basically duplicated code but only the code in WDifferenceState was maintained and extended. Another RiverUtils function bites the dust.
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 16 Dec 2013 16:24:07 +0100
parents feb23ab736f4
children 4daaf5e51dfb
comparison
equal deleted inserted replaced
7696:feb23ab736f4 7697:640342d9ab8a
721 WINFOArtifact winfo, 721 WINFOArtifact winfo,
722 CallContext context) 722 CallContext context)
723 { 723 {
724 State state = winfo.getCurrentState(context); 724 State state = winfo.getCurrentState(context);
725 if(state instanceof WDifferencesState) { 725 if(state instanceof WDifferencesState) {
726 WDifferencesState wState = (WDifferencesState) state;
727
726 String diffids = winfo.getDataAsString("diffids"); 728 String diffids = winfo.getDataAsString("diffids");
727 String datas[] = diffids.split("#"); 729 String datas[] = diffids.split("#");
728 730
729 // Validate the Data-Strings. 731 // Validate the Data-Strings.
730 for (String s: datas) { 732 for (String s: datas) {
739 741
740 String diffs = ""; 742 String diffs = "";
741 for(int i = 0; i < datas.length; i+=2) { 743 for(int i = 0; i < datas.length; i+=2) {
742 // e.g.: 744 // e.g.:
743 // 42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;1 745 // 42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;1
744 WKms minuendWKms = getWKms(StringUtil.unbracket(datas[i+0]), 746 WKms minuendWKms = wState.getWKms(StringUtil.unbracket(datas[i+0]),
745 context); 747 context);
746 WKms subtrahendWKms = getWKms(StringUtil.unbracket(datas[i+1]), 748 WKms subtrahendWKms = wState.getWKms(StringUtil.unbracket(datas[i+1]),
747 context); 749 context);
748 if (minuendWKms != null && subtrahendWKms != null) { 750 if (minuendWKms != null && subtrahendWKms != null) {
749 diffs += StringUtil.wWrap(minuendWKms.getName()) 751 diffs += StringUtil.wWrap(minuendWKms.getName())
750 + " - " + StringUtil.wWrap(subtrahendWKms.getName()); 752 + " - " + StringUtil.wWrap(subtrahendWKms.getName());
751 } 753 }
756 else { 758 else {
757 logger.warn("Not a valid state for differences."); 759 logger.warn("Not a valid state for differences.");
758 return ""; 760 return "";
759 } 761 }
760 } 762 }
761
762
763 protected static WKms getWKms(String mingle, CallContext context) {
764 String[] def = mingle.split(";");
765 String uuid = def[0];
766 String name = def[1];
767 int idx = Integer.parseInt(def[2]);
768
769 if (name.startsWith("staticwkms")) {
770 StaticWKmsArtifact staticWKms =
771 (StaticWKmsArtifact) RiverUtils.getArtifact(
772 uuid,
773 context);
774 WKms wkms = staticWKms.getWKms(idx);
775 if (wkms == null)
776 logger.error("No WKms from artifact.");
777 return wkms;
778 }
779
780 WINFOArtifact flys = (WINFOArtifact) RiverUtils.getArtifact(
781 uuid,
782 context);
783
784 if (flys == null) {
785 logger.warn("One of the artifacts (1) for diff calculation could not be loaded");
786 return null;
787 }
788 else{
789 Object data = flys.getWaterlevelData(context).getData();
790
791 if (data == null) {
792 logger.error("No waterlevel Data in artifact");
793 return null;
794 }
795
796 if (data instanceof WQKms[]) {
797 WQKms[] wqkms = (WQKms[]) data;
798 if (wqkms.length < idx) {
799 logger.error("not enough waterlevels in artifact");
800 return null;
801 }
802 return wqkms[idx];
803 } else if (data instanceof WKms[]) {
804 WKms[] wkms = (WKms[]) data;
805 if (wkms.length < idx) {
806 logger.error("not enough wkms in artifact");
807 return null;
808 }
809 return wkms[idx];
810 }
811
812 logger.error("unknown Waterlevel Data.");
813 return null;
814 }
815 }
816
817 763
818 /** 764 /**
819 * Transform a string into an int array. Therefore, the string 765 * Transform a string into an int array. Therefore, the string
820 * <i>raw</i> must consist of int values separated by a <i>';'</i>. 766 * <i>raw</i> must consist of int values separated by a <i>';'</i>.
821 * 767 *

http://dive4elements.wald.intevation.org