com.sfs.whichdoctor.formatter.UrlGenerator.java Source code

Java tutorial

Introduction

Here is the source code for com.sfs.whichdoctor.formatter.UrlGenerator.java

Source

/*******************************************************************************
 * Copyright (c) 2009 David Harrison.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl-3.0.html
 *
 * Contributors:
 *     David Harrison - initial API and implementation
 ******************************************************************************/
package com.sfs.whichdoctor.formatter;

import com.sfs.whichdoctor.beans.PreferencesBean;

import org.apache.commons.lang.StringUtils;

public class UrlGenerator {

    public static String modify(final PreferencesBean preferences, final String type, final int objectId) {

        String url = "";

        if (StringUtils.equalsIgnoreCase(type, "person")) {
            url = preferences.buildUrl("save", "people_edit", "modifyitem", objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "organisation")) {
            url = preferences.buildUrl("save", "organisations_edit", "modifyitem", objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "debit")) {
            url = preferences.buildUrl("save", "debits_edit", "modifyitem", objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "credit")) {
            url = preferences.buildUrl("save", "credits_edit", "modifyitem", objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "receipt")) {
            url = preferences.buildUrl("save", "receipts_edit", "modifyitem", objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "reimbursement")) {
            url = preferences.buildUrl("save", "reimbursements_edit", "modifyitem", objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "rotation")) {
            url = preferences.buildUrl("save", "rotations_modify", "modify", objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "group")) {
            url = preferences.buildUrl("save", "groups_edit", "modifyitem", objectId);
        }
        return url;
    }

    public static String modify(final PreferencesBean preferences, final String type, final int objectId,
            String parenttype, final int parentGUID, final int parentId) {

        String url = "";

        if (parenttype == null) {
            parenttype = "member";
        }
        if (StringUtils.equalsIgnoreCase(parenttype, "person")) {
            parenttype = "member";
        }
        parenttype = parenttype.toLowerCase();

        if (StringUtils.equalsIgnoreCase(type, "membership")) {
            url = preferences.buildUrl("save", "people_edit", "modifyitem", "membership_Id=" + objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "memo")) {
            if (StringUtils.equalsIgnoreCase(parenttype, "member")) {
                parenttype = "person";
            }
            url = preferences.buildUrl("save", "memo", "modifyitem", parentGUID, objectId, "Type=" + parenttype);
        }
        if (StringUtils.equalsIgnoreCase(type, "address")) {
            url = preferences.buildUrl("save", "address", "modifyitem", parentGUID, objectId, "Type=" + parenttype);
        }
        if (StringUtils.equalsIgnoreCase(type, "phone")) {
            url = preferences.buildUrl("save", "phone", "modifyitem", parentGUID, objectId, "Type=" + parenttype);
        }
        if (StringUtils.equalsIgnoreCase(type, "email")) {
            url = preferences.buildUrl("save", "email", "modifyitem", parentGUID, objectId, "Type=" + parenttype);
        }
        if (StringUtils.equalsIgnoreCase(type, "specialty")) {
            url = preferences.buildUrl("save", "specialty", "modifyitem", parentGUID, objectId,
                    "Type=" + parenttype);
        }
        if (StringUtils.equalsIgnoreCase(type, "workshop")) {
            url = preferences.buildUrl("save", "workshop", "modifyitem", parentId, objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "rotation")) {
            url = preferences.buildUrl("save", "rotations_modify", "modify", objectId, "PersonId=" + parentGUID);
        }
        if (StringUtils.equalsIgnoreCase(type, "project")) {
            url = preferences.buildUrl("save", "project", "modifyitem", parentId, objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "exam")) {
            url = preferences.buildUrl("save", "exam", "modifyitem", parentId, objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "qualification")) {
            url = preferences.buildUrl("save", "qualification", "modifyitem", parentGUID, objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "accreditation")) {
            url = preferences.buildUrl("save", "accreditation", "modifyitem", parentGUID, objectId,
                    "Type=rotatoin");
        }
        if (StringUtils.equalsIgnoreCase(type, "assessment")) {
            url = preferences.buildUrl("save", "assessment", "modifyitem", parentId, objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "report")) {
            url = preferences.buildUrl("save", "report", "modifyitem", parentGUID, objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "expenseclaim")) {
            url = preferences.buildUrl("save", "expenseclaim", "modifyitem", parentGUID, objectId);
        }
        if (StringUtils.equalsIgnoreCase(type, "payment")) {
            url = preferences.buildUrl("save", "payment", "modifyitem", parentId, objectId);
        }

        return url;
    }
}