Example usage for org.joda.time DateTimeZone forID

List of usage examples for org.joda.time DateTimeZone forID

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone forID.

Prototype

@FromString
public static DateTimeZone forID(String id) 

Source Link

Document

Gets a time zone instance for the specified time zone id.

Usage

From source file:org.gephi.io.importer.plugin.file.ImporterGEXF.java

License:Open Source License

private void readGraph(XMLStreamReader reader) throws Exception {
    String mode = "";
    String defaultEdgeType = "";
    String timeFormat = "";
    String timeRepresentation = "";
    String timeZone = "";
    String timestamp = "";
    String start = "";
    String end = "";
    String idType = "";

    //Attributes/* w  ww  .  ja va2  s. c o  m*/
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attName = reader.getAttributeName(i).getLocalPart();
        if (GRAPH_DEFAULT_EDGETYPE.equalsIgnoreCase(attName)) {
            defaultEdgeType = reader.getAttributeValue(i);
        } else if (ATTRIBUTES_TYPE2.equalsIgnoreCase(attName)) {
            mode = reader.getAttributeValue(i);
        } else if (GRAPH_TIMEFORMAT.equalsIgnoreCase(attName) || GRAPH_TIMEFORMAT2.equalsIgnoreCase(attName)) {
            timeFormat = reader.getAttributeValue(i);
        } else if (GRAPH_TIMEREPRESENTATION.equalsIgnoreCase(attName)) {
            timeRepresentation = reader.getAttributeValue(i);
        } else if (GRAPH_TIMEZONE.equalsIgnoreCase(attName)) {
            timeZone = reader.getAttributeValue(i);
        } else if (TIMESTAMP.equalsIgnoreCase(attName)) {
            timestamp = reader.getAttributeValue(i);
        } else if (START.equalsIgnoreCase(attName)) {
            start = reader.getAttributeValue(i);
        } else if (END.equalsIgnoreCase(attName)) {
            end = reader.getAttributeValue(i);
        } else if (GRAPH_IDTYPE.equals(attName)) {
            idType = reader.getAttributeValue(i);
        }
    }

    //Edge Type
    if (!defaultEdgeType.isEmpty()) {
        if (defaultEdgeType.equalsIgnoreCase("undirected")) {
            container.setEdgeDefault(EdgeDirectionDefault.UNDIRECTED);
        } else if (defaultEdgeType.equalsIgnoreCase("directed")) {
            container.setEdgeDefault(EdgeDirectionDefault.DIRECTED);
        } else if (defaultEdgeType.equalsIgnoreCase("mutual")) {
            report.logIssue(new Issue(NbBundle.getMessage(ImporterGEXF.class, "importerGEXF_error_edgedouble"),
                    Issue.Level.WARNING));
        } else {
            report.logIssue(new Issue(NbBundle.getMessage(ImporterGEXF.class,
                    "importerGEXF_error_defaultedgetype", defaultEdgeType), Issue.Level.SEVERE));
        }
    }

    //TimeFormat
    if (!timeFormat.isEmpty()) {
        if ("double".equalsIgnoreCase(timeFormat) || "float".equalsIgnoreCase(timeFormat)) {
            container.setTimeFormat(TimeFormat.DOUBLE);
        } else if ("date".equalsIgnoreCase(timeFormat)) {
            container.setTimeFormat(TimeFormat.DATE);
        } else if ("datetime".equalsIgnoreCase(timeFormat)) {
            container.setTimeFormat(TimeFormat.DATETIME);
        } else if ("timestamp".equalsIgnoreCase(timeFormat)) {
            container.setTimeFormat(TimeFormat.DATETIME);
        }
    } else if (mode.equalsIgnoreCase("dynamic")) {
        container.setTimeFormat(TimeFormat.DOUBLE);
    }

    //TimeRepresentation
    if (!timeRepresentation.isEmpty()) {
        if ("timestamp".equalsIgnoreCase(timeRepresentation)) {
            container.setTimeRepresentation(TimeRepresentation.TIMESTAMP);
        } else if ("interval".equalsIgnoreCase(timeRepresentation)) {
            container.setTimeRepresentation(TimeRepresentation.INTERVAL);
        }
    }

    //Timezone
    if (!timeZone.isEmpty()) {
        try {
            container.setTimeZone(DateTimeZone.forID(timeZone));
        } catch (IllegalArgumentException e) {
            report.logIssue(
                    new Issue(NbBundle.getMessage(ImporterGEXF.class, "importerGEXF_error_timezone_parseerror"),
                            Issue.Level.SEVERE));
        }
    }

    // Slice
    if (!mode.isEmpty() && mode.equalsIgnoreCase("slice")) {
        if (timestamp.isEmpty() && (start.isEmpty() && end.isEmpty())) {
            report.logIssue(
                    new Issue(NbBundle.getMessage(ImporterGEXF.class, "importerGEXF_error_slice_bound_missing"),
                            Issue.Level.SEVERE));
        }

        if (!timestamp.isEmpty() && checkTimerepresentationIsTimestamp()) {
            container.setTimestamp(timestamp);
        }

        // Interval
        if ((!start.isEmpty() || !end.isEmpty()) && checkTimerepresentationIsInterval()) {
            container.setInterval(start, end);
        }
    }

    //Id type
    if (!idType.isEmpty()) {
        if (idType.equalsIgnoreCase("integer")) {
            container.setElementIdType(ElementIdType.INTEGER);
        } else if (idType.equalsIgnoreCase("long")) {
            container.setElementIdType(ElementIdType.LONG);
        } else if (idType.equalsIgnoreCase("string")) {
            container.setElementIdType(ElementIdType.STRING);
        } else {
            report.logIssue(new Issue(
                    NbBundle.getMessage(ImporterGEXF.class, "importerGEXF_error_idtype_error", idType),
                    Issue.Level.SEVERE));
        }
    }
}

From source file:org.graylog.plugins.pipelineprocessor.functions.dates.TimezoneAwareFunction.java

License:Open Source License

protected TimezoneAwareFunction() {
    timeZoneParam = ParameterDescriptor.string(TIMEZONE, DateTimeZone.class)
            .transform(id -> DateTimeZone
                    .forID(UPPER_ZONE_MAP.getOrDefault(id.toUpperCase(Locale.ENGLISH), "UTC")))
            .optional().description("The timezone to apply to the date, defaults to UTC").build();
}

From source file:org.graylog2.inputs.converters.AbstractDateConverter.java

License:Open Source License

private static DateTimeZone buildTimeZone(Object timeZoneId) {
    if (timeZoneId instanceof String) {
        try {/*from www .  j a  v a 2  s  .c  om*/
            final String timeZoneString = (String) timeZoneId;
            final String zoneId = firstNonNull(emptyToNull(timeZoneString.trim()), "Etc/UTC");
            return DateTimeZone.forID(zoneId);
        } catch (IllegalArgumentException e) {
            return DEFAULT_TIME_ZONE;
        }
    } else {
        return DEFAULT_TIME_ZONE;
    }
}

From source file:org.graylog2.rest.resources.users.UsersResource.java

License:Open Source License

@PUT
@Path("{username}")
@ApiOperation("Modify user details.")
@ApiResponses({//  w w w .  j a  v a2  s .co m
        @ApiResponse(code = 400, message = "Attempted to modify a read only user account (e.g. built-in or LDAP users)."),
        @ApiResponse(code = 400, message = "Missing or invalid user details.") })
public void changeUser(
        @ApiParam(name = "username", value = "The name of the user to modify.", required = true) @PathParam("username") String username,
        @ApiParam(name = "JSON body", value = "Updated user information.", required = true) @Valid @NotNull ChangeUserRequest cr)
        throws ValidationException {
    checkPermission(USERS_EDIT, username);

    final org.graylog2.plugin.database.users.User user = userService.load(username);
    if (user == null) {
        throw new NotFoundException();
    }

    if (user.isReadOnly()) {
        throw new BadRequestException("Cannot modify readonly user " + username);
    }
    // we only allow setting a subset of the fields in CreateStreamRuleRequest
    if (cr.email() != null) {
        user.setEmail(cr.email());
    }
    if (cr.fullName() != null) {
        user.setFullName(cr.fullName());
    }
    final boolean permitted = isPermitted(USERS_PERMISSIONSEDIT, user.getName());
    if (permitted && cr.permissions() != null) {
        user.setPermissions(cr.permissions());
    }

    final String timezone = cr.timezone();
    if (timezone == null) {
        user.setTimeZone((String) null);
    } else {
        try {
            if (timezone.isEmpty()) {
                user.setTimeZone((String) null);
            } else {
                final DateTimeZone tz = DateTimeZone.forID(timezone);
                user.setTimeZone(tz);
            }
        } catch (IllegalArgumentException e) {
            LOG.error("Invalid timezone '{}', ignoring it for user {}.", timezone, username);
        }
    }

    final Startpage startpage = cr.startpage();
    if (startpage != null) {
        user.setStartpage(startpage.type(), startpage.id());
    }

    if (isPermitted("*")) {
        final Long sessionTimeoutMs = cr.sessionTimeoutMs();
        if (sessionTimeoutMs != null && sessionTimeoutMs != 0) {
            user.setSessionTimeoutMs(sessionTimeoutMs);
        }
    }
    userService.save(user);
}

From source file:org.graylog2.restclient.models.User.java

License:Open Source License

public User(ApiClient api, String id, String name, String email, String fullName, List<String> permissions,
        String sessionId, String timezone, boolean readonly, boolean external, Startpage startpage,
        long sessionTimeoutMs, Map<String, Object> preferences) {
    DateTimeZone timezone1 = null;//from  w w  w .  j  a va  2s .  co  m
    this.sessionTimeoutMs = sessionTimeoutMs;
    this.api = api;
    this.id = id;
    this.name = name;
    this.email = email;
    this.fullName = fullName;
    this.permissions = permissions;
    this.sessionId = sessionId;
    try {
        if (timezone != null) {
            timezone1 = DateTimeZone.forID(timezone);
        }
    } catch (IllegalArgumentException e) {
        log.warn("Invalid time zone name {} when loading user {}.", timezone, name);
    } finally {
        this.timezone = timezone1;
    }
    this.readonly = readonly;
    this.external = external;
    this.startpage = startpage;
    if (preferences != null) {
        this.preferences = preferences;
    } else {
        this.preferences = Collections.emptyMap();
    }
}

From source file:org.graylog2.users.UserImpl.java

License:Open Source License

@Override
public DateTimeZone getTimeZone() {
    final Object o = fields.get(TIMEZONE);
    try {//from   w  ww  .j  a  v  a2s.  c  o  m
        if (o != null) {
            return DateTimeZone.forID(o.toString());
        }
    } catch (IllegalArgumentException e) {
        LOG.warn("Invalid timezone \"{}\" saved for user \"{}\"", o, getName());
    }
    return null;
}

From source file:org.graylog2.users.UserImpl.java

License:Open Source License

@Override
public void setTimeZone(final String timeZone) {
    DateTimeZone dateTimeZone;//  w  w  w  .  ja v  a2  s  . c  o  m
    try {
        dateTimeZone = DateTimeZone.forID(firstNonNull(timeZone, DateTimeZone.UTC.getID()));
    } catch (IllegalArgumentException e) {
        LOG.info("Invalid timezone \"{}\", falling back to UTC.", timeZone);
        dateTimeZone = DateTimeZone.UTC;
    }

    setTimeZone(dateTimeZone);
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.DateColumnLocalDateMapper.java

License:Apache License

public DateTimeZone parseZone(String zoneString) {
    return DateTimeZone.forID(zoneString);
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.StringColumnDateTimeZoneMapper.java

License:Apache License

@Override
public DateTimeZone fromNonNullValue(String s) {
    return DateTimeZone.forID(s);
}

From source file:org.jadira.usertype.dateandtime.joda.util.DateTimeZoneWithOffset.java

License:Apache License

public DateTimeZoneWithOffset(String zoneWithOffset) {

    int separatorIndex = zoneWithOffset.indexOf('{');
    if (separatorIndex == -1) {
        this.standardDateTimeZone = DateTimeZone.forID(zoneWithOffset);
        this.offsetDateTimeZone = null;
    } else {//w w w .java2s.c  om
        this.standardDateTimeZone = DateTimeZone.forID(zoneWithOffset.substring(0, separatorIndex));
        this.offsetDateTimeZone = DateTimeZone
                .forID(zoneWithOffset.substring(separatorIndex + 1, zoneWithOffset.length() - 1));
    }

}