Example usage for org.joda.time DateTime withTimeAtStartOfDay

List of usage examples for org.joda.time DateTime withTimeAtStartOfDay

Introduction

In this page you can find the example usage for org.joda.time DateTime withTimeAtStartOfDay.

Prototype

public DateTime withTimeAtStartOfDay() 

Source Link

Document

Returns a copy of this datetime with the time set to the start of the day.

Usage

From source file:org.efaps.esjp.accounting.transaction.Transaction_Base.java

License:Apache License

/**
 * Numbering of the transaction.// w ww.ja v  a  2  s . c o  m
 *
 * @param _parameter Parameter as passed by the eFaps API
 * @return new Return
 * @throws EFapsException on error
 */
public Return asignNumber(final Parameter _parameter) throws EFapsException {
    final DateTime date = new DateTime(
            _parameter.getParameterValue(CIFormAccounting.Accounting_TransactionAsignNumberForm.date.name));
    final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.TransactionAbstract);
    queryBldr.addWhereAttrEqValue(CIAccounting.TransactionAbstract.StatusAbstract,
            Status.find(CIAccounting.TransactionStatus.Closed));
    queryBldr.addWhereAttrEqValue(CIAccounting.TransactionAbstract.PeriodLink, _parameter.getInstance());
    queryBldr.addWhereAttrLessValue(CIAccounting.TransactionAbstract.Date,
            date.withTimeAtStartOfDay().plusDays(1));
    queryBldr.addOrderByAttributeAsc(CIAccounting.TransactionAbstract.Date);
    queryBldr.addOrderByAttributeAsc(CIAccounting.TransactionAbstract.Name);
    final MultiPrintQuery multi = queryBldr.getPrint();
    multi.addAttribute(CIAccounting.TransactionAbstract.Name);
    multi.setEnforceSorted(true);
    multi.execute();
    String currentValue = getStartValue(_parameter);
    while (multi.next()) {
        currentValue = setName(_parameter, multi.getCurrentInstance(),
                multi.<String>getAttribute(CIAccounting.TransactionAbstract.Name), currentValue, true);
    }
    return new Return();
}

From source file:org.egov.infra.utils.DateUtils.java

License:Open Source License

public static DateTime startOfGivenDate(DateTime dateTime) {
    return dateTime.withTimeAtStartOfDay();
}

From source file:org.egov.pgr.elasticsearch.entity.contract.ComplaintSearchRequest.java

License:Open Source License

public void setComplaintDate(String complaintDate) {
    if (complaintDate != null) {
        DateTime currentDate = new DateTime();
        this.toDate = endOfGivenDate(currentDate).toString(ES_DATE_FORMAT);
        if ("today".equalsIgnoreCase(complaintDate)) {
            this.fromDate = currentDate.withTimeAtStartOfDay().toString(ES_DATE_FORMAT);
        } else if ("lastsevendays".equalsIgnoreCase(complaintDate)) {
            this.fromDate = currentDate.minusDays(7).toString(ES_DATE_FORMAT);
        } else if ("lastthirtydays".equalsIgnoreCase(complaintDate)) {
            this.fromDate = currentDate.minusDays(30).toString(ES_DATE_FORMAT);
        } else if ("lastninetydays".equalsIgnoreCase(complaintDate)) {
            this.fromDate = currentDate.minusDays(90).toString(ES_DATE_FORMAT);
        } else {//  ww  w  .j  a  v  a2 s .co m
            this.fromDate = null;
            this.toDate = null;
        }
    }

}

From source file:org.egov.pgr.web.contract.ComplaintSearchRequest.java

License:Open Source License

public void setComplaintDate(final String complaintDate) {
    if (null != complaintDate) {
        DateTime currentDate = new DateTime();
        complaintDateTo = endOfGivenDate(currentDate).toString(SEARCH_DATE_FORMAT);
        if (complaintDate.equalsIgnoreCase("today")) {
            complaintDateFrom = currentDate.withTimeAtStartOfDay().toString(SEARCH_DATE_FORMAT);
        } else if (complaintDate.equalsIgnoreCase("all")) {
            complaintDateFrom = null;/*from ww  w .j  a va2  s. c o  m*/
            complaintDateTo = null;
        } else if (complaintDate.equalsIgnoreCase("lastsevendays")) {
            complaintDateFrom = currentDate.minusDays(7).toString(SEARCH_DATE_FORMAT);
        } else if (complaintDate.equalsIgnoreCase("lastthirtydays")) {
            complaintDateFrom = currentDate.minusDays(30).toString(SEARCH_DATE_FORMAT);
        } else if (complaintDate.equalsIgnoreCase("lastninetydays")) {
            complaintDateFrom = currentDate.minusDays(90).toString(SEARCH_DATE_FORMAT);
        } else {
            complaintDateFrom = null;
            complaintDateTo = null;
        }
    }

}

From source file:org.imsglobal.lti.toolProvider.ToolProvider.java

License:LGPL

/**
 * Check the authenticity of the LTI launch request.
 *
 * The consumer, resource link and user objects will be initialised if the request is valid.
 *
 * @return boolean True if the request has been successfully validated.
 *//* w  w w . ja  v  a2s.  c  om*/
private boolean authenticate() {
    boolean doSaveConsumer = false;
    //JSON Initialization
    JSONParser parser = new JSONParser();
    JSONObject tcProfile = null;

    String messageType = request.getParameter("lti_message_type");
    ok = (StringUtils.isNotEmpty(messageType) && MESSAGE_TYPES.containsKey(messageType));
    if (!ok) {
        reason = "Invalid or missing lti_message_type parameter.";
    }
    if (ok) {
        String version = request.getParameter("lti_version");
        ok = (StringUtils.isNotEmpty(version)) && (LTI_VERSIONS.contains(version));
        if (!ok) {
            reason = "Invalid or missing lti_version parameter.";
        }
    }
    if (ok) {
        if (messageType.equals("basic-lti-launch-request")) {
            String resLinkId = request.getParameter("resource_link_id");
            ok = (StringUtils.isNotEmpty(resLinkId));
            if (!ok) {
                reason = "Missing resource link ID.";
            }
        } else if (messageType.equals("ContentItemSelectionRequest")) {
            String accept = request.getParameter("accept_media_types");
            ok = (StringUtils.isNotEmpty(accept));
            if (ok) {
                String[] mediaTypes = StringUtils.split(accept, ",");
                Set<String> mTypes = new HashSet<String>();
                for (String m : mediaTypes) {
                    mTypes.add(m); //unique set of media types, no repeats
                }
                ok = mTypes.size() > 0;
                if (!ok) {
                    reason = "No accept_media_types found.";
                } else {
                    this.mediaTypes = mTypes;
                }
            } else { //no accept 
                ok = false;
            }
            String targets = request.getParameter("accept_presentation_document_targets");
            if (ok && StringUtils.isNotEmpty(targets)) {
                Set<String> documentTargets = new HashSet<String>();
                for (String t : StringUtils.split(targets, ",")) {
                    documentTargets.add(t);
                }
                ok = documentTargets.size() > 0;
                if (!ok) {
                    reason = "Missing or empty accept_presentation_document_targets parameter.";
                } else {
                    List<String> valid = Arrays.asList("embed", "frame", "iframe", "window", "popup", "overlay",
                            "none");
                    boolean thisCheck = true;
                    String problem = "";
                    for (String target : documentTargets) {
                        thisCheck = valid.contains(target);
                        if (!thisCheck) {
                            problem = target;
                            break;
                        }
                    }
                    if (!thisCheck) {
                        reason = "Invalid value in accept_presentation_document_targets parameter: " + problem;
                    }
                }
                if (ok) {
                    this.documentTargets = documentTargets;
                }
            } else {
                ok = false;
            }
            if (ok) {
                String ciReturnUrl = request.getParameter("content_item_return_url");
                ok = StringUtils.isNotEmpty(ciReturnUrl);
                if (!ok) {
                    reason = "Missing content_item_return_url parameter.";
                }
            }
        } else if (messageType.equals("ToolProxyRegistrationRequest")) {
            String regKey = request.getParameter("reg_key");
            String regPass = request.getParameter("reg_password");
            String profileUrl = request.getParameter("tc_profile_url");
            String launchReturnUrl = request.getParameter("launch_presentation_return_url");
            ok = StringUtils.isNotEmpty(regKey) && StringUtils.isNotEmpty(regPass)
                    && StringUtils.isNotEmpty(profileUrl) && StringUtils.isNotEmpty(launchReturnUrl);
            if (debugMode && !ok) {
                reason = "Missing message parameters.";
            }
        }
    }
    DateTime now = DateTime.now();
    //check consumer key
    if (ok && !messageType.equals("ToolProxyRegistrationRequest")) {
        String key = request.getParameter("oauth_consumer_key");
        ok = StringUtils.isNotEmpty(key);
        if (!ok) {
            reason = "Missing consumer key.";
        }
        if (ok) {
            this.consumer = new ToolConsumer(key, dataConnector);
            ok = consumer.getCreated() != null;
            if (!ok) {
                reason = "Invalid consumer key.";
            }
        }
        if (ok) {
            if (consumer.getLastAccess() == null) {
                doSaveConsumer = true;
            } else {
                DateTime last = consumer.getLastAccess();
                doSaveConsumer = doSaveConsumer || last.isBefore(now.withTimeAtStartOfDay());
            }
            consumer.setLastAccess(now);
            String baseString = "";
            String signature = "";
            OAuthMessage oAuthMessage = null;
            try {
                OAuthConsumer oAuthConsumer = new OAuthConsumer("about:blank", consumer.getKey(),
                        consumer.getSecret(), null);
                OAuthAccessor oAuthAccessor = new OAuthAccessor(oAuthConsumer);
                OAuthValidator oAuthValidator = new SimpleOAuthValidator();
                URL u = new URL(request.getRequestURI());
                String url = u.getProtocol() + "://" + u.getHost() + u.getPath();
                Map<String, String[]> params = request.getParameterMap();
                Map<String, List<String>> param2 = new HashMap<String, List<String>>();
                for (String k : params.keySet()) {
                    param2.put(k, Arrays.asList(params.get(k)));
                }
                List<Map.Entry<String, String>> param3 = ToolConsumer.convert(param2);
                oAuthMessage = new OAuthMessage(request.getMethod(), url, param3);
                baseString = OAuthSignatureMethod.getBaseString(oAuthMessage);
                signature = oAuthMessage.getSignature();
                oAuthValidator.validateMessage(oAuthMessage, oAuthAccessor);
            } catch (Exception e) {
                System.err.println(e.getMessage());
                OAuthProblemException oe = null;
                if (e instanceof OAuthProblemException) {
                    oe = (OAuthProblemException) e;
                    for (String p : oe.getParameters().keySet()) {
                        System.err.println(p + ": " + oe.getParameters().get(p).toString());
                    }
                }
                this.ok = false;
                if (StringUtils.isEmpty(reason)) {
                    if (debugMode) {
                        reason = e.getMessage();
                        if (StringUtils.isEmpty(reason)) {
                            reason = "OAuth exception.";
                        }
                        details.add("Timestamp: " + request.getParameter("oauth_timestamp"));
                        details.add("Current system time: " + System.currentTimeMillis());
                        details.add("Signature: " + signature);
                        details.add("Base string: " + baseString);
                    } else {
                        reason = "OAuth signature check failed - perhaps an incorrect secret or timestamp.";
                    }
                }
            }
        }
        if (ok) {
            DateTime today = DateTime.now();
            if (consumer.getLastAccess() == null) {
                doSaveConsumer = true;
            } else {
                DateTime last = consumer.getLastAccess();
                doSaveConsumer = doSaveConsumer || last.isBefore(today.withTimeAtStartOfDay());
            }
            consumer.setLastAccess(today);
            if (consumer.isThisprotected()) {
                String guid = request.getParameter("tool_consumer_instance_guid");
                if (StringUtils.isNotEmpty(consumer.getConsumerGuid())) {
                    ok = StringUtils.isEmpty(guid) || consumer.getConsumerGuid().equals(guid);
                    if (!ok) {
                        reason = "Request is from an invalid tool consumer.";
                    }
                } else {
                    ok = StringUtils.isEmpty(guid);
                    if (!ok) {
                        reason = "A tool consumer GUID must be included in the launch request.";
                    }
                }
            }
            if (ok) {
                ok = consumer.isEnabled();
                if (!ok) {
                    reason = "Tool consumer has not been enabled by the tool provider.";
                }
            }
            if (ok) {
                ok = consumer.getEnableFrom() == null || consumer.getEnableFrom().isBefore(today);
                if (ok) {
                    ok = consumer.getEnableUntil() == null || consumer.getEnableUntil().isAfter(today);
                    if (!ok) {
                        reason = "Tool consumer access has expired.";
                    }
                } else {
                    reason = "Tool consumer access is not yet available.";
                }
            }
        }

        // Validate other message parameter values
        if (ok) {
            List<String> boolValues = Arrays.asList("true", "false");
            String acceptUnsigned = request.getParameter("accept_unsigned");
            String acceptMultiple = request.getParameter("accept_multiple");
            String acceptCopyAdvice = request.getParameter("accept_copy_advice");
            String autoCreate = request.getParameter("auto_create");
            String canConfirm = request.getParameter("can_confirm");
            String lpdt = request.getParameter("launch_presentation_document_target");
            if (messageType.equals("ContentItemSelectionRequest")) {
                if (StringUtils.isNotEmpty(acceptUnsigned)) {
                    ok = boolValues.contains(acceptUnsigned);
                    if (!ok) {
                        reason = "Invalid value for accept_unsigned parameter: " + acceptUnsigned + ".";
                    }
                }
                if (ok && StringUtils.isNotEmpty(acceptMultiple)) {
                    ok = boolValues.contains(acceptMultiple);
                    if (!ok) {
                        reason = "Invalid value for accept_multiple parameter: " + acceptMultiple + ".";
                    }
                }
                if (ok && StringUtils.isNotEmpty(acceptCopyAdvice)) {
                    ok = boolValues.contains(acceptCopyAdvice);
                    if (!ok) {
                        reason = "Invalid value for accept_copy_advice parameter: " + acceptCopyAdvice + ".";
                    }
                }
                if (ok && StringUtils.isNotEmpty(autoCreate)) {
                    ok = boolValues.contains(autoCreate);
                    if (!ok) {
                        reason = "Invalid value for auto_create parameter: " + autoCreate + ".";
                    }
                }
                if (ok && StringUtils.isNotEmpty(canConfirm)) {
                    ok = boolValues.contains(canConfirm);
                    if (!ok) {
                        reason = "Invalid value for can_confirm parameter: " + canConfirm + ".";
                    }
                }
            } else if (StringUtils.isNotEmpty(lpdt)) {
                List<String> valid = Arrays.asList("embed", "frame", "iframe", "window", "popup", "overlay",
                        "none");
                ok = valid.contains(lpdt);
                if (!ok) {
                    reason = "Invalid value for launch_presentation_document_target parameter: " + lpdt + ".";
                }
            }
        }
    }

    if (ok && (messageType.equals("ToolProxyRegistrationRequest"))) {

        ok = request.getParameter("lti_version").equals(LTI_VERSION2);
        if (!ok) {
            reason = "Invalid lti_version parameter";
        }
        if (ok) {
            HttpClient client = HttpClientBuilder.create().build();
            String tcProfUrl = request.getParameter("tc_profile_url");
            HttpGet get = new HttpGet(tcProfUrl);
            get.addHeader("Accept", "application/vnd.ims.lti.v2.toolconsumerprofile+json");
            HttpResponse response = null;
            try {
                response = client.execute(get);
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (response == null) {
                reason = "Tool consumer profile not accessible.";
            } else {
                try {
                    String json_string = EntityUtils.toString(response.getEntity());
                    tcProfile = (JSONObject) parser.parse(json_string);
                    ok = tcProfile != null;
                    if (!ok) {
                        reason = "Invalid JSON in tool consumer profile.";
                    } else {
                        JSONContext jsonContext = new JSONContext();
                        jsonContext.parse(tcProfile);
                        consumer.getProfile().setContext(jsonContext);
                    }
                } catch (Exception je) {
                    je.printStackTrace();
                    ok = false;
                    reason = "Invalid JSON in tool consumer profile.";
                }
            }
        }
        // Check for required capabilities
        if (ok) {
            String regKey = request.getParameter("reg_key");
            consumer = new ToolConsumer(regKey, dataConnector);
            ConsumerProfile profile = new ConsumerProfile();
            JSONContext context = new JSONContext();
            context.parse(tcProfile);
            profile.setContext(context);
            consumer.setProfile(profile);
            List<String> capabilities = consumer.getProfile().getCapabilityOffered();
            List<String> missing = new ArrayList<String>();
            for (ProfileResourceHandler handler : resourceHandlers) {
                for (ProfileMessage message : handler.getRequiredMessages()) {
                    String type = message.getType();
                    if (!capabilities.contains(type)) {
                        missing.add(type);
                    }
                }
            }
            for (String name : constraints.keySet()) {
                ParameterConstraint constraint = constraints.get(name);
                if (constraint.isRequired()) {
                    if (!capabilities.contains(name)) {
                        missing.add(name);
                    }
                }
            }
            if (!missing.isEmpty()) {
                StringBuilder sb = new StringBuilder();
                for (String cap : missing) {
                    sb.append(cap).append(", ");
                }
                reason = "Required capability not offered - \"" + sb.toString() + "\"";
                ok = false;
            }
        }
        // Check for required services
        if (ok) {
            for (ToolService tService : requiredServices) {
                for (String format : tService.getFormats()) {
                    ServiceDefinition sd = findService(format, tService.getActions());
                    if (sd == null) {
                        if (ok) {
                            reason = "Required service(s) not offered - ";
                            ok = false;
                        } else {
                            reason += ", ";
                        }
                        StringBuilder sb = new StringBuilder();
                        for (String a : tService.getActions()) {
                            sb.append(a).append(", ");
                        }
                        reason += format + "[" + sb.toString() + "]";
                    }
                }
            }
        }
        if (ok) {
            if (messageType.equals("ToolProxyRegistrationRequest")) {
                ConsumerProfile profile = new ConsumerProfile();
                JSONContext context = new JSONContext();
                context.parse(tcProfile);
                profile.setContext(context);
                consumer.setProfile(profile);
                consumer.setSecret(request.getParameter("reg_password"));
                consumer.setLtiVersion(request.getParameter("lti_version"));
                consumer.setName(profile.getProduct().getProductInfo().getProductName().get("default_name"));
                consumer.setConsumerName(consumer.getName());
                consumer.setConsumerVersion(
                        "{tcProfile.product_instance.product_info.product_family.code}-{tcProfile.product_instance.product_info.product_version}");
                consumer.setConsumerGuid(profile.getProduct().getGuid());
                consumer.setEnabled(true);
                consumer.setThisprotected(true);
                doSaveConsumer = true;
            }
        }
    } else if (ok && !request.getParameter("custom_tc_profile_url").isEmpty()
            && consumer.getProfile() == null) {
        String tcProfUrl = request.getParameter("custom_tc_profile_url");
        HttpClient client = HttpClientBuilder.create().build();
        HttpGet get = new HttpGet(tcProfUrl);
        get.addHeader("Accept", "application/vnd.ims.lti.v2.toolconsumerprofile+json");
        HttpResponse response = null;
        try {
            response = client.execute(get);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (response == null) {
            reason = "Tool consumer profile not accessible.";
        } else {
            try {
                String json_string = EntityUtils.toString(response.getEntity());
                tcProfile = (JSONObject) parser.parse(json_string);
                ok = tcProfile != null;
                if (!ok) {
                    reason = "Invalid JSON in tool consumer profile.";
                } else {
                    JSONContext jsonContext = new JSONContext();
                    jsonContext.parse(tcProfile);
                    consumer.getProfile().setContext(jsonContext);
                    doSaveConsumer = true;
                }
            } catch (Exception je) {
                je.printStackTrace();
                ok = false;
                reason = "Invalid JSON in tool consumer profile.";
            }
        }
    }

    // Validate message parameter constraints
    if (ok) {
        List<String> invalidParameters = new ArrayList<String>();
        for (String name : constraints.keySet()) {
            ParameterConstraint constraint = constraints.get(name);
            if (constraint.getMessageTypes().isEmpty() || constraint.getMessageTypes().contains(messageType)) {
                ok = true;
                String n = request.getParameter("name");
                if (constraint.isRequired()) {
                    n = n.trim();
                    if (StringUtils.isBlank(n)) {
                        invalidParameters.add(name + " (missing)");
                        ok = false;
                    }
                }
                if (ok && constraint.getMaxLength() > 0 && StringUtils.isNotBlank(n)) {
                    if (n.trim().length() > constraint.getMaxLength()) {
                        invalidParameters.add(name + " (too long)");
                    }
                }
            }
        }
        if (invalidParameters.size() > 0) {
            ok = false;
            if (StringUtils.isEmpty(reason)) {
                StringBuilder sb = new StringBuilder();
                for (String ip : invalidParameters) {
                    sb.append(ip).append(", ");
                }
                reason = "Invalid parameter(s): " + sb.toString() + ".";
            }
        }
    }

    if (ok) {

        // Set the request context
        String cId = request.getParameter("context_id");
        if (StringUtils.isNotEmpty(cId)) {
            context = Context.fromConsumer(consumer, cId.trim());
            String title = request.getParameter("context_title");
            if (StringUtils.isNotEmpty(title)) {
                title = title.trim();
            }
            if (StringUtils.isBlank(title)) {
                title = "Course " + context.getId();
            }
            context.setTitle(title);
        }

        // Set the request resource link
        String rlId = request.getParameter("resource_link_id");
        if (StringUtils.isNotEmpty(rlId)) {
            String contentItemId = request.getParameter("custom_content_item_id");
            resourceLink = ResourceLink.fromConsumer(consumer, rlId, contentItemId);
            if (context != null) {
                resourceLink.setContextId(context.getRecordId());
            }
            String title = request.getParameter("resource_link_title");
            if (StringUtils.isEmpty(title)) {
                title = "Resource " + resourceLink.getId();
            }
            resourceLink.setTitle(title);
            // Delete any existing custom parameters
            for (String name : consumer.getSettings().keySet()) {
                if (StringUtils.startsWith(name, "custom_")) {
                    consumer.setSetting(name);
                    doSaveConsumer = true;
                }
            }
            if (context != null) {
                for (String name : context.getSettings().keySet()) {
                    if (StringUtils.startsWith(name, "custom_")) {
                        context.setSetting(name, "");
                    }
                }
            }
            for (String name : resourceLink.getSettings().keySet()) {
                if (StringUtils.startsWith(name, "custom_")) {
                    resourceLink.setSetting(name, "");
                }
            }
            // Save LTI parameters
            for (String name : LTI_CONSUMER_SETTING_NAMES) {
                String s = request.getParameter(name);
                if (StringUtils.isNotBlank(s)) {
                    consumer.setSetting(name, s);
                } else {
                    consumer.setSetting(name);
                }
            }
            if (context != null) {
                for (String name : LTI_CONTEXT_SETTING_NAMES) {
                    String s = request.getParameter(name);
                    if (StringUtils.isNotBlank(s)) {
                        context.setSetting(name, s);
                    } else {
                        context.setSetting(name, "");
                    }
                }
            }
            for (String name : LTI_RESOURCE_LINK_SETTING_NAMES) {
                String sn = request.getParameter(name);
                if (StringUtils.isNotEmpty(sn)) {
                    resourceLink.setSetting(name, sn);
                } else {
                    resourceLink.setSetting(name, "");
                }
            }
            // Save other custom parameters
            ArrayList<String> combined = new ArrayList<String>();
            combined.addAll(Arrays.asList(LTI_CONSUMER_SETTING_NAMES));
            combined.addAll(Arrays.asList(LTI_CONTEXT_SETTING_NAMES));
            combined.addAll(Arrays.asList(LTI_RESOURCE_LINK_SETTING_NAMES));
            for (String name : request.getParameterMap().keySet()) {
                String value = request.getParameter(name);
                if (StringUtils.startsWith(name, "custom_") && !combined.contains(name)) {
                    resourceLink.setSetting(name, value);
                }
            }
        }

        // Set the user instance
        String userId = request.getParameter("user_id");
        if (StringUtils.isNotEmpty(userId)) {
            userId = userId.trim();
        }

        user = User.fromResourceLink(resourceLink, userId);

        // Set the user name
        String firstname = request.getParameter("lis_person_name_given");
        String lastname = request.getParameter("lis_person_name_family");
        String fullname = request.getParameter("lis_person_name_full");
        user.setNames(firstname, lastname, fullname);

        // Set the user email
        String email = request.getParameter("lis_person_contact_email_primary");
        user.setEmail(email, defaultEmail);

        // Set the user image URI
        String img = request.getParameter("user_image");
        if (StringUtils.isNotEmpty(img)) {
            try {
                URL imgUrl = new URL(img);
                user.setImage(imgUrl);
            } catch (Exception e) {
                //bad url
            }
        }

        // Set the user roles
        String roles = request.getParameter("roles");
        if (StringUtils.isNotEmpty(roles)) {
            user.setRoles(parseRoles(roles));
        }

        // Initialise the consumer and check for changes
        consumer.setDefaultEmail(defaultEmail);
        String ltiV = request.getParameter("lti_version");
        if (!ltiV.equals(consumer.getLtiVersion())) {
            consumer.setLtiVersion(ltiV);
            doSaveConsumer = true;
        }
        String instanceName = request.getParameter("tool_consumer_instance_name");
        if (StringUtils.isNotEmpty(instanceName)) {
            if (!instanceName.equals(consumer.getConsumerName())) {
                consumer.setConsumerName(instanceName);
                doSaveConsumer = true;
            }
        }
        String familyCode = request.getParameter("tool_consumer_info_product_family_code");
        String extLMS = request.getParameter("ext_lms");
        if (StringUtils.isNotBlank(familyCode)) {
            String version = familyCode;
            String infoVersion = request.getParameter("tool_consumer_info_version");
            if (StringUtils.isNotEmpty(infoVersion)) {
                version += "-" + infoVersion;
            }
            // do not delete any existing consumer version if none is passed
            if (!version.equals(consumer.getConsumerVersion())) {
                consumer.setConsumerVersion(version);
                doSaveConsumer = true;
            }
        } else if (StringUtils.isNotEmpty(extLMS) && !consumer.getConsumerName().equals(extLMS)) {
            consumer.setConsumerVersion(extLMS);
            doSaveConsumer = true;
        }
        String tciGuid = request.getParameter("tool_consumer_instance_guid");
        if (StringUtils.isNotEmpty(tciGuid)) {
            if (StringUtils.isNotEmpty(consumer.getConsumerGuid())) {
                consumer.setConsumerGuid(tciGuid);
                doSaveConsumer = true;
            } else if (!consumer.isThisprotected()) {
                doSaveConsumer = (!tciGuid.equals(consumer.getConsumerGuid()));
                if (doSaveConsumer) {
                    consumer.setConsumerGuid(tciGuid);
                }
            }
        }
        String css = request.getParameter("launch_presentation_css_url");
        String extCss = request.getParameter("ext_launch_presentation_css_url");
        if (StringUtils.isNotEmpty(css)) {
            if (!css.equals(consumer.getCssPath())) {
                consumer.setCssPath(css);
                doSaveConsumer = true;
            }
        } else if (StringUtils.isNotEmpty(extCss) && !consumer.getCssPath().equals(extCss)) {
            consumer.setCssPath(extCss);
            doSaveConsumer = true;
        } else if (StringUtils.isNotEmpty(consumer.getCssPath())) {
            consumer.setCssPath(null);
            doSaveConsumer = true;
        }
    }

    // Persist changes to consumer
    if (doSaveConsumer) {
        consumer.save();
    }
    if (ok && context != null) {
        context.save();
    }
    if (ok && resourceLink != null) {

        // Check if a share arrangement is in place for this resource link
        ok = checkForShare();

        // Persist changes to resource link
        resourceLink.save();

        // Save the user instance
        String lrsdid = request.getParameter("lis_result_sourcedid");
        if (StringUtils.isNotEmpty(lrsdid)) {
            if (!lrsdid.equals(user.getLtiResultSourcedId())) {
                user.setLtiResultSourcedId(lrsdid);
                user.save();
            }
        } else if (StringUtils.isNotEmpty(user.getLtiResultSourcedId())) {
            user.setLtiResultSourcedId("");
            user.save();
        }
    }

    return ok;

}

From source file:org.isisaddons.module.fakedata.dom.JavaSqlDates.java

License:Apache License

private static Date asSqlDate(final DateTime dateTime) {
    final DateTime dateTimeAtStartOfDay = dateTime.withTimeAtStartOfDay();
    return new Date(dateTimeAtStartOfDay.toDate().getTime());
}

From source file:org.mythtv.client.ui.dvr.GuideDataFragment.java

License:Open Source License

public void scroll(final int channelId, final DateTime selectedDate) {
    Log.v(TAG, "scroll : enter");

    Log.v(TAG, "scroll : selectedDate=" + selectedDate.toString());
    getListView().postDelayed(new Runnable() {

        /* (non-Javadoc)
         * @see java.lang.Runnable#run()
         *//*  w  w w  .  ja v a 2  s.co m*/
        @Override
        public void run() {
            Log.v(TAG, "postDelayed : enter");

            //DateTime selectedDateUtc = DateUtils.convertUtc( selectedDate );
            //Log.v( TAG, "postDelayed : selectedDateUtc=" + selectedDateUtc.toString() );

            //DateTime start = selectedDateUtc.withTimeAtStartOfDay();
            List<Program> programs = mProgramGuideDaoHelper.findAll(getActivity(), mLocationProfile, channelId,
                    selectedDate.withTimeAtStartOfDay());
            if (null != programs && !programs.isEmpty()) {
                Log.v(TAG, "postDelayed : programs size=" + programs.size());

                int selectedPosition = 0;
                for (int i = 0; i < programs.size(); i++) {
                    Program program = programs.get(i);
                    Log.v(TAG,
                            "postDelayed : postion '" + i + "', title=" + program.getTitle() + ", startTime="
                                    + program.getStartTime().toString() + ", endTime="
                                    + program.getEndTime().toString() + " ["
                                    + (program.getStartTime().isEqual(selectedDate)
                                            || (program.getStartTime().isBefore(selectedDate)
                                                    && program.getEndTime().isAfter(selectedDate)))
                                    + "]");

                    if (program.getStartTime().isEqual(selectedDate)
                            || (program.getStartTime().isAfter(selectedDate)
                                    && program.getEndTime().isAfter(selectedDate))) {
                        Log.v(TAG, "postDelayed : selecting postion '" + i + "'");

                        selectedPosition = i;

                        break;
                    }
                }

                Log.v(TAG, "postDelayed : scrolling to postion '" + selectedPosition + "' of '"
                        + getListView().getCount() + "'");
                getListView().smoothScrollToPosition(selectedPosition);

            }

            Log.v(TAG, "postDelayed : enter");

        }

    }, 100);

    Log.v(TAG, "scroll : exit");
}

From source file:org.mythtv.client.ui.dvr.GuideFragment.java

License:Open Source License

@Override
public void onDateChanged(DateTime date) {
    Log.v(TAG, "onDateChanged : enter");

    Log.v(TAG, "onDateChanged : date=" + date.toString());

    selectedDate = date.withTimeAtStartOfDay();
    Log.v(TAG, "onDateChanged : selectedDate=" + selectedDate.toString());

    updateView();//from  w  ww  . ja v  a  2  s  . c  om

    //      timeslotSelect( date.getHourOfDay() + ":00:00" );

    Log.v(TAG, "onDateChanged : enter");
}

From source file:org.onebusaway.nextbus.impl.util.ConversionUtil.java

License:Apache License

public static long getStartofDayTime(Date date) {
    DateTime dateTime = new DateTime(date, timeZone);
    dateTime = dateTime.withTimeAtStartOfDay();
    return dateTime.getMillis();
}

From source file:org.openmainframe.ade.ext.stats.MessageRateStats.java

License:Open Source License

/**
 * Return the end of day of yesterday/* www  . j a  v a2s .  c o m*/
 * @param dateTime
 * @return
 */
private DateTime getYesterdayEndOfDay(DateTime dateTime) {
    dateTime = dateTime.withTimeAtStartOfDay();
    dateTime = dateTime.minusMillis(1);

    return dateTime;
}