Package com.sonyericsson.hudson.plugins.metadata.model.values

Examples of com.sonyericsson.hudson.plugins.metadata.model.values.DateMetadataValue


        PluginImpl.getInstance().setDefinitions(list);
        FreeStyleProject freeStyleProject = createFreeStyleProject();
        configRoundtrip(freeStyleProject);
        MetadataJobProperty property = freeStyleProject.getProperty(MetadataJobProperty.class);
        assertNotNull("No MetadataJobProperty", property);
        DateMetadataValue dateValue = (DateMetadataValue)TreeStructureUtil.getLeaf(property, "date");
        assertNotNull(dateValue);
        assertEquals(def.getHour(), dateValue.getHour());
        assertEquals(def.getMinute(), dateValue.getMinute());
        assertEquals(def.getSecond(), dateValue.getSecond());
        assertEquals(def.getDay(), dateValue.getDay());
        assertEquals(def.getMonth(), dateValue.getMonth());
        assertEquals(def.getYear(), dateValue.getYear());
    }
View Full Code Here


    }

    @Override
    public AbstractMetadataValue createValue(Object o) throws Descriptor.FormException {
        boolean detailsCheck = false;
        DateMetadataValue dateMetadataValue;
        Calendar cal = Calendar.getInstance();
        MetadataChecks checks = new MetadataChecks();

        if (o instanceof JSONObject) {
            String day = "";
            String month = "";
            String year = "";
            JSONObject jsonObject = (JSONObject)o;
            if (jsonObject.has("day")) {
                day = jsonObject.getString("day");
            }
            if (jsonObject.has("month")) {
                month = jsonObject.getString("month");
            }
            if (jsonObject.has("year")) {
                year = jsonObject.getString("year");
            }
            FormValidation dateValidation = checks.doCheckDateValue(year, month, day);
            if (!dateValidation.equals(FormValidation.ok())) {
                throw new Descriptor.FormException("Wrong date format " + dateValidation.getMessage(), "");
            }
            cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day));
            cal.set(Calendar.MONTH, Integer.parseInt(month) - DEFAULT_MONTH_ADJUSTMENT);
            cal.set(Calendar.YEAR, Integer.parseInt(year));


            if (jsonObject.has("details")) {
                String hour = "";
                String minute = "";
                String second = "";
                detailsCheck = true;
                JSONObject details = jsonObject.getJSONObject("details");
                if (details.has("hour")) {
                    hour = details.getString("hour");
                }
                if (details.has("minute")) {
                    minute = details.getString("minute");
                }
                if (details.has("second")) {
                    second = details.getString("second");
                }
                FormValidation timeValidation = checks.doCheckTimeValue(hour, minute, second);
                if (!timeValidation.equals(FormValidation.ok())) {
                    throw new Descriptor.FormException("Wrong time format: " + timeValidation.getMessage(), "");
                }
                cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hour));
                cal.set(Calendar.MINUTE, Integer.parseInt(minute));
                cal.set(Calendar.SECOND, Integer.parseInt(second));
            } else {
                cal.set(Calendar.HOUR_OF_DAY, 0);
                cal.set(Calendar.MINUTE, 0);
                cal.set(Calendar.SECOND, 0);
            }
            cal.set(Calendar.MILLISECOND, 0);
            dateMetadataValue = new DateMetadataValue(getName(), getDescription(),
                    cal, detailsCheck, isExposedToEnvironment());
        } else {
            //maybe we should throw an exception here instead of going with default.
            dateMetadataValue = new DateMetadataValue(getName(), getDescription(),
                    getDefaultValue(), detailsCheck, isExposedToEnvironment());
        }
        return dateMetadataValue;
    }
View Full Code Here

TOP

Related Classes of com.sonyericsson.hudson.plugins.metadata.model.values.DateMetadataValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.