001: package org.tigris.scarab.notification;
002:
003: import java.util.HashMap;
004: import java.util.Map;
005: import java.util.Set;
006:
007: public class ActivityType {
008: String code = null;
009: String resourceId = null;
010:
011: public static final ActivityType ISSUE_CREATED = new ActivityType(
012: "issue_created", "ActivityTypeIssueCreated");
013: public static final ActivityType ISSUE_MOVED = new ActivityType(
014: "issue_moved", "ActivityTypeIssueMoved");
015: public static final ActivityType ISSUE_COPIED = new ActivityType(
016: "issue_copied", "ActivityTypeIssueCopied");
017: public static final ActivityType ISSUE_DELETED = new ActivityType(
018: "issue_deleted", "ActivityTypeIssueDeleted");
019: public static final ActivityType ATTRIBUTE_CHANGED = new ActivityType(
020: "attribute_changed", "ActivityTypeAttributeChanged");
021: public static final ActivityType USER_ATTRIBUTE_CHANGED = new ActivityType(
022: "user_attribute_changed",
023: "ActivityTypeUserAttributeChanged");
024: public static final ActivityType COMMENT_ADDED = new ActivityType(
025: "comment_added", "ActivityTypeCommentAdded");
026: public static final ActivityType COMMENT_CHANGED = new ActivityType(
027: "comment_changed", "ActivityTypeCommentChanged");
028: public static final ActivityType URL_ADDED = new ActivityType(
029: "url_added", "ActivityTypeURLAdded");
030: public static final ActivityType URL_CHANGED = new ActivityType(
031: "url_changed", "ActivityTypeURLChanged");
032: public static final ActivityType URL_DESC_CHANGED = new ActivityType(
033: "url_desc_changed", "ActivityTypeURLDescChanged");
034: public static final ActivityType URL_DELETED = new ActivityType(
035: "url_deleted", "ActivityTypeURLDeleted");
036: public static final ActivityType ATTACHMENT_CREATED = new ActivityType(
037: "attachment_created", "ActivityTypeAttachmentCreated");
038: public static final ActivityType ATTACHMENT_REMOVED = new ActivityType(
039: "attachment_removed", "ActivityTypeAttachmentRemoved");
040: public static final ActivityType DEPENDENCY_CREATED = new ActivityType(
041: "dependency_created", "ActivityTypeDependencyCreated");
042: public static final ActivityType DEPENDENCY_CHANGED = new ActivityType(
043: "dependency_changed", "ActivityTypeDependencyChanged");
044: public static final ActivityType DEPENDENCY_DELETED = new ActivityType(
045: "dependency_deleted", "ActivityTypeDependencyDeleted");
046:
047: private static Map types = new HashMap();
048:
049: static {
050: types.put(ISSUE_CREATED.getCode(), ISSUE_CREATED);
051: types.put(ISSUE_MOVED.getCode(), ISSUE_MOVED);
052: types.put(ISSUE_COPIED.getCode(), ISSUE_COPIED);
053: types.put(ISSUE_DELETED.getCode(), ISSUE_DELETED);
054: types.put(ATTRIBUTE_CHANGED.getCode(), ATTRIBUTE_CHANGED);
055: types.put(USER_ATTRIBUTE_CHANGED.getCode(),
056: USER_ATTRIBUTE_CHANGED);
057: types.put(COMMENT_ADDED.getCode(), COMMENT_ADDED);
058: types.put(COMMENT_CHANGED.getCode(), COMMENT_CHANGED);
059: types.put(URL_ADDED.getCode(), URL_ADDED);
060: types.put(URL_CHANGED.getCode(), URL_CHANGED);
061: types.put(URL_DESC_CHANGED.getCode(), URL_DESC_CHANGED);
062: types.put(URL_DELETED.getCode(), URL_DELETED);
063: types.put(ATTACHMENT_CREATED.getCode(), ATTACHMENT_CREATED);
064: types.put(ATTACHMENT_REMOVED.getCode(), ATTACHMENT_REMOVED);
065: types.put(DEPENDENCY_CREATED.getCode(), DEPENDENCY_CREATED);
066: types.put(DEPENDENCY_CHANGED.getCode(), DEPENDENCY_CHANGED);
067: types.put(DEPENDENCY_DELETED.getCode(), DEPENDENCY_DELETED);
068:
069: }
070:
071: /**
072: * Return an iterator over all available ActivityType codes.
073: * @return
074: */
075: public static Set getActivityTypeCodes() {
076: return types.keySet();
077: }
078:
079: /**
080: * Returns the activitytype constant given its database value.
081: *
082: * @param code The internal code of the type (the value that gets stored in database)
083: * @return A constant AcivityType matching the given code
084: */
085: public static ActivityType getActivityType(String code) {
086: return (ActivityType) types.get(code);
087: }
088:
089: public String getCode() {
090: return this .code;
091: }
092:
093: private ActivityType(String desc, String resourceId) {
094: this .code = desc;
095: this .resourceId = resourceId;
096: }
097:
098: /**
099: * Compares two ActivityType objects with their <code>code</code> attribute.
100: */
101: public boolean equals(Object obj) {
102: boolean bRdo = false;
103: if (obj != null)
104: bRdo = this .code.equals(((ActivityType) obj).getCode());
105: return bRdo;
106: }
107:
108: /**
109: * Return the resource id for the given activity code.
110: * Note[HD]: Unfortunately the name convention for resources is
111: * different from the name convention used in ActivityType for
112: * activity codes. We should switch to the convention for resources
113: * here. Thus we can avoid this remapping from code to resource id.
114: * @param code
115: * @return
116: */
117: public static String getResourceId(String code) {
118: return getActivityType(code).resourceId;
119: }
120: }
|