Example usage for org.apache.commons.lang.time DateFormatUtils format

List of usage examples for org.apache.commons.lang.time DateFormatUtils format

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateFormatUtils format.

Prototype

public static String format(Date date, String pattern) 

Source Link

Document

Formats a date/time into a specific pattern.

Usage

From source file:org.betaconceptframework.astroboa.util.DateUtils.java

public static String formatDate(Date date, String pattern) {
    if (date == null)
        return null;
    if (StringUtils.isBlank(pattern))
        pattern = Default_Pattern; //Default Pattern

    return DateFormatUtils.format(date, pattern);
}

From source file:org.dspace.app.webui.jsptag.AccessSettingTag.java

public int doStartTag() throws JspException {
    String legend = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.access-setting.legend");
    String label_name = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.access-setting.label_name");
    String label_group = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.access-setting.label_group");
    String label_embargo = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.access-setting.label_embargo");
    String label_date = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.access-setting.label_date");
    String radio0 = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.access-setting.radio0");
    String radio1 = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.access-setting.radio1");
    String radio_help = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.access-setting.radio_help");
    String label_reason = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.access-setting.label_reason");
    String button_confirm = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.access-setting.button_confirm");

    String help_name = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.access-setting.name_help");
    String help_reason = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.access-setting.reason_help");

    JspWriter out = pageContext.getOut();
    StringBuffer sb = new StringBuffer();

    try {/*  w w  w.  j a  va2s  .co m*/
        HttpServletRequest hrq = (HttpServletRequest) pageContext.getRequest();
        Context context = UIUtil.obtainContext(hrq);

        // get startDate and reason of the resource policy of the target DSpaceObject
        List<ResourcePolicy> policies = null;
        if (!advanced && dso != null) {
            policies = AuthorizeManager.findPoliciesByDSOAndType(context, dso, ResourcePolicy.TYPE_CUSTOM);
        } else if (rp != null) {
            policies = new ArrayList<ResourcePolicy>();
            policies.add(rp);
        }

        String name = "";
        int group_id = 0;
        String startDate = "";
        String reason = "";
        String radio0Checked = " checked=\"checked\"";
        String radio1Checked = "";
        String disabled = " disabled=\"disabled\"";
        if (policies != null && policies.size() > 0) {
            ResourcePolicy rp = policies.get(0);
            name = (rp.getRpName() == null ? "" : rp.getRpName());
            group_id = rp.getGroup().getID();
            startDate = (rp.getStartDate() != null ? DateFormatUtils.format(rp.getStartDate(), "yyyy-MM-dd")
                    : "");
            reason = (rp.getRpDescription() == null ? "" : rp.getRpDescription());
            if (!startDate.equals("")) {
                radio0Checked = "";
                radio1Checked = " checked=\"checked\"";
                disabled = "";
            }
        }

        // if advanced embargo is disabled, embargo date and reason fields are always enabled
        if (!advanced) {
            disabled = "";
        }

        if (embargo) {
            // Name
            sb.append("<div class=\"form-group\">");
            sb.append(label_name).append("\n");
            sb.append("<p class=\"help-block\">").append(help_name).append("</p>").append("\n");
            sb.append(
                    "<input class=\"form-control\" name=\"name\" id=\"policy_name\" type=\"text\" maxlength=\"30\" value=\"")
                    .append(name).append("\" />\n");
            sb.append("</div>");

            // Group
            sb.append("<div class=\"form-group\">");
            sb.append(label_group).append("\n");
            sb.append("<select class=\"form-control\" name=\"group_id\" id=\"select_group\">\n");

            Group[] groups = getGroups(context, hrq, subInfo);
            if (groups != null) {
                for (Group group : groups) {
                    sb.append("<option value=\"").append(group.getID()).append("\"");
                    if (group_id == group.getID()) {
                        sb.append(" selected=\"selected\"");
                    }
                    sb.append(">").append(group.getName()).append("</option>\n");
                }
            } else {
                sb.append("<option value=\"0\" selected=\"selected\">Anonymous</option>\n");
            }
            sb.append("</select>\n");
            sb.append("</div>");
            // Select open or embargo
            sb.append(label_embargo).append("\n");
            sb.append("<div class=\"radio\">");
            sb.append("<label><input name=\"open_access_radios\" type=\"radio\" value=\"0\"")
                    .append(radio0Checked).append(" />").append(radio0).append("</label>\n");
            sb.append("</div>");
            sb.append("<div class=\"radio\">");
            sb.append("<label><input name=\"open_access_radios\" type=\"radio\" value=\"1\"")
                    .append(radio1Checked).append(" />").append(radio1).append("</label>\n");
            sb.append("</div>");

        }

        // Embargo Date
        if (hidden) {
            sb.append(
                    "<input name=\"embargo_until_date\" id=\"embargo_until_date_hidden\" type=\"hidden\" value=\"")
                    .append(startDate).append("\" />\n");
            ;
            sb.append("<input name=\"reason\" id=\"reason_hidden\" type=\"hidden\" value=\"").append(reason)
                    .append("\" />\n");
        } else {
            sb.append("<div class=\"form-group col-md-12\">");
            sb.append("<div class=\"col-md-2\">");
            sb.append(label_date);
            sb.append("</div>");
            sb.append("<div class=\"col-md-2\">");
            sb.append(
                    "<input class=\"form-control\" name=\"embargo_until_date\" id=\"embargo_until_date\" maxlength=\"10\" size=\"10\" type=\"text\" value=\"")
                    .append(startDate).append("\"").append(disabled).append(" />\n");
            sb.append("</div>");
            sb.append("<div class=\"col-md-8\">");
            sb.append("<span class=\"help-block\">" + radio_help + "</span>");
            sb.append("</div>");
            sb.append("</div>");
            // Reason                
            sb.append("<div class=\"form-group col-md-12\">");
            sb.append("<div class=\"col-md-12\">");
            sb.append(label_reason).append("\n");
            sb.append("</div>");
            sb.append("<div class=\"col-md-12\">");
            sb.append("<p class=\"help-block\">").append(help_reason).append("</p>").append("\n");
            sb.append("</div>");
            sb.append("<div class=\"col-md-12\">");
            sb.append("<textarea class=\"form-control\" name=\"reason\" id=\"reason\" cols=\"30\" rows=\"5\"")
                    .append(disabled).append(">").append(reason).append("</textarea>\n");
            sb.append("</div>");
            sb.append("</div>");
        }

        // Add policy button
        if (addpolicy) {

            sb.append(
                    "<input class=\"btn btn-success col-md-offset-5\" name=\"submit_add_policy\" type=\"submit\" value=\"")
                    .append(button_confirm).append("\" />\n");

        }

        out.println(sb.toString());
    } catch (IOException ie) {
        throw new JspException(ie);
    } catch (SQLException e) {
        throw new JspException(e);
    }

    return SKIP_BODY;
}

From source file:org.dspace.app.webui.jsptag.PoliciesListTag.java

public int doStartTag() throws JspException {
    String label_name = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.policies-list.label_name");
    String label_action = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.policies-list.label_action");
    String label_group = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.policies-list.label_group");
    String label_sdate = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.policies-list.label_sdate");
    String label_edate = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.policies-list.label_edate");

    String label_emptypolicies = LocaleSupport.getLocalizedMessage(pageContext,
            "org.dspace.app.webui.jsptag.policies-list.no_policies");

    JspWriter out = pageContext.getOut();
    StringBuffer sb = new StringBuffer();

    try {//w  ww.j a  va  2  s  .c o  m
        if (policies != null && policies.size() > 0) {
            sb.append("<div class=\"table-responsive\">\n");
            sb.append("<table class=\"table\">\n");
            sb.append("<tr>\n");
            sb.append("<th class=\"accessHeadOdd\">").append(label_name).append("</th>\n");
            sb.append("<th class=\"accessHeadEven\">").append(label_action).append("</th>\n");
            sb.append("<th class=\"accessHeadOdd\">").append(label_group).append("</th>\n");
            sb.append("<th class=\"accessHeadEven\">").append(label_sdate).append("</th>\n");
            sb.append("<th class=\"accessHeadOdd\">").append(label_edate).append("</th>\n");
            if (showButton) {
                sb.append("<th class=\"accessButton\">&nbsp;</th>\n");
            }
            sb.append("</tr>\n");

            String column1 = "Even";
            String column2 = "Odd";
            for (ResourcePolicy policy : policies) {
                column1 = (column1.equals("Even") ? "Odd" : "Even");
                column2 = (column2.equals("Even") ? "Odd" : "Even");
                String rpName = (policy.getRpName() == null ? "" : policy.getRpName());
                String startDate = (policy.getStartDate() == null ? ""
                        : DateFormatUtils.format(policy.getStartDate(), "yyyy-MM-dd"));
                String endDate = (policy.getEndDate() == null ? ""
                        : DateFormatUtils.format(policy.getEndDate(), "yyyy-MM-dd"));

                sb.append("<tr>\n");
                sb.append("<td class=\"access").append(column1).append("\">").append(rpName).append("</td>\n");
                sb.append("<td class=\"access").append(column2).append("\">").append(policy.getActionText())
                        .append("</td>\n");
                sb.append("<td class=\"access").append(column1).append("\">")
                        .append(policy.getGroup().getName()).append("</td>\n");
                sb.append("<td class=\"access").append(column2).append("\">").append(startDate)
                        .append("</td>\n");
                sb.append("<td class=\"access").append(column1).append("\">").append(endDate).append("</td>\n");
                if (showButton) {
                    sb.append("<td class=\"accessButton\">\n");
                    sb.append("<input class=\"btn btn-default\" name=\"submit_edit_edit_policies_")
                            .append(policy.getID())
                            .append("\" type=\"submit\" value=\"Edit\" /> <input class=\"btn btn-danger\" name=\"submit_delete_edit_policies_")
                            .append(policy.getID()).append("\" type=\"submit\" value=\"Remove\" />\n");
                    sb.append("</td>\n");
                }
                sb.append("</tr>\n");
            }
            sb.append("</table>\n");
            sb.append("</div>\n");
        } else {
            sb.append("<div class=\"alert alert-warning\">").append(label_emptypolicies).append("</div>")
                    .append("\n");
        }
        out.println(sb.toString());
    } catch (IOException ie) {
        throw new JspException(ie);
    } catch (SQLException e) {
        throw new JspException(e);
    }

    return SKIP_BODY;
}

From source file:org.dspace.app.xmlui.aspect.administrative.authorization.EditItemPolicies.java

private void rowBuilder(String baseURL, Table table, java.util.List<ResourcePolicy> policies, int objectID,
        int objectType, int highlightID) throws WingException, SQLException {
    // If the list of policies is empty, say so
    if (policies == null || policies.size() == 0) {
        table.addRow().addCell(1, 8).addHighlight("italic").addContent(T_no_policies);
    }//from   w  w w.j a v  a2 s  . c  om
    // Otherwise, iterate over the given policies, creating a new table row for each one
    else {
        for (ResourcePolicy policy : policies) {
            Row row;
            if (policy.getID() == highlightID) {
                row = table.addRow(null, null, "highlight");
            } else {
                row = table.addRow();
            }

            Cell cell;
            if (objectType == Constants.BUNDLE) {
                cell = row.addCell(null, null, "indent");
            } else if (objectType == Constants.BITSTREAM) {
                cell = row.addCell(null, null, "doubleIndent");
            } else {
                cell = row.addCell();
            }

            CheckBox select = cell.addCheckBox("select_policy");

            select.setLabel(String.valueOf(policy.getID()));
            select.addOption(String.valueOf(policy.getID()));

            // Accounting for the funky case of an empty policy
            Group policyGroup = policy.getGroup();

            row.addCell().addXref(baseURL + "&submit_edit&policy_id=" + policy.getID() + "&object_id="
                    + objectID + "&object_type=" + objectType, String.valueOf(policy.getID()));

            // name
            String name = "";
            if (policy.getRpName() != null)
                name = policy.getRpName();
            row.addCell().addContent(name);

            row.addCell().addXref(baseURL + "&submit_edit&policy_id=" + policy.getID() + "&object_id="
                    + objectID + "&object_type=" + objectType, policy.getActionText());
            if (policyGroup != null) {
                Cell groupCell = row.addCell(1, 2);
                groupCell.addContent(policyGroup.getName());
                Highlight groupHigh = groupCell.addHighlight("fade");
                groupHigh.addContent(" [");
                groupHigh.addXref(baseURL + "&submit_edit_group&group_id=" + policyGroup.getID(), T_group_edit);
                groupHigh.addContent("]");
            } else {
                row.addCell(1, 2).addContent("...");
            }

            // startDate
            if (policy.getStartDate() != null) {
                row.addCell().addContent(DateFormatUtils.format(policy.getStartDate(), "yyyy-MM-dd"));
            } else {
                row.addCell().addContent("");
            }

            // endDate
            if (policy.getEndDate() != null) {
                row.addCell().addContent(DateFormatUtils.format(policy.getEndDate(), "yyyy-MM-dd"));
            } else {
                row.addCell().addContent("");
            }
        }
    }
}

From source file:org.dspace.app.xmlui.aspect.administrative.authorization.EditPolicyForm.java

public void addBody(Body body) throws WingException, SQLException {
    /* Get and setup our parameters. We should always have an objectType and objectID, since every policy
       * has to have a parent resource. policyID may, however, be -1 for new, not-yet-created policies and
       * the groupID is only set if the group is being changed. */
    int objectType = parameters.getParameterAsInteger("objectType", -1);
    int objectID = parameters.getParameterAsInteger("objectID", -1);
    int policyID = parameters.getParameterAsInteger("policyID", -1);
    int groupID = parameters.getParameterAsInteger("groupID", -1);
    int actionID = parameters.getParameterAsInteger("actionID", -1);
    int page = parameters.getParameterAsInteger("page", 0);
    String query = decodeFromURL(parameters.getParameter("query", "-1"));
    String rpName = parameters.getParameter("name", null);
    String rpDescription = parameters.getParameter("description", null);
    String rpStartDate = parameters.getParameter("startDate", null);
    String rpEndDate = parameters.getParameter("endDate", null);

    // The current policy, if it exists (i.e. we are not creating a new one)
    ResourcePolicy policy = ResourcePolicy.find(context, policyID);

    if (policy != null) {
        if (rpName == null || rpName.equals(""))
            rpName = policy.getRpName();

        if (rpDescription == null || rpDescription.equals(""))
            rpDescription = policy.getRpDescription();

        if (StringUtils.isBlank(rpStartDate) && policy.getStartDate() != null) {
            rpStartDate = DateFormatUtils.format(policy.getStartDate(), "yyyy-MM-dd");
        }//  w  w w .ja v a 2 s  .  c  om

        if (StringUtils.isBlank(rpEndDate) && policy.getEndDate() != null) {
            rpEndDate = DateFormatUtils.format(policy.getEndDate(), "yyyy-MM-dd");
        }
    }

    // The currently set group; it's value depends on wether previously clicked the "Set" button to change 
    // the associated group, came here to edit an existing group, or create a new one. 
    Group currentGroup;
    if (groupID != -1) {
        currentGroup = Group.find(context, groupID);
    } else if (policy != null) {
        currentGroup = policy.getGroup();
    } else {
        currentGroup = null;
    }

    // Same for the current action; it can either blank (-1), manually set, or inherited from the current policy
    if (policy != null && actionID == -1) {
        actionID = policy.getAction();

    }

    String errorString = parameters.getParameter("errors", null);
    ArrayList<String> errors = new ArrayList<String>();
    if (errorString != null) {
        for (String error : errorString.split(",")) {
            errors.add(error);
        }
    }

    /* Set up our current Dspace object */
    DSpaceObject dso;
    switch (objectType) {
    case Constants.COMMUNITY:
        dso = Community.find(context, objectID);
        break;
    case Constants.COLLECTION:
        dso = Collection.find(context, objectID);
        break;
    case Constants.ITEM:
        dso = org.dspace.content.Item.find(context, objectID);
        break;
    case Constants.BUNDLE:
        dso = Bundle.find(context, objectID);
        break;
    case Constants.BITSTREAM:
        dso = Bitstream.find(context, objectID);
        break;
    default:
        dso = null;
    }

    // DIVISION: edit-container-policies
    Division main = body.addInteractiveDivision("edit-policy", contextPath + "/admin/authorize",
            Division.METHOD_POST, "primary administrative authorization");

    if (policyID >= 0) {
        objectID = policy.getResourceID();
        objectType = policy.getResourceType();
        main.setHead(T_main_head_edit.parameterize(policyID, Constants.typeText[objectType], objectID));
    } else {
        main.setHead(T_main_head_new.parameterize(Constants.typeText[objectType], objectID));
    }

    int resourceRelevance = 1 << objectType;

    // DIVISION: authorization-actions
    Division actions = main.addDivision("edit-policy-actions");
    List actionsList = actions.addList("actions", "form");

    // name-description
    Text name = actionsList.addItem().addText("name");
    name.setLabel(T_label_name);
    name.setValue(rpName);

    TextArea description = actionsList.addItem().addTextArea("description");
    description.setLabel(T_label_description);
    description.setValue(rpDescription);

    // actions radio buttons
    actionsList.addLabel(T_label_action);
    Radio actionSelect = actionsList.addItem().addRadio("action_id");
    actionSelect.setLabel(T_label_action);
    for (int i = 0; i < Constants.actionText.length; i++) {
        // only display if action i is relevant
        //  to resource type resourceRelevance                             
        if ((Constants.actionTypeRelevance[i] & resourceRelevance) > 0) {
            if (actionID == i) {
                actionSelect.addOption(true, i, Constants.actionText[i]);
            } else {
                actionSelect.addOption(i, Constants.actionText[i]);
            }
        }
    }
    if (errors.contains("action_id")) {
        actionSelect.addError(T_error_no_action);
    }

    // currently set group
    actionsList.addLabel(T_policy_currentGroup);
    Select groupSelect = actionsList.addItem().addSelect("group_id");
    for (Group group : Group.findAll(context, Group.NAME)) {
        if (group == currentGroup) {
            groupSelect.addOption(true, group.getID(), group.getName());
        } else {
            groupSelect.addOption(group.getID(), group.getName());
        }
    }
    if (errors.contains("group_id")) {
        groupSelect.addError(T_error_no_group);
    }
    if (errors.contains("duplicatedPolicy")) {
        groupSelect.addError(T_error_duplicated_policy);
    }

    if (dso instanceof Item || dso instanceof Bitstream) {
        // start date
        Text startDate = actionsList.addItem().addText("start_date");
        startDate.setLabel(T_label_start_date);
        startDate.setValue(rpStartDate);
        startDate.setHelp(T_label_date_help);
        if (errors.contains("startDate"))
            startDate.addError(T_error_date_format);
        else if (errors.contains("startDateGreaterThenEndDate"))
            startDate.addError(T_error_start_date_greater_than_end_date);

        // end date
        Text endDate = actionsList.addItem().addText("end_date");
        endDate.setLabel(T_label_end_date);
        endDate.setValue(rpEndDate);
        endDate.setHelp(T_label_date_help);
        if (errors.contains("endDate"))
            endDate.addError(T_error_date_format);
    }

    // the search function
    actionsList.addLabel(T_label_search);
    org.dspace.app.xmlui.wing.element.Item searchItem = actionsList.addItem();
    Text searchText = searchItem.addText("query");
    if (!query.equals("-1")) {
        searchText.setValue(query);
    }
    searchItem.addButton("submit_search_groups").setValue(T_submit_search_groups);

    actionsList.addLabel();
    org.dspace.app.xmlui.wing.element.Item buttons = actionsList.addItem();
    buttons.addButton("submit_save").setValue(T_submit_save);
    buttons.addButton("submit_cancel").setValue(T_submit_cancel);

    // Display the search results table
    if (!query.equals("-1")) {
        Division groupsList = main.addDivision("edit-policy-groupsList");
        groupsList.setHead(T_groups_head);
        this.addGroupSearch(groupsList, currentGroup, dso, query, page);
    }

    main.addHidden("administrative-continue").setValue(knot.getId());
}

From source file:org.dspace.app.xmlui.aspect.administrative.eperson.EditEPersonForm.java

private void add_signed_licenses(Division profile, EPerson edited_eperson) throws WingException {

    try {/*from w ww  .  j  a v a 2s  . c o m*/

        IFunctionalities functionalityManager = DSpaceApi.getFunctionalityManager();
        functionalityManager.openSession();
        java.util.List<LicenseResourceUserAllowance> licenses = functionalityManager
                .getSignedLicensesByUser(edited_eperson.getID());

        // hack for group by /////////
        /*
        java.util.List<String> keys = new ArrayList<String>();
        java.util.List<LicenseResourceUserAllowance> licenses_group_by = new ArrayList<LicenseResourceUserAllowance>();
                
        for (LicenseResourceUserAllowance license : licenses) {
           String createdOn = DateFormatUtils.format(license.getCreatedOn(), "ddMMyyyyhhmm");
           String epersonID = "" + license.getUserRegistration().getEpersonId();
           String licenseID = "" + license.getLicenseResourceMapping().getLicenseDefinition().getLicenseId();
           String key = createdOn + ":" + epersonID + ":" + licenseID;
           if(!keys.contains(key)) {
              keys.add(key);
              licenses_group_by.add(license);
           }
        }
        */
        /////////////////////////////

        if (licenses != null && licenses.size() > 0) {

            Table wftable = profile.addTable("singed-licenses", 1, 6);

            Row wfhead = wftable.addRow(Row.ROLE_HEADER);

            // table items - because of GUI not all columns could be shown
            wfhead.addCellContent("ID");
            wfhead.addCellContent("DATE");
            wfhead.addCellContent("LICENSE");
            wfhead.addCellContent("ITEM");
            wfhead.addCellContent("BITSTREAM");
            wfhead.addCellContent("EXTRA METADATA");

            for (LicenseResourceUserAllowance license : licenses) {
                int bitstreamID = license.getLicenseResourceMapping().getBitstreamId();
                LicenseDefinition ld = license.getLicenseResourceMapping().getLicenseDefinition();
                UserRegistration ur = license.getUserRegistration();
                Date signingDate = license.getCreatedOn();

                Row r = wftable.addRow(null, null, "font_smaller bold");
                String id = DateFormatUtils.format(signingDate, "yyyyMMddhhmmss") + "-" + ur.getEpersonId()
                        + "-" + bitstreamID;
                r.addCellContent(id);

                r.addCellContent(DateFormatUtils.format(signingDate, "yyyy-MM-dd hh:mm:ss"));

                r.addCell().addXref(ld.getDefinition(), ld.getName());

                Bitstream bitstream = Bitstream.find(context, bitstreamID);
                org.dspace.content.Item item = (org.dspace.content.Item) bitstream.getParentObject();

                String base = ConfigurationManager.getProperty("dspace.url");
                StringBuffer itemLink = new StringBuffer().append(base).append(base.endsWith("/") ? "" : "/")
                        .append("/handle/").append(item.getHandle());

                r.addCell().addXref(itemLink.toString(), "" + item.getID());

                StringBuffer bitstreamLink = new StringBuffer().append(base)
                        .append(base.endsWith("/") ? "" : "/").append("bitstream/handle/")
                        .append(item.getHandle()).append("/")
                        .append(URLEncoder.encode(bitstream.getName(), "UTF8")).append("?sequence=")
                        .append(bitstream.getSequenceID());
                r.addCell().addXref(bitstreamLink.toString(), "" + bitstream.getID());

                Cell c = r.addCell();
                java.util.List<UserMetadata> extraMetaData = functionalityManager
                        .getUserMetadata_License(ur.getEpersonId(), license.getTransactionId());
                for (UserMetadata metadata : extraMetaData) {
                    c.addHighlight("label label-info font_smaller")
                            .addContent(metadata.getMetadataKey() + ": " + metadata.getMetadataValue());
                }
            }

        } else {
            profile.addPara(null, "alert").addContent("Not signed any licenses yet.");
        }

        functionalityManager.closeSession();

    } catch (IllegalArgumentException e1) {
        profile.addPara(null, "alert alert-error").addContent("No items - " + e1.getMessage());
    } catch (Exception e2) {
        profile.addPara(null, "alert alert-error").addContent("Exception - " + e2.toString());
    }

}

From source file:org.dspace.app.xmlui.aspect.eperson.EditProfile.java

private void add_signed_licenses(Division profile) throws WingException {

    try {//w  ww . j a v  a2  s .c o m

        IFunctionalities functionalityManager = DSpaceApi.getFunctionalityManager();
        functionalityManager.openSession();
        java.util.List<LicenseResourceUserAllowance> licenses = functionalityManager
                .getSignedLicensesByUser(eperson.getID());

        // hack for group by /////////
        /*
        java.util.List<String> keys = new ArrayList<String>();
        java.util.List<LicenseResourceUserAllowance> licenses_group_by = new ArrayList<LicenseResourceUserAllowance>();
                
        for (LicenseResourceUserAllowance license : licenses) {
           String createdOn = DateFormatUtils.format(license.getCreatedOn(), "ddMMyyyyhhmm");
           String epersonID = "" + license.getUserRegistration().getEpersonId();
           String licenseID = "" + license.getLicenseResourceMapping().getLicenseDefinition().getLicenseId();
           String key = createdOn + ":" + epersonID + ":" + licenseID;
           if(!keys.contains(key)) {
              keys.add(key);
              licenses_group_by.add(license);
           }
        }
        */
        /////////////////////////////
        if (licenses != null && licenses.size() > 0) {

            Table wftable = profile.addTable("singed-licenses", 1, 6);

            Row wfhead = wftable.addRow(Row.ROLE_HEADER);

            // table items - because of GUI not all columns could be shown
            wfhead.addCellContent("ID");
            wfhead.addCellContent("DATE");
            wfhead.addCellContent("LICENSE");
            wfhead.addCellContent("ITEM");
            wfhead.addCellContent("BITSTREAM");
            wfhead.addCellContent("EXTRA METADATA");

            for (LicenseResourceUserAllowance license : licenses) {
                int bitstreamID = license.getLicenseResourceMapping().getBitstreamId();
                LicenseDefinition ld = license.getLicenseResourceMapping().getLicenseDefinition();
                UserRegistration ur = license.getUserRegistration();
                Date signingDate = license.getCreatedOn();

                Row r = wftable.addRow(null, null, "font_smaller bold");
                String id = DateFormatUtils.format(signingDate, "yyyyMMddhhmmss") + "-" + ur.getEpersonId()
                        + "-" + bitstreamID;
                r.addCellContent(id);

                r.addCellContent(DateFormatUtils.format(signingDate, "yyyy-MM-dd hh:mm:ss"));

                r.addCell().addXref(ld.getDefinition(), ld.getName());

                Bitstream bitstream = Bitstream.find(context, bitstreamID);
                org.dspace.content.Item item = (org.dspace.content.Item) bitstream.getParentObject();

                String base = ConfigurationManager.getProperty("dspace.url");
                StringBuffer itemLink = new StringBuffer().append(base).append(base.endsWith("/") ? "" : "/")
                        .append("/handle/").append(item.getHandle());

                r.addCell().addXref(itemLink.toString(), "" + item.getID());

                StringBuffer bitstreamLink = new StringBuffer().append(base)
                        .append(base.endsWith("/") ? "" : "/").append("bitstream/handle/")
                        .append(item.getHandle()).append("/")
                        .append(URLEncoder.encode(bitstream.getName(), "UTF8")).append("?sequence=")
                        .append(bitstream.getSequenceID());
                r.addCell().addXref(bitstreamLink.toString(), "" + bitstream.getID());

                Cell c = r.addCell();
                java.util.List<UserMetadata> extraMetaData = functionalityManager
                        .getUserMetadata_License(ur.getEpersonId(), license.getTransactionId());
                for (UserMetadata metadata : extraMetaData) {
                    c.addHighlight("label label-info font_smaller")
                            .addContent(metadata.getMetadataKey() + ": " + metadata.getMetadataValue());
                }
            }

        } else {
            profile.addPara(null, "alert").addContent("Not signed any licenses yet.");
        }
        functionalityManager.closeSession();

    } catch (IllegalArgumentException e1) {
        profile.addPara(null, "alert alert-error").addContent("No items - " + e1.getMessage());
    } catch (Exception e2) {
        profile.addPara(null, "alert alert-error").addContent("Exception - " + e2.toString());
    }

}

From source file:org.dspace.app.xmlui.aspect.submission.submit.AccessStepUtil.java

public void addEmbargoDateSimpleForm(DSpaceObject dso, List form, int errorFlag)
        throws SQLException, WingException {

    String date = null;/*  w ww. jav  a  2s .  co m*/

    if (dso != null) {
        java.util.List<ResourcePolicy> policies = AuthorizeManager.findPoliciesByDSOAndType(context, dso,
                ResourcePolicy.TYPE_CUSTOM);
        if (policies.size() > 0) {
            ResourcePolicy rp = policies.get(0);
            if (rp.getStartDate() != null) {
                date = DateFormatUtils.format(rp.getStartDate(), "yyyy-MM-dd");
            }
            globalReason = rp.getRpDescription();
        }
    }
    //        CheckBox privateCheckbox = form.addItem().addCheckBox("emabrgo_option");
    //        privateCheckbox.setLabel(T_item_embargoed);
    //        if(date!=null){
    //            privateCheckbox.addOption(true, CB_EMBARGOED, "");
    //        }
    //        else{
    //            privateCheckbox.addOption(false, CB_EMBARGOED, "");
    //        }

    // Date
    Text startDate = form.addItem().addText("embargo_until_date");
    startDate.setLabel(T_item_embargoed);
    if (errorFlag == org.dspace.submit.step.AccessStep.STATUS_ERROR_FORMAT_DATE) {
        startDate.addError(T_error_date_format);
    } else if (errorFlag == org.dspace.submit.step.AccessStep.STATUS_ERROR_MISSING_DATE) {
        startDate.addError(T_error_missing_date);
    }

    if (date != null) {
        startDate.setValue(date);
    }
    startDate.setHelp(T_label_date_help);
}

From source file:org.dspace.app.xmlui.aspect.submission.submit.AccessStepUtil.java

public void addTablePolicies(Division div, DSpaceObject dso) throws WingException, SQLException {
    if (isAdvancedFormEnabled) {
        java.util.List<ResourcePolicy> resourcePolicies = AuthorizeManager.findPoliciesByDSOAndType(context,
                dso, ResourcePolicy.TYPE_CUSTOM);

        int cols = resourcePolicies.size();
        if (cols == 0)
            cols = 1;//from   w  w w.  j av  a  2 s  .c o  m
        Table policies = div.addTable("policies", 6, cols);
        policies.setHead(T_head_policies_table);
        Row header = policies.addRow(Row.ROLE_HEADER);

        header.addCellContent(T_column0); // name
        header.addCellContent(T_column1); // action
        header.addCellContent(T_column2); // group
        header.addCellContent(T_column3); // start_date
        header.addCellContent(T_column4); // end_date

        for (ResourcePolicy rp : resourcePolicies) {
            int id = rp.getID();

            String name = "";
            if (rp.getRpName() != null)
                name = rp.getRpName();

            String action = rp.getActionText();

            // if it is the default policy for the Submitter don't show it.
            if (dso instanceof org.dspace.content.Item) {
                org.dspace.content.Item item = (org.dspace.content.Item) dso;
                if (rp.getEPersonID() != -1 && rp.getEPersonID() != 0) {
                    if (item.getSubmitter().getID() == rp.getEPersonID())
                        continue;
                }
            }

            String group = "";
            if (rp.getGroup() != null)
                group = rp.getGroup().getName();

            Row row = policies.addRow();

            row.addCellContent(name);
            row.addCellContent(action);
            row.addCellContent(group);

            // start
            String startDate = "";
            if (rp.getStartDate() != null) {
                startDate = DateFormatUtils.format(rp.getStartDate(), "yyyy-MM-dd");
            }
            row.addCellContent(startDate);

            // endDate
            String endDate = "";
            if (rp.getEndDate() != null) {
                endDate = DateFormatUtils.format(rp.getEndDate(), "yyyy-MM-dd");
            }
            row.addCellContent(endDate);

            Button edit = row.addCell().addButton("submit_edit_edit_policies_" + id);
            edit.setValue(T_table_submit_edit);

            Button delete = row.addCell().addButton("submit_delete_edit_policies_" + id);
            delete.setValue(T_table_submit_delete);
        }
    }
}

From source file:org.dspace.app.xmlui.aspect.submission.submit.EditPolicyStep.java

public void addBody(Body body)
        throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException {

    Collection collection = submission.getCollection();
    String actionURL = contextPath + "/handle/" + collection.getHandle() + "/submit/" + knot.getId()
            + ".continue";
    Request request = ObjectModelHelper.getRequest(objectModel);
    Division div = body.addInteractiveDivision("submit-edit-policy", actionURL, Division.METHOD_POST,
            "primary submission");
    div.setHead(T_submission_head);/*from  w  w w. ja v  a  2 s  .  c om*/
    addSubmissionProgressList(div);
    List edit = div.addList("submit-edit-file", List.TYPE_FORM);
    edit.setHead(T_head);

    div.addHidden("policy_id").setValue(resourcePolicy.getID());

    // if come from EditBitstreamPolicies
    if (bitstream != null)
        div.addHidden("bitstream_id").setValue(bitstream.getID());

    AccessStepUtil asu = new AccessStepUtil(context);

    asu.addName(resourcePolicy.getRpName(), edit, errorFlag);

    asu.addListGroups(Integer.toString(resourcePolicy.getGroupID()), edit, errorFlag, collection);

    // radio buttons: Item will be visible / Embargo Access + date
    String selectedRadio = Integer.toString(AccessStep.RADIO_OPEN_ACCESS_ITEM_VISIBLE);
    if (resourcePolicy.getStartDate() != null)
        selectedRadio = Integer.toString(AccessStep.RADIO_OPEN_ACCESS_ITEM_EMBARGOED);

    // this step is possible only in case of AdvancedForm
    String dateValue = "";
    if (resourcePolicy.getStartDate() != null) {
        dateValue = DateFormatUtils.format(resourcePolicy.getStartDate(), "yyyy-MM-dd");
    }
    asu.addAccessRadios(selectedRadio, dateValue, edit, errorFlag, null);

    // Reason
    asu.addReason(resourcePolicy.getRpDescription(), edit, errorFlag);

    // Note, not standard control actions, this page just goes back to the upload step.
    org.dspace.app.xmlui.wing.element.Item actions = edit.addItem();
    actions.addButton(org.dspace.submit.step.AccessStep.FORM_EDIT_BUTTON_SAVE).setValue(T_submit_save);
    actions.addButton(org.dspace.submit.step.AccessStep.FORM_EDIT_BUTTON_CANCEL).setValue(T_submit_cancel);
}