Search in sources :

Example 46 with VersionData

use of com.sldeditor.common.vendoroption.VersionData in project sldeditor by robward-scisys.

the class VendorOptionInfoManagerTest method testAddVendorOptionInfo.

/**
 * Test method for
 * {@link com.sldeditor.common.vendoroption.info.VendorOptionInfoManager#addVendorOptionInfo(com.sldeditor.ui.detail.vendor.VendorOptionFactoryInterface)}.
 * {@link com.sldeditor.common.vendoroption.info.VendorOptionInfoManager#getPanel(java.lang.Class)}.
 * {@link com.sldeditor.common.vendoroption.info.VendorOptionInfoManager#setSelectedVersion(java.lang.Class, com.sldeditor.common.vendoroption.VersionData)}.
 */
@Test
public void testAddVendorOptionInfo() {
    VendorOptionInfoManager.getInstance().addVendorOptionInfo(null);
    VendorOptionFactoryInterface f1 = new VendorOptionFactoryInterface() {

        @Override
        public List<VendorOptionInterface> getVendorOptionList() {
            return null;
        }

        @Override
        public List<VendorOptionInterface> getVendorOptionList(String className) {
            return null;
        }

        @Override
        public List<VendorOptionInfo> getVendorOptionInfoList() {
            List<VendorOptionInfo> list = new ArrayList<VendorOptionInfo>();
            return list;
        }
    };
    VendorOptionInfoManager.getInstance().addVendorOptionInfo(f1);
    VendorOptionInfoManager.getInstance().addVendorOptionInfo(f1);
    VendorOptionInfoPanel panel1 = VendorOptionInfoManager.getInstance().getPanel(String.class);
    VendorOptionInfoPanel panel2 = VendorOptionInfoManager.getInstance().getPanel(Double.class);
    VendorOptionInfoPanel panel3 = VendorOptionInfoManager.getInstance().getPanel(String.class);
    assertTrue(panel1 == panel3);
    assertTrue(panel1 != panel2);
    VendorOptionInfoManager.getInstance().setSelectedVersion(null, null);
    VersionData versionData = VersionData.decode(GeoServerVendorOption.class, "3.1.4");
    VendorOptionInfoManager.getInstance().setSelectedVersion(String.class, versionData);
}
Also used : VendorOptionInfoPanel(com.sldeditor.common.vendoroption.info.VendorOptionInfoPanel) VersionData(com.sldeditor.common.vendoroption.VersionData) ArrayList(java.util.ArrayList) VendorOptionInfo(com.sldeditor.common.vendoroption.info.VendorOptionInfo) VendorOptionFactoryInterface(com.sldeditor.ui.detail.vendor.VendorOptionFactoryInterface) VendorOptionInterface(com.sldeditor.ui.detail.vendor.geoserver.VendorOptionInterface) Test(org.junit.Test)

Example 47 with VersionData

use of com.sldeditor.common.vendoroption.VersionData in project sldeditor by robward-scisys.

the class VendorOptionInfoModelTest method testAddVendorOptionInfo.

/**
 * Test method for {@link com.sldeditor.common.vendoroption.info.VendorOptionInfoModel#addVendorOptionInfo(java.util.List)}.
 */
@Test
public void testAddVendorOptionInfo() {
    VendorOptionInfoModel model = new VendorOptionInfoModel();
    assertEquals(0, model.getRowCount());
    model.addVendorOptionInfo(null);
    List<VendorOptionInfo> vendorOptionInfoList = new ArrayList<VendorOptionInfo>();
    String name = "name";
    VersionData versionDataMin = VersionData.decode(getClass(), "2.4.1");
    VersionData versionDataMax = VersionData.decode(getClass(), "2.8.3");
    VendorOptionVersion versionData = new VendorOptionVersion(GeoServerVendorOption.class, versionDataMin, versionDataMax);
    String description = "test description";
    VendorOptionInfo info = new VendorOptionInfo(name, versionData, description);
    vendorOptionInfoList.add(info);
    String name2 = "name2";
    String description2 = "test description2";
    VendorOptionVersion versionData2 = VendorOptionManager.getInstance().getDefaultVendorOptionVersion();
    vendorOptionInfoList.add(new VendorOptionInfo(name2, versionData2, description2));
    VersionData versionDataMin3 = VersionData.decode(getClass(), "2.8.1");
    VersionData versionDataMax3 = VersionData.decode(getClass(), "Latest");
    VendorOptionVersion versionData3 = new VendorOptionVersion(GeoServerVendorOption.class, versionDataMin3, versionDataMax3);
    String name3 = "name3";
    String description3 = "test description3";
    vendorOptionInfoList.add(new VendorOptionInfo(name3, versionData3, description3));
    model.addVendorOptionInfo(vendorOptionInfoList);
    assertEquals(vendorOptionInfoList.size(), model.getRowCount());
    assertNull(model.getValueAt(-1, 0));
    assertNull(model.getValueAt(-1, -1));
    assertNull(model.getValueAt(4, -1));
    assertNull(model.getValueAt(4, 4));
    assertEquals(name2, model.getValueAt(0, 0));
    assertEquals("Strict SLD", model.getValueAt(0, 1));
    assertEquals("GeoServer 2.4.1-2.8.3", model.getValueAt(1, 1));
    // Test get description
    assertNull(model.getDescription(-1));
    assertNull(model.getDescription(10));
    assertEquals(description2, model.getDescription(0));
    model.setSelectedVersion(VersionData.decode(getClass(), "2.5.1"));
    model.isVendorOptionAvailable(-1);
    model.isVendorOptionAvailable(42);
    model.isVendorOptionAvailable(1);
}
Also used : VersionData(com.sldeditor.common.vendoroption.VersionData) VendorOptionVersion(com.sldeditor.common.vendoroption.VendorOptionVersion) ArrayList(java.util.ArrayList) VendorOptionInfoModel(com.sldeditor.common.vendoroption.info.VendorOptionInfoModel) VendorOptionInfo(com.sldeditor.common.vendoroption.info.VendorOptionInfo) Test(org.junit.Test)

Example 48 with VersionData

use of com.sldeditor.common.vendoroption.VersionData in project sldeditor by robward-scisys.

the class VendorOptionMenuUtilsTest method testSetSelected.

/**
 * Test method for
 * {@link com.sldeditor.common.vendoroption.selection.VendorOptionMenuUtils#setSelected(com.sldeditor.ui.menucombobox.MenuComboBox, com.sldeditor.common.vendoroption.VersionData)}.
 */
@Test
public void testSetSelected() {
    VendorOptionMenuUtils.setSelected(null, null);
    List<VersionData> listVersionData = new ArrayList<VersionData>();
    listVersionData.add(VersionData.decode(GeoServerVendorOption.class, "1.3.1"));
    VersionData expectedVersionData1 = VersionData.decode(GeoServerVendorOption.class, "1.2.0");
    listVersionData.add(expectedVersionData1);
    listVersionData.add(VersionData.decode(GeoServerVendorOption.class, "1.3.99"));
    listVersionData.add(VersionData.decode(GeoServerVendorOption.class, "1.4.5"));
    listVersionData.add(VersionData.decode(GeoServerVendorOption.class, "1.4.1"));
    listVersionData.add(VersionData.decode(GeoServerVendorOption.class, "1.3.3"));
    listVersionData.add(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData());
    // Expecting:
    // Not Set
    // 1.2.0
    // 1.3.x - 1.3.1, 1.3.3, 1.3.99
    // 1.4.x - 1.4.1, 1.4.5
    @SuppressWarnings("unused") List<ValueComboBoxDataGroup> actual = VendorOptionMenuUtils.createMenu(listVersionData);
    VendorOptionMenuUtils.setSelected(null, expectedVersionData1);
    VendorOptionMenuUtils.setSelected(null, VendorOptionManager.getInstance().getDefaultVendorOptionVersionData());
}
Also used : ValueComboBoxDataGroup(com.sldeditor.ui.widgets.ValueComboBoxDataGroup) GeoServerVendorOption(com.sldeditor.common.vendoroption.GeoServerVendorOption) VersionData(com.sldeditor.common.vendoroption.VersionData) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 49 with VersionData

use of com.sldeditor.common.vendoroption.VersionData in project sldeditor by robward-scisys.

the class SLDTestRunner method runTest.

/**
 * Run the test.
 *
 * @param folder the folder
 * @param testConfig the test config
 */
public void runTest(String folder, String testConfig) {
    // read JSON file data as String
    String fullPath = "/" + folder + "/test/" + testConfig;
    SldEditorTest testSuite = (SldEditorTest) ParseXML.parseFile("", fullPath, SCHEMA_RESOURCE, SldEditorTest.class);
    Assert.assertNotNull("Failed to read test config file : " + fullPath, testSuite);
    String testsldfile = testSuite.getTestsldfile();
    if (!testsldfile.startsWith("/")) {
        testsldfile = "/" + testsldfile;
    }
    System.out.println("Opening : " + testsldfile);
    List<XMLVendorOption> xmlVendorOptionList = testSuite.getVendorOption();
    List<VersionData> versionDataList = new ArrayList<VersionData>();
    if ((xmlVendorOptionList != null) && !xmlVendorOptionList.isEmpty()) {
        for (XMLVendorOption vo : xmlVendorOptionList) {
            VersionData versionData = ReadPanelConfig.decodeVersionData(vo);
            versionDataList.add(versionData);
        }
    }
    // If in doubt revert to strict SLD
    if (versionDataList.isEmpty()) {
        versionDataList.add(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData());
    }
    sldEditor.setVendorOptions(versionDataList);
    InputStream inputStream = SLDTestRunner.class.getResourceAsStream(testsldfile);
    if (inputStream == null) {
        Assert.assertNotNull("Failed to find sld test file : " + testsldfile, inputStream);
    } else {
        File f = null;
        try {
            f = stream2file(inputStream);
            int noOfRetries = 3;
            int attempt = 0;
            while (attempt < noOfRetries) {
                try {
                    sldEditor.openFile(f.toURI().toURL());
                    break;
                } catch (NullPointerException nullException) {
                    nullException.printStackTrace();
                    StackTraceElement[] stackTraceElements = nullException.getStackTrace();
                    System.out.println(stackTraceElements[0].getMethodName());
                    System.out.println("Attempt : " + attempt + 1);
                    attempt++;
                }
            }
            f.delete();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        GraphicPanelFieldManager mgr = sldEditor.getFieldDataManager();
        for (XMLPanelTest test : testSuite.getPanelTests()) {
            XMLSetup selectedItem = test.getSetup();
            TreeSelectionData selectionData = new TreeSelectionData();
            selectionData.setLayerIndex(getXMLValue(selectedItem.getLayer()));
            selectionData.setStyleIndex(getXMLValue(selectedItem.getStyle()));
            selectionData.setFeatureTypeStyleIndex(getXMLValue(selectedItem.getFeatureTypeStyle()));
            selectionData.setRuleIndex(getXMLValue(selectedItem.getRule()));
            selectionData.setSymbolizerIndex(getXMLValue(selectedItem.getSymbolizer()));
            selectionData.setSymbolizerDetailIndex(getXMLValue(selectedItem.getSymbolizerDetail()));
            try {
                selectionData.setSelectedPanel(Class.forName(selectedItem.getExpectedPanel()));
            } catch (ClassNotFoundException e1) {
                Assert.fail("Unknown class : " + selectedItem.getExpectedPanel());
            }
            boolean result = sldEditor.selectTreeItem(selectionData);
            Assert.assertTrue("Failed to select tree item", result);
            PopulateDetailsInterface panel = sldEditor.getSymbolPanel();
            String panelClassName = panel.getClass().getName();
            Assert.assertEquals(panelClassName, selectedItem.getExpectedPanel());
            Assert.assertEquals("Check panel data present", panel.isDataPresent(), selectedItem.getEnabled());
            Class<?> panelId = null;
            try {
                panelId = Class.forName(selectedItem.getExpectedPanel());
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            if (test.getFieldTests() != null) {
                for (XMLFieldTest testItem : test.getFieldTests()) {
                    if (testItem != null) {
                        if (testItem.getDisabledOrLiteralStringOrLiteralInt() != null) {
                            for (Object xmlTestValueObj : testItem.getDisabledOrLiteralStringOrLiteralInt()) {
                                if (xmlTestValueObj instanceof XMLSetMultiOptionGroup) {
                                    XMLSetMultiOptionGroup testValue = (XMLSetMultiOptionGroup) xmlTestValueObj;
                                    GroupIdEnum groupId = testValue.getMultiOptionGroupId();
                                    String outputText = "Checking multioption group : " + groupId;
                                    System.out.println(outputText);
                                    Assert.assertNotNull(outputText, groupId);
                                    MultiOptionGroup multiOptionGroup = mgr.getMultiOptionGroup(panelId, groupId);
                                    Assert.assertNotNull(panelId.getName() + "/" + groupId + " multi option group should exist", multiOptionGroup);
                                    multiOptionGroup.setOption(testValue.getOption());
                                    OptionGroup optionGroupSelected = multiOptionGroup.getSelectedOptionGroup();
                                    Assert.assertTrue(groupId + " should be set", optionGroupSelected.getId() == testValue.getOption());
                                } else if (xmlTestValueObj instanceof XMLSetGroup) {
                                    XMLSetGroup testValue = (XMLSetGroup) xmlTestValueObj;
                                    GroupIdEnum groupId = testValue.getGroupId();
                                    String outputText = "Checking group : " + groupId;
                                    System.out.println(outputText);
                                    Assert.assertNotNull(outputText, groupId);
                                    GroupConfigInterface groupConfig = mgr.getGroup(panelId, groupId);
                                    Assert.assertNotNull(panelId.getName() + "/" + groupId + " group should exist", groupConfig);
                                    groupConfig.enable(testValue.getEnable());
                                    Assert.assertTrue(groupId + " should be set", groupConfig.isPanelEnabled() == testValue.getEnable());
                                } else {
                                    XMLFieldBase testValue = (XMLFieldBase) xmlTestValueObj;
                                    FieldIdEnum fieldId = testValue.getField();
                                    String outputText = "Checking : " + fieldId;
                                    System.out.println(outputText);
                                    Assert.assertNotNull(outputText, fieldId);
                                    try {
                                        Thread.sleep(100);
                                    } catch (InterruptedException e) {
                                        e.printStackTrace();
                                    }
                                    FieldConfigBase fieldConfig = mgr.getData(panelId, fieldId);
                                    Assert.assertNotNull(String.format("Failed to field panel %s field %s", selectedItem.getExpectedPanel(), fieldId), fieldConfig);
                                    if (testValue instanceof XMLSetFieldLiteralBase) {
                                        XMLSetFieldLiteralInterface testInterface = (XMLSetFieldLiteralInterface) testValue;
                                        testInterface.accept(fieldConfig, fieldId);
                                        if (!((XMLSetFieldLiteralBase) testValue).getIgnoreCheck()) {
                                            String sldContentString = sldEditor.getSLDString();
                                            boolean actualResult = testOutput.testValue(sldContentString, selectionData, testValue.getField(), testValue);
                                            Assert.assertTrue(fieldId + " should be set", actualResult);
                                        }
                                    } else if (testValue instanceof XMLSetFieldAttribute) {
                                        XMLSetFieldLiteralInterface testInterface = (XMLSetFieldLiteralInterface) testValue;
                                        testInterface.accept(fieldConfig, fieldId);
                                        String sldContentString = sldEditor.getSLDString();
                                        boolean actualResult = testOutput.testAttribute(sldContentString, selectionData, testValue.getField(), (XMLSetFieldAttribute) testValue);
                                        Assert.assertTrue(fieldId + " should be set", actualResult);
                                    } else if (testValue instanceof XMLFieldDisabled) {
                                        Assert.assertFalse(fieldId + " should be disabled", fieldConfig.isEnabled());
                                    } else {
                                        Assert.assertTrue(fieldId + " should be enabled", fieldConfig.isEnabled());
                                        Expression expression = null;
                                        if (fieldConfig.isValueOnly()) {
                                            String expectedValue = "";
                                            if (testValue instanceof XMLFieldLiteralBase) {
                                                Object literalValue = getLiteralValue((XMLFieldLiteralBase) testValue);
                                                expectedValue = String.valueOf(literalValue);
                                                if (fieldId == FieldIdEnum.TTF_SYMBOL) {
                                                    expectedValue = processTTFField(expectedValue).toString();
                                                }
                                            } else if (testValue instanceof XMLFieldAttribute) {
                                                expectedValue = ((XMLFieldAttribute) testValue).getAttribute();
                                            // CHECKSTYLE:OFF
                                            } else if (testValue instanceof XMLFieldExpression) {
                                                expectedValue = ((XMLFieldExpression) testValue).getExpression();
                                            } else if (testValue instanceof XMLColourMapEntries) {
                                                expectedValue = EncodeColourMap.encode(((XMLColourMapEntries) testValue).getEntry());
                                            // CHECKSTYLE:ON
                                            } else {
                                                Assert.fail(fieldId + " has unsupported type " + testValue.getClass().getName());
                                            }
                                            String actualValue = fieldConfig.getStringValue();
                                            String msg = String.format("%s Expected : '%s' Actual : '%s'", outputText, expectedValue, actualValue);
                                            boolean condition;
                                            if (comparingFilename(fieldId)) {
                                                File actualFile = new File(actualValue);
                                                File expectedFile = new File(expectedValue);
                                                String actualFileString = actualFile.getAbsolutePath();
                                                String expectedFileString = expectedFile.getAbsolutePath();
                                                expectedFileString = expectedFileString.substring(expectedFileString.length() - expectedValue.length());
                                                condition = actualFileString.endsWith(expectedFileString);
                                            } else {
                                                condition = (expectedValue.compareTo(actualValue) == 0);
                                            }
                                            Assert.assertTrue(msg, condition);
                                        } else {
                                            if (colourFieldsList.contains(fieldId)) {
                                                FieldConfigColour fieldColour = (FieldConfigColour) fieldConfig;
                                                expression = fieldColour.getColourExpression();
                                            } else {
                                                expression = fieldConfig.getExpression();
                                                if (fieldId == FieldIdEnum.SYMBOL_TYPE) {
                                                    String string = expression.toString();
                                                    expression = ff.literal(string.replace(File.separatorChar, '/'));
                                                } else if (fieldId == FieldIdEnum.FONT_FAMILY) {
                                                    // Handle the case where a font is not
                                                    // available on all operating systems
                                                    String string = expression.toString();
                                                    if (string.compareToIgnoreCase(DEFAULT_FONT) != 0) {
                                                        expression = ff.literal(getFontForOS());
                                                        // CHECKSTYLE:OFF
                                                        System.out.println("Updated font family to test for : " + expression.toString());
                                                    // CHECKSTYLE:ON
                                                    }
                                                } else if (fieldId == FieldIdEnum.TTF_SYMBOL) {
                                                    expression = processTTFField(expression.toString());
                                                }
                                            }
                                            if (expression != null) {
                                                if (testValue instanceof XMLFieldLiteralBase) {
                                                    Object literalValue = getLiteralValue((XMLFieldLiteralBase) testValue);
                                                    if (literalValue.getClass() == Double.class) {
                                                        checkLiteralValue(outputText, expression, (Double) literalValue);
                                                    } else if (literalValue.getClass() == Integer.class) {
                                                        checkLiteralValue(outputText, expression, (Integer) literalValue);
                                                    } else if (literalValue.getClass() == String.class) {
                                                        // CHECKSTYLE:OFF
                                                        if (fieldId == FieldIdEnum.FONT_FAMILY) {
                                                            // Handle the case where a font is not
                                                            // available on all operating systems
                                                            // CHECKSTYLE:ON
                                                            checkLiteralValue(outputText, expression, getFontForOS());
                                                        } else {
                                                            checkLiteralValue(outputText, expression, (String) literalValue);
                                                        }
                                                    }
                                                }
                                            } else {
                                                String actualValue;
                                                String expectedValue = fieldConfig.getStringValue();
                                                Object literalValue = getLiteralValue((XMLFieldLiteralBase) testValue);
                                                if (literalValue.getClass() == Double.class) {
                                                    actualValue = String.valueOf((Double) literalValue);
                                                } else if (literalValue.getClass() == Integer.class) {
                                                    actualValue = String.valueOf((Integer) literalValue);
                                                } else if (literalValue.getClass() == String.class) {
                                                    actualValue = (String) literalValue;
                                                } else {
                                                    actualValue = "";
                                                }
                                                String msg = String.format("%s Expected : '%s' Actual : '%s'", outputText, expectedValue, actualValue);
                                                boolean condition = (expectedValue.compareTo(actualValue) == 0);
                                                Assert.assertTrue(msg, condition);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    JFrame frame = sldEditor.getApplicationFrame();
    frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
}
Also used : XMLPanelTest(com.sldeditor.common.xml.ui.XMLPanelTest) XMLFieldDisabled(com.sldeditor.common.xml.ui.XMLFieldDisabled) XMLSetFieldLiteralBase(com.sldeditor.common.xml.ui.XMLSetFieldLiteralBase) SldEditorTest(com.sldeditor.common.xml.ui.SldEditorTest) ArrayList(java.util.ArrayList) XMLFieldLiteralString(com.sldeditor.common.xml.ui.XMLFieldLiteralString) XMLSetFieldLiteralInterface(com.sldeditor.common.xml.ui.XMLSetFieldLiteralInterface) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) PopulateDetailsInterface(com.sldeditor.ui.iface.PopulateDetailsInterface) XMLFieldBase(com.sldeditor.common.xml.ui.XMLFieldBase) OptionGroup(com.sldeditor.ui.detail.config.base.OptionGroup) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) XMLSetMultiOptionGroup(com.sldeditor.common.xml.ui.XMLSetMultiOptionGroup) JFrame(javax.swing.JFrame) XMLSetFieldAttribute(com.sldeditor.common.xml.ui.XMLSetFieldAttribute) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) XMLSetMultiOptionGroup(com.sldeditor.common.xml.ui.XMLSetMultiOptionGroup) XMLSetup(com.sldeditor.common.xml.ui.XMLSetup) GroupIdEnum(com.sldeditor.common.xml.ui.GroupIdEnum) XMLFieldAttribute(com.sldeditor.common.xml.ui.XMLFieldAttribute) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) XMLVendorOption(com.sldeditor.common.xml.ui.XMLVendorOption) InputStream(java.io.InputStream) XMLColourMapEntries(com.sldeditor.common.xml.ui.XMLColourMapEntries) IOException(java.io.IOException) XMLSetMultiOptionGroup(com.sldeditor.common.xml.ui.XMLSetMultiOptionGroup) XMLFieldLiteralDouble(com.sldeditor.common.xml.ui.XMLFieldLiteralDouble) XMLFieldExpression(com.sldeditor.common.xml.ui.XMLFieldExpression) Expression(org.opengis.filter.expression.Expression) XMLFieldExpression(com.sldeditor.common.xml.ui.XMLFieldExpression) XMLFieldLiteralBase(com.sldeditor.common.xml.ui.XMLFieldLiteralBase) VersionData(com.sldeditor.common.vendoroption.VersionData) XMLFieldTest(com.sldeditor.common.xml.ui.XMLFieldTest) TreeSelectionData(com.sldeditor.TreeSelectionData) WindowEvent(java.awt.event.WindowEvent) XMLSetGroup(com.sldeditor.common.xml.ui.XMLSetGroup) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) File(java.io.File)

Example 50 with VersionData

use of com.sldeditor.common.vendoroption.VersionData in project sldeditor by robward-scisys.

the class CheckUpdateGitHub method check.

/**
 * Check.
 *
 * @param jsonString the json string
 * @return the update data
 */
protected UpdateData check(String jsonString) {
    if (jsonString == null) {
        return null;
    }
    if (jsonString.isEmpty()) {
        return null;
    }
    try {
        JsonParser parser = new JsonParser();
        JsonArray o = parser.parse(jsonString).getAsJsonArray();
        Map<Calendar, String> map = new HashMap<Calendar, String>();
        Map<Calendar, JsonObject> jsonMap = new HashMap<Calendar, JsonObject>();
        Map<String, String> descriptionMap = new HashMap<String, String>();
        List<Calendar> calList = new ArrayList<Calendar>();
        for (int index = 0; index < o.size(); index++) {
            JsonObject obj = o.get(index).getAsJsonObject();
            String tagName = obj.get(TAG_NAME).getAsString();
            if (tagName.startsWith(TAG_PREFIX)) {
                tagName = tagName.substring(1);
            }
            String published = obj.get(PUBLISHED_AT).getAsString();
            Calendar cal = ISO8601toCalendar(published);
            map.put(cal, tagName);
            jsonMap.put(cal, obj);
            calList.add(cal);
            descriptionMap.put(tagName, obj.get(BODY).getAsString());
        }
        Collections.sort(calList, Collections.reverseOrder());
        Calendar latestTime = calList.get(0);
        String latest = map.get(latestTime);
        StringBuilder description = new StringBuilder();
        for (Calendar time : calList) {
            String tag = map.get(time);
            formatDescription(description, tag, descriptionMap.get(tag));
        }
        VersionData latestVersion = VersionData.decode(getClass(), latest);
        UpdateData updateData = new UpdateData(latestVersion, description.toString());
        return updateData;
    } catch (ParseException e) {
        ConsoleManager.getInstance().exception(this, e);
    } catch (IllegalStateException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    return null;
}
Also used : HashMap(java.util.HashMap) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) VersionData(com.sldeditor.common.vendoroption.VersionData) ParseException(java.text.ParseException) JsonParser(com.google.gson.JsonParser)

Aggregations

VersionData (com.sldeditor.common.vendoroption.VersionData)56 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)26 VendorOptionVersion (com.sldeditor.common.vendoroption.VendorOptionVersion)13 GeoServerVendorOption (com.sldeditor.common.vendoroption.GeoServerVendorOption)9 PrefData (com.sldeditor.common.preferences.PrefData)7 VendorOptionInfo (com.sldeditor.common.vendoroption.info.VendorOptionInfo)5 Color (java.awt.Color)5 SLDData (com.sldeditor.common.data.SLDData)4 VendorOptionTypeInterface (com.sldeditor.common.vendoroption.VendorOptionTypeInterface)4 File (java.io.File)4 VendorOptionTableModel (com.sldeditor.common.vendoroption.selection.VendorOptionTableModel)3 ValueComboBoxDataGroup (com.sldeditor.ui.widgets.ValueComboBoxDataGroup)3 IOException (java.io.IOException)3 LinkedHashMap (java.util.LinkedHashMap)3 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)2 StyleWrapper (com.sldeditor.common.data.StyleWrapper)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1