886
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public ScarabUser getUser(Object userId) throws TorqueException
{
return ScarabUserTool.getUser(userId);
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
private void ensure_List_has_MIT_data(MITList currentList, Module module, IssueType issueType) throws TorqueException
{
if(currentList != null)
{
MITListItem item = currentList.getFirstItem();
if(item != null)
{
if(item.getModule() == null)
{
// Ensure the item has been assigned to a module
item.setModule(module);
}
IssueType itemIssueType = item.getIssueType();
if(itemIssueType == null)
{
// item's issueType has not beeen initialized ?
if(issueType == null)
{
// Our local IssueType has also not been created ??
issueType = new IssueType();
}
item.setIssueType(issueType);
itemIssueType = issueType;
}
if (itemIssueType.getIssueTypeId() == null)
{
// No definition means "Do not care". Hence it is equal to "any issueType from any module":
itemIssueType.setIssueTypeId(MITListPeer.ALL_MODULES_ISSUETYPES.intValue());
}
}
}
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public String getRModuleAttributeDisplayName(final Attribute attribute) throws TorqueException
{
final ScarabUser user = (ScarabUser)data.getUser();
MITList mitList = user.getCurrentMITList();
return getRModuleAttributeDisplayName(attribute, mitList);
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public String getRModuleAttributeDisplayName(final Attribute attribute, final MITList mitlist)
throws TorqueException
{
return mitlist.getAttributeDisplayName(attribute);
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public List<RModuleAttribute> getRModuleUserAttributes() throws TorqueException
{
ScarabUser user = (ScarabUser)data.getUser();
Module module = user.getCurrentModule();
List<RModuleAttribute> result = getRModuleUserAttributes(user, module);
return result;
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public List<RModuleAttribute> getRModuleUserAttributes(Query q) throws TorqueException
{
List<RModuleAttribute> result = getRModuleUserAttributes();
if(result.size() == 0)
{
/*
* When we get here, then the current user uses a public query for which
* he/she has not yet created a customization (ake call s the query for the
* first time ever). Since we assume, that the original creator of the
* query has configured the query wisely, we take a copy of the creators
* customization here. Hence the new user gets a reasonable default setting.
* However the new user can configure the query independently from the originators
* customization.
*/
ScarabUser me = (ScarabUser)data.getUser(); // the userId of the current user
MITList currentList = q.getMITList(); // The query MIT-list
ScarabUser owner = q.getScarabUser(); // The originator of the query
if(owner==null)
{
Log.get().warn("Current Query does not contain a User");
owner = me;
if(owner == null)
{
owner = this.getCurrentUser();
if(owner == null)
{
Log.get().warn("Current session has no user assigned. Can not retrieve RModuleUserAttributes.");
return result;
}
}
}
Module module = me.getCurrentModule(); // The current module
IssueType theIssueType = this.getIssueType(); // The current issue Type
currentList = currentList.copy(); // Here we make a physical copy
currentList.setUserId(owner.getUserId()); // We set the current users uid
/*
* Now we recall the Userattributes of the originators customisation,
* but get it in to our copy. The nice side effect: The copy will be
* added to the database, thus it gets persistent. Subsequent calls
* to this method will always return the copy from the database.
*/
result = getRModuleUserAttributes(owner, module, theIssueType, currentList );
}
return result;
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
private List<RModuleAttribute> getRModuleUserAttributes(ScarabUser user, Module module) throws TorqueException
{
Integer defaultIssueTypeId = (Integer)MITListPeer.ALL_MODULES_ISSUETYPES.intValue();
IssueType theIssueType = this.getIssueType(defaultIssueTypeId);
if(issueListColumns == null || issueListColumns.size() == 0)
{
issueListColumns= getRModuleUserAttributes(user, module, theIssueType);
if (issueListColumns == null)
{
issueListColumns = Collections.EMPTY_LIST;
}
initialIssueListColumnsSize = issueListColumns.size();
}
// DEP: Not sure about this initial list stuff, or if we need it..
if (initialIssueListColumnsSize > issueListColumns.size())
{
TemplateContext context =
(TemplateContext) data.getTemp(Turbine.CONTEXT);
context.put("columnLimitExceeded", Boolean.TRUE);
}
return issueListColumns;
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public Query getQuery() throws TorqueException
{
String queryId = data.getParameters().getString("queryId");
if(queryId==null)
{
queryId = data.getParameters().getString("query");
}
if (queryId != null || query == null)
{
query = getQuery(queryId);
}
return query;
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
private Query getQuery(String queryId) throws TorqueException
{
try
{
if (queryId == null || queryId.length() == 0)
{
query = Query.getInstance();
Module m = getCurrentModule();
if(m != null)
{
query.setModule(m);
}
}
else
{
query = QueryManager
.getInstance(new NumberKey(queryId), false);
}
}
catch (TorqueException e)
{
e.printStackTrace();
throw e;
}
return query;
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public IssueType getIssueType() throws TorqueException
{
return getIssueType((Integer)null);
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public IssueType getIssueType(Integer defaultIssueTypeId) throws TorqueException
{
if (issueType == null)
{
String key = data.getParameters()
.getString("issuetypeid");
if (key == null)
{
// get new issue type
issueType = new IssueType(defaultIssueTypeId);
}
else
{
try
{
issueType = IssueTypeManager
.getInstance(new NumberKey(key), false);
}
catch (Exception e)
{
issueType = new IssueType(defaultIssueTypeId);
}
}
}
return issueType;
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public IssueType getCurrentIssueType()throws TorqueException
{
ScarabUser user = (ScarabUser)data.getUser();
IssueType curit = user.getCurrentIssueType();
if (curit == null)
{
Integer curitID = data.getParameters().getInteger(ScarabConstants.CURRENT_ISSUE_TYPE);
if(curitID.intValue()!=0)
{
curit = IssueTypeManager.getInstance(curitID);
}
}
return curit;
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public String getNextIssue()
throws TorqueException
{
String nextIssueId = null;
int nextIssueIndex = getNextIssuePosInList() - 1;
List searchResults = getCurrentSearchResults();
if(nextIssueIndex>=0 && nextIssueIndex< searchResults.size() )
{
nextIssueId = ((QueryResult)searchResults.get(nextIssueIndex)).getUniqueId();
}
return nextIssueId;
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public String getPrevIssue()
throws TorqueException
{
String prevIssueId = null;
int prevIssueIndex = getPrevIssuePosInList() - 1;
List searchResults = getCurrentSearchResults();
if(prevIssueIndex>=0 && prevIssueIndex<searchResults.size() )
{
prevIssueId = ((QueryResult)searchResults.get(prevIssueIndex)).getUniqueId();
}
return prevIssueId;
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public static MITListItem convertToMITListItem(RModuleIssueType rmit)
throws TorqueException
{
MITListItem item = MITListItemManager.getInstance();
item.setModuleId(rmit.getModuleId());
item.setIssueTypeId(rmit.getIssueTypeId());
return item;
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public void initializeLink(ScarabLink link)
throws org.apache.torque.TorqueException
{
int offset = listOffset + count;
link.setPage("ViewIssue.vm")
.addPathInfo("id", ((QueryResult)current).getUniqueId())
.addPathInfo(POS_IN_LIST, offset);
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public List getSortedAttributeOptions() throws TorqueException
{
return AttributeOptionPeer.getSortedAttributeOptions();
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public List getSortedAttributeOptionsForModule(Module module) throws TorqueException
{
return AttributeOptionPeer.getSortedAttributeOptions(module);
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public boolean isAnonymousLoginAllowed()
throws TorqueException
{
return ScarabUserTool.isAnonymousLoginAllowed();
}
// in java/org/tigris/scarab/tools/ScarabRequestTool.java
public RModuleOption getFirstModuleOption(Module module, IssueType issueType, String displayValue) throws TorqueException
{
RModuleOption result = null;
if (module != null && issueType != null && displayValue != null)
{
result = RModuleOption.getFirstRMO(module.getModuleId(), issueType.getIssueTypeId(), displayValue);
}
return result;
}
// in java/org/tigris/scarab/tools/SecurityAdminTool.java
public boolean hasRequestedRole(ScarabUser user, Role role, Group group)
throws TorqueException
{
List result = null;
Object obj = ScarabCache.get(this, HAS_REQUESTED_ROLE, user);
if (obj == null)
{
Criteria crit = new Criteria();
crit.add(PendingGroupUserRolePeer.USER_ID, user.getUserId());
result = PendingGroupUserRolePeer.doSelect(crit);
ScarabCache.put(result, this, HAS_REQUESTED_ROLE);
}
else
{
result = (List)obj;
}
boolean b = false;
Iterator iter = result.iterator();
while (iter.hasNext())
{
PendingGroupUserRole pmur = (PendingGroupUserRole)iter.next();
if (pmur.getRoleName().equals(role.getName())
&& ((Module)group).getModuleId().equals(pmur.getGroupId()))
{
b = true;
break;
}
}
return b;
}
// in java/org/tigris/scarab/tools/SecurityAdminTool.java
public List getPendingGroupUserRoles(Module module)
throws TorqueException
{
List result = null;
Object obj = ScarabCache.get(this, GET_PENDING, module);
if (obj == null)
{
Criteria crit = new Criteria();
crit.add(PendingGroupUserRolePeer.GROUP_ID, module.getModuleId());
result = PendingGroupUserRolePeer.doSelect(crit);
ScarabCache.put(result, this, GET_PENDING);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/tools/ScarabUserTool.java
public static ScarabUser getUser(Object userId)
throws TorqueException
{
if (userId == null)
{
return null;
}
if(IssueSearch.SEARCHING_USER_KEY.equalsIgnoreCase(userId.toString()))
{
return IssueSearch.getSearchingUserPlaceholder();
}
Integer pk = null;
try
{
pk = new Integer(userId.toString());
}
catch( NumberFormatException e)
{
return null;
}
ScarabUser su = null;
try
{
su = ScarabUserManager.getInstance(pk);
}
catch (TorqueException e)
{
return null;
}
return su;
}
// in java/org/tigris/scarab/tools/ScarabUserTool.java
public static boolean isAnonymousLoginAllowed()
throws TorqueException
{
return ScarabUserManager.anonymousAccessAllowed();
}
// in java/org/tigris/scarab/tools/ScarabUserTool.java
public static int getNotificationCount(Module module, ScarabUser user) throws TorqueException
{
return NotificationStatusManager.getNotificationCount(module, user);
}
// in java/org/tigris/scarab/tools/ScarabUserTool.java
public static boolean wantEdit(ScarabUser user, Issue issue, RunData data) throws TorqueException
{
Object testExists = data.getParameters().get("edit_attributes");
if(testExists != null)
{
boolean wantToOpenEditor = data.getParameters().getBoolean("edit_attributes");
return wantToOpenEditor;
}
// Now check for condition
String behaviour = GlobalParameterManager.getStringFromHierarchy(
"scarab.edit.behaviour",
issue.getModule(),
"default");
if(behaviour.equals("smart"))
{
if(issue.isSealed())
{
return false; // don't open this issue in edit mode, because it is sealed!
}
// Check if user is assigned to issue.
// If that is the case, open the issue
// in edit mode per default.
List<AttributeValue> userAttributeValues = issue.getUserAttributeValues(user);
Iterator<AttributeValue> iter = userAttributeValues.iterator();
while(iter.hasNext())
{
AttributeValue attributeValue = iter.next();
Attribute attribute = attributeValue.getAttribute();
String permission = attribute.getPermission();
if("Issue | Edit".equals(permission))
{
return true; // if can edit and want edit, lets edit ...
}
}
}
else
{
// Scarab default behaviour: Open issue in view mode.
}
return false;
}
// in java/org/tigris/scarab/tools/ScarabGlobalTool.java
public String getRequiredModifyPermission(Issue issue) throws TorqueException
{
String editPermission = ScarabSecurity.ISSUE__EDIT;
String status = getTurbineProperty("scarab.common.status.id");
if (status != null)
{
String value = getTurbineProperty("scarab.common.status.sealed");
if(value != null)
{
AttributeValue attval = issue.getAttributeValue(status);
if(attval != null && attval.getValue().equals(value))
{
String permissionString = getTurbineProperty("scarab.common.status.sealed.modifyPermission");
if(permissionString != null)
{
editPermission = permissionString;
}
}
}
}
return editPermission;
}
// in java/org/tigris/scarab/tools/ScarabGlobalTool.java
public List getCustomization(Object moduleId, Object userId, Object activityCode) throws TorqueException
{
NotificationRulePeer nfp = new NotificationRulePeer();
List result = nfp.getCustomization(moduleId, userId, activityCode);
return result;
}
// in java/org/tigris/scarab/tools/ScarabGlobalTool.java
public static Notification getEmptyNotificationFor(ScarabUser user, ScarabModule module) throws TorqueException
{
return new Notification(user, module);
}
// in java/org/tigris/scarab/tools/ScarabGlobalTool.java
public static NotificationRule getNotificationRule(Integer ruleId) throws TorqueException
{
NotificationRule result = NotificationRuleManager.getInstance(ruleId);
return result;
}
// in java/org/tigris/scarab/tools/ScarabGlobalTool.java
public List getModulesFromIssueList(List issues)
throws TorqueException
{
return ModuleManager.getInstancesFromIssueList(issues);
}
// in java/org/tigris/scarab/search/CachedQuery.java
private static List executeSelect( String sql )
throws TorqueException
{
List result;
try
{
long queryStartTime = System.currentTimeMillis();
result = BasePeer.executeQuery(sql);
logLongRunningQuery(sql, System.currentTimeMillis() - queryStartTime);
}
catch (TorqueException e)
{
Log.get(LOGGER).warn("Search sql:\n" + sql +
"\nresulted in an exception: " + e.getMessage());
throw e;
}
return result;
}
// in java/org/tigris/scarab/attribute/SelectOneAttribute.java
public void init() throws TorqueException
{
/*
if (getAttributeValue() == null &&
!getScarabIssue().isNew())
{
Criteria crit = new Criteria()
.add(ScarabIssueAttributeValuePeer.ATTRIBUTE_ID,
getScarabAttribute().getPrimaryKey());
Vector results = getScarabIssue()
.getScarabIssueAttributeValues(crit);
if (results.size() == 1) // if value is not found it will be null until
{
setScarabIssueAttributeValue(
(ScarabIssueAttributeValue)results.get(0));
}
}
if (getScarabIssueAttributeValue() != null)
{
value = getOptionById(
getScarabIssueAttributeValue().getOptionId());
loaded = true;
}
*/
}
// in java/org/tigris/scarab/attribute/OptionAttribute.java
public void setOption(final RModuleOption option)
throws TorqueException
{
setOptionIdOnly(option.getOptionId());
setValueOnly(option.getDisplayValue());
}
// in java/org/tigris/scarab/attribute/OptionAttribute.java
public Object loadResources() throws TorqueException
{
return null;
}
// in java/org/tigris/scarab/attribute/FreeFormAttribute.java
public void init() throws TorqueException
{
if (getIssue().isNew())
{
setDeleted(false);
}
}
// in java/org/tigris/scarab/om/AttributeValue.java
public void setChainedValue(final AttributeValue v)
throws TorqueException, ScarabException
{
if (v == null)
{
this.chainedValue = null;
}
else
{
if (v.getAttributeId() == null && getAttributeId() != null)
{
v.setAttributeId(getAttributeId());
}
else if (v.getAttribute() != null
&& !v.getAttribute().equals(getAttribute()))
{
throw new ScarabException(L10NKeySet.ExceptionCantChainAttributeValues,
v.getAttributeId(),
getAttributeId());
}
if (v.getIssueId() == null && getIssueId() != null)
{
v.setIssueId(getIssueId());
}
else if (v.getIssue() != null
&& !v.getIssue().equals(getIssue()))
{
throw new ScarabException(L10NKeySet.ExceptionCantChainIssues,
v.getIssueId(),
getIssueId());
}
if (this.chainedValue == null)
{
this.chainedValue = v;
}
else
{
chainedValue.setChainedValue(v);
}
if (activitySet != null)
{
v.startActivitySet(activitySet);
}
}
}
// in java/org/tigris/scarab/om/AttributeValue.java
public void setAttributeId(Integer nk)
throws TorqueException
{
super.setAttributeId(nk);
if (chainedValue != null)
{
chainedValue.setAttributeId(nk);
}
}
// in java/org/tigris/scarab/om/AttributeValue.java
public void setIssueId(Long nk)
throws TorqueException
{
super.setIssueId(nk);
if (chainedValue != null)
{
chainedValue.setIssueId(nk);
}
}
// in java/org/tigris/scarab/om/AttributeValue.java
public void startActivitySet(ActivitySet activitySet)
throws ScarabException, TorqueException
{
if (activitySet == null)
{
throw new ScarabException(L10NKeySet.ExceptionCanNotStartActivitySet);
}
if (this.activitySet == null)
{
this.activitySet = activitySet;
}
else
{
throw new ScarabException(L10NKeySet.ExceptionActivitySetInProgress);
}
/*
This is wrong. It prevented the old/new value stuff from working properly!
If we have an existing issue and we change some attributes, then when the
history was created, the data was not valid in it for some reason. I'm not
quite sure why this was added. (JSS)
Leaving here so that John can remove or fix.
oldOptionIdIsSet = false;
oldValueIsSet = false;
oldOptionId = null;
oldValue = null;
*/
// Check for previous active activities on this attribute
// If they exist, set old value for this activity
List result = null;
final Issue issue = getIssue();
if (issue != null)
{
result = issue
.getActivitiesWithNullEndDate(getAttribute());
}
if (result != null && result.size() > 0)
{
for (int i=0; i<result.size(); i++)
{
final Activity a = (Activity)result.get(i);
oldOptionId = a.getNewOptionId();
oldValue = a.getNewValue();
}
}
if (chainedValue != null)
{
chainedValue.startActivitySet(activitySet);
}
}
// in java/org/tigris/scarab/om/AttributeValue.java
public void setOptionId(Integer optionId)
throws TorqueException
{
if ( optionId != null )
{
Module module = getIssue().getModule();
IssueType issueType = getIssue().getIssueType();
if (module == null || issueType == null)
{
AttributeOption option = AttributeOptionManager
.getInstance(optionId);
setValueOnly(option.getName());
}
else
{
// FIXME! create a key and get the instance directly from
// the manager.
List options = null;
options = module
.getRModuleOptions(getAttribute(), issueType);
if(options != null)
{
for (int i = options.size() - 1; i >= 0; i--)
{
RModuleOption option = (RModuleOption) options.get(i);
if (option.getOptionId().equals(optionId))
{
setValueOnly(option.getDisplayValue());
break;
}
}
}
}
}
else
{
// any reason to set a option_id to null, once its already set?
setValueOnly(null);
}
setOptionIdOnly(optionId);
}
// in java/org/tigris/scarab/om/AttributeValue.java
protected void setOptionIdOnly(Integer optionId)
throws TorqueException
{
if (!ObjectUtils.equals(optionId, getOptionId()))
{
// if the value is set multiple times before saving only
// save the last saved value
if (!isNew() && !oldOptionIdIsSet && getOptionId() != null)
{
oldOptionId = getOptionId();
oldOptionIdIsSet = true;
}
super.setOptionId(optionId);
}
}
// in java/org/tigris/scarab/om/AttributeValue.java
public void setUserId(Integer userId)
throws TorqueException
{
if (userId != null)
{
ScarabUser user = ScarabUserManager.getInstance(userId);
setValueOnly(user.getUserName());
}
else
{
// any reason to set a user_id to null, once its already set?
setValueOnly(null);
}
setUserIdOnly(userId);
}
// in java/org/tigris/scarab/om/AttributeValue.java
protected void setUserIdOnly(Integer value)
throws TorqueException
{
if (!ObjectUtils.equals(value, getUserId()))
{
// if the value is set multiple times before saving only
// save the last saved value
if (!isNew() && !oldUserIdIsSet)
{
oldUserId = getUserId();
oldUserIdIsSet = true;
}
super.setUserId(value);
}
}
// in java/org/tigris/scarab/om/AttributeValue.java
public void setOptionIds(final Integer[] ids)
throws TorqueException, ScarabException
{
if (ids != null && ids.length > 0)
{
setOptionId(ids[0]);
}
if (ids != null && ids.length > 1)
{
for (int i=1; i<ids.length; i++)
{
final AttributeValue av = AttributeValue
.getNewInstance(getAttributeId(), getIssue());
setChainedValue(av);
av.setOptionId(ids[i]);
}
}
}
// in java/org/tigris/scarab/om/AttributeValue.java
public void setUserIds(final Integer[] ids)
throws TorqueException, ScarabException
{
if (ids != null && ids.length > 0)
{
setUserId(ids[0]);
}
if (ids != null && ids.length > 1)
{
for (int i=1; i<ids.length; i++)
{
final AttributeValue av = AttributeValue
.getNewInstance(getAttributeId(), getIssue());
setChainedValue(av);
av.setUserId(ids[i]);
}
}
}
// in java/org/tigris/scarab/om/AttributeValue.java
public boolean isRequired()
throws TorqueException, ScarabException
{
return getRModuleAttribute().getRequired();
}
// in java/org/tigris/scarab/om/AttributeValue.java
public RModuleAttribute getRModuleAttribute()
throws TorqueException, ScarabException
{
final Issue issue = getIssue();
RModuleAttribute rma = null;
if (issue != null)
{
final Module module = issue.getModule();
if (module != null)
{
rma = module.getRModuleAttribute(
getAttribute(), getIssue().getIssueType());
}
else
{
throw new ScarabException (L10NKeySet.ExceptionGeneral,
"Module is null: Please report this issue."); //EXCEPTION
}
}
else
{
throw new ScarabException (L10NKeySet.ExceptionGeneral,
"Issue is null: Please report this issue."); //EXCEPTION
}
return rma;
}
// in java/org/tigris/scarab/om/AttributeValue.java
public String getDisplayValue(ScarabLocalizationTool l10n)
throws TorqueException
{
String displayValue = null;
if(getAttribute().isOptionAttribute())
{
try
{
displayValue = getIssue().getModule().getRModuleOption( getAttributeOption(), getIssue().getIssueType()).getDisplayValue();
//displayValue = getRModuleAttribute().getDisplayValue();
}
catch (NullPointerException npe)
{
// Something wrong in the database ?
displayValue="";
}
}
else if(getAttribute().isUserAttribute())
{
displayValue = getScarabUser().getUserName();
}
else if(getAttribute().isDateAttribute())
{
displayValue = DateAttribute.dateFormat(getValue(), L10NKeySet.ShortDateDisplay.getMessage(l10n));
}
else
{
displayValue = getValue();
}
return displayValue;
}
// in java/org/tigris/scarab/om/AttributeValue.java
public AttributeOption getAttributeOption()
throws TorqueException
{
return getAttribute()
.getAttributeOption(getOptionId());
}
// in java/org/tigris/scarab/om/AttributeValue.java
public boolean isQuickSearchAttribute()
throws TorqueException
{
boolean result = false;
List qsAttributes = getIssue().getIssueType()
.getQuickSearchAttributes(getIssue().getModule());
for (int i=qsAttributes.size()-1; i>=0; i--)
{
if (((Attribute)qsAttributes.get(i)).equals(getAttribute()))
{
result = true;
break;
}
}
return result;
}
// in java/org/tigris/scarab/om/AttributeValue.java
public static AttributeValue getNewInstance(
RModuleAttribute rma, Issue issue) throws TorqueException
{
return getNewInstance(rma.getAttributeId(), issue);
}
// in java/org/tigris/scarab/om/AttributeValue.java
public static AttributeValue getNewInstance(
Integer attId, Issue issue) throws TorqueException
{
Attribute attribute = AttributeManager.getInstance(attId);
return getNewInstance(attribute, issue);
}
// in java/org/tigris/scarab/om/AttributeValue.java
public static synchronized AttributeValue getNewInstance(
Attribute attribute, Issue issue) throws TorqueException
{
AttributeValue attv = null;
try
{
String className = attribute
.getAttributeType().getJavaClassName();
attv = (AttributeValue)
Class.forName(className).newInstance();
attv.setAttribute(attribute);
attv.setIssue(issue);
attv.init();
}
catch (Exception e)
{
throw new TorqueException(e); //EXCEPTION
}
return attv;
}
// in java/org/tigris/scarab/om/AttributeValue.java
public AttributeValue copy() throws TorqueException
{
AttributeValue copyObj = AttributeValue
.getNewInstance(getAttributeId(), getIssue());
return copyInto(copyObj);
}
// in java/org/tigris/scarab/om/AttributeValue.java
public AttributeValue copy(Connection con) throws TorqueException
{
throw new RuntimeException("Unimplemented method AttributeValue:copy(Connection conn)");
//return copy();
}
// in java/org/tigris/scarab/om/AttributeValue.java
public void save(Connection dbcon)
throws TorqueException
{
if (isModified() && !getAttribute().isUserAttribute())
{
try
{
checkActivitySet(L10NKeySet.ExceptionCanNotSaveAttributeValue);
}
catch (Exception e)
{
throw new TorqueException(e);
}
if (saveActivity == null)
{
if (getDeleted())
{
saveActivity = ActivityManager
.create(getIssue(), getAttribute(), activitySet,
ActivityType.ATTRIBUTE_CHANGED, null, null, getNumericValue(), ScarabConstants.INTEGER_0,
getUserId(), null, getOptionId(), null,
getValue(), null, dbcon);
}
else
{
saveActivity = ActivityManager
.create(getIssue(), getAttribute(), activitySet,
ActivityType.ATTRIBUTE_CHANGED, null, null, oldNumericValue, getNumericValue(),
oldUserId, getUserId(), oldOptionId, getOptionId(),
oldValue, getValue(), dbcon);
}
}
}
super.save(dbcon);
if (chainedValue != null)
{
chainedValue.save(dbcon);
}
endActivitySet();
}
// in java/org/tigris/scarab/om/AttributeValue.java
public void setProperties(final AttributeValue attVal1)
throws TorqueException
{
setAttribute(attVal1.getAttribute());
setIssue(attVal1.getIssue());
setNumericValue(attVal1.getNumericValue());
setOptionId(attVal1.getOptionId());
setUserId(attVal1.getUserId());
setValue(attVal1.getValue());
}
// in java/org/tigris/scarab/om/RIssueTypeAttribute.java
public void setIsDefaultText(boolean b)
throws TorqueException
{
if (b && !getDefaultTextFlag())
{
// get related RIAs
List rias = getIssueType().getRIssueTypeAttributes(false);
// make sure no other rma is selected
for (int i=0; i<rias.size(); i++)
{
RIssueTypeAttribute ria = (RIssueTypeAttribute)rias.get(i);
if (ria.getDefaultTextFlag())
{
ria.setDefaultTextFlag(false);
ria.save();
break;
}
}
}
setDefaultTextFlag(b);
}
// in java/org/tigris/scarab/om/RIssueTypeAttribute.java
public boolean getIsDefaultText()
throws TorqueException
{
boolean isDefault = getDefaultTextFlag();
if (!isDefault && getAttribute().isTextAttribute())
{
// get related RIAs
List rias = getIssueType().getRIssueTypeAttributes();
// check if another is chosen
boolean anotherIsDefault = false;
for (int i=0; i<rias.size(); i++)
{
RIssueTypeAttribute ria = (RIssueTypeAttribute)rias.get(i);
if (ria.getDefaultTextFlag())
{
anotherIsDefault = true;
break;
}
}
if (!anotherIsDefault)
{
// locate the default text attribute
for (int i=0; i<rias.size(); i++)
{
RIssueTypeAttribute ria = (RIssueTypeAttribute)rias.get(i);
if (ria.getAttribute().isTextAttribute())
{
if (ria.getAttributeId().equals(getAttributeId()))
{
isDefault = true;
}
else
{
anotherIsDefault = true;
}
break;
}
}
}
}
return isDefault;
}
// in java/org/tigris/scarab/om/RIssueTypeAttribute.java
public void delete()
throws TorqueException
{
if (Log.get().isDebugEnabled())
{
Log.get().debug(
"Deleting SCARAB_R_ISSUETYPE_ATTRIBUTE where issuetype id="
+ getIssueTypeId() + " and attribute id=" + getAttributeId());
}
Criteria c = new Criteria()
.add(RIssueTypeAttributePeer.ISSUE_TYPE_ID, getIssueTypeId())
.add(RIssueTypeAttributePeer.ATTRIBUTE_ID, getAttributeId());
RIssueTypeAttributePeer.doDelete(c);
Attribute attr = getAttribute();
String attributeType = null;
attributeType = (attr.isUserAttribute() ? IssueType.USER : IssueType.NON_USER);
getIssueType().getRIssueTypeAttributes(false, attributeType).remove(this);
// delete issuetype-option mappings
if (attr.isOptionAttribute())
{
List optionList = getIssueType().getRIssueTypeOptions(attr, false);
if (optionList != null && !optionList.isEmpty())
{
ArrayList optionIdList = new ArrayList(optionList.size());
for (int i =0; i<optionList.size(); i++)
{
optionIdList.add(((RIssueTypeOption)optionList.get(i)).getOptionId());
}
Criteria c2 = new Criteria()
.add(RIssueTypeOptionPeer.ISSUE_TYPE_ID, getIssueTypeId())
.addIn(RIssueTypeOptionPeer.OPTION_ID, optionIdList);
RIssueTypeOptionPeer.doDelete(c2);
}
}
}
// in java/org/tigris/scarab/om/RIssueTypeAttribute.java
public RIssueTypeAttribute copyRia()
throws TorqueException
{
RIssueTypeAttribute ria = new RIssueTypeAttribute();
ria.setIssueTypeId(getIssueTypeId());
ria.setAttributeId(getAttributeId());
ria.setActive(getActive());
ria.setRequired(getRequired());
ria.setOrder(getOrder());
ria.setQuickSearch(getQuickSearch());
ria.setDefaultTextFlag(getDefaultTextFlag());
return ria;
}
// in java/org/tigris/scarab/om/MITList.java
public MITList copy() throws TorqueException
{
MITList copyObj = new MITList();
copyObj.setName(getName());
copyObj.setActive(getActive());
copyObj.setModifiable(getModifiable());
copyObj.setUserId(getUserId());
List v = getMITListItems();
for (int i = 0; i < v.size(); i++)
{
MITListItem obj = (MITListItem) v.get(i);
copyObj.addMITListItem(obj.copy());
}
return copyObj;
}
// in java/org/tigris/scarab/om/MITList.java
public MITList getPermittedSublist(String permission, ScarabUser user)
throws TorqueException
{
String[] perms = { permission };
return getPermittedSublist(perms, user);
}
// in java/org/tigris/scarab/om/MITList.java
public MITList getPermittedSublist(String[] permissions, ScarabUser user)
throws TorqueException
{
MITList sublist = new MITList();
ScarabUser userB = getScarabUser();
if (userB != null)
{
sublist.setScarabUser(userB);
}
List items = getExpandedMITListItems();
sublist.isAllMITs = this.isAllMITs;
Module[] validModules = user.getModules(permissions);
Set moduleIds = new HashSet();
for (int j = 0; j < validModules.length; j++)
{
moduleIds.add(validModules[j].getModuleId());
}
for (Iterator i = items.iterator(); i.hasNext();)
{
MITListItem item = (MITListItem) i.next();
if (moduleIds.contains(item.getModuleId()))
{
// use a copy of the item here to avoid changing the the
// list_id of the original
sublist.addMITListItem(item.copy());
}
}
return sublist;
}
// in java/org/tigris/scarab/om/MITList.java
public Module getModule() throws TorqueException
{
if (!isSingleModule())
{
throw new IllegalStateException(
"method should not be called on"
+ " a list including more than one module."); //EXCEPTION
}
return getModule(getFirstItem());
}
// in java/org/tigris/scarab/om/MITList.java
public IssueType getIssueType() throws TorqueException
{
if (!isSingleIssueType())
{
throw new IllegalStateException(
"method should not be called on"
+ " a list including more than one issue type."); //EXCEPTION
}
return getFirstItem().getIssueType();
}
// in java/org/tigris/scarab/om/MITList.java
Module getModule(MITListItem item) throws TorqueException
{
Module module = null;
if (item.getModuleId() == null)
{
ScarabUser user = getScarabUser();
module = user.getCurrentModule();
}
else
{
module = item.getModule();
}
return module;
}
// in java/org/tigris/scarab/om/MITList.java
public void setScarabUser(ScarabUser v) throws TorqueException
{
if (v == null)
{
throw new IllegalArgumentException("cannot set user to null."); //EXCEPTION
}
super.setScarabUser(v);
aScarabUser = v;
expandedList = null;
}
// in java/org/tigris/scarab/om/MITList.java
public ScarabUser getScarabUser() throws TorqueException
{
ScarabUser user = null;
if (aScarabUser == null)
{
user = super.getScarabUser();
}
else
{
user = aScarabUser;
}
return user;
}
// in java/org/tigris/scarab/om/MITList.java
public List getAttributes(final boolean activeOnly, final boolean commonOnly)
throws TorqueException,
DataSetException
{
Set matchingAttributes = new HashSet();
Iterator iter = iterator();
while (iter.hasNext())
{
final MITListItem item = (MITListItem)iter.next();
final List rmas = getModule(item).getRModuleAttributes(
item.getIssueType());
for (Iterator i = rmas.iterator(); i.hasNext();)
{
final RModuleAttribute rma = (RModuleAttribute) i.next();
final Attribute att = rma.getAttribute();
if ((!activeOnly || rma.getActive()))
{
boolean wantedAttribute = (commonOnly) ? isCommon(att,
activeOnly) : true;
if (size() == 1 || wantedAttribute)
{
matchingAttributes.add(att);
}
}
}
if(commonOnly)
{
// don't need to iterate through other Items, because the
// intersection with the first MITListItem is sufficient
// to fulfill the commonOnly rule.
break;
}
}
// Finally copy the resultset into an ArrayList for
// compatibility to older implementaiton of this method.
final List result = new ArrayList();
iter = matchingAttributes.iterator();
while(iter.hasNext())
{
result.add(iter.next());
}
return result;
}
// in java/org/tigris/scarab/om/MITList.java
public List getCommonAttributes() throws TorqueException, DataSetException
{
return getAttributes(true,true);
}
// in java/org/tigris/scarab/om/MITList.java
public List getCommonAttributes(final boolean activeOnly) throws TorqueException, DataSetException
{
return getAttributes(activeOnly, true);
}
// in java/org/tigris/scarab/om/MITList.java
public boolean isCommon(final Attribute attribute, final boolean activeOnly)
throws TorqueException, DataSetException
{
final Criteria crit = new Criteria();
addToCriteria(
crit,
RModuleAttributePeer.MODULE_ID,
RModuleAttributePeer.ISSUE_TYPE_ID);
crit.add(RModuleAttributePeer.ATTRIBUTE_ID, attribute.getAttributeId());
if (activeOnly)
{
crit.add(RModuleAttributePeer.ACTIVE, true);
}
return size() == RModuleAttributePeer.count(crit);
}
// in java/org/tigris/scarab/om/MITList.java
public boolean isCommon(final Attribute attribute) throws TorqueException, DataSetException
{
return isCommon(attribute, true);
}
// in java/org/tigris/scarab/om/MITList.java
public List getCommonNonUserAttributes() throws TorqueException, DataSetException
{
assertNotEmpty();
final List matchingAttributes = new ArrayList();
final MITListItem item = getFirstItem();
final List rmas = getModule(item).getRModuleAttributes(item.getIssueType());
final Iterator i = rmas.iterator();
while (i.hasNext())
{
final RModuleAttribute rma = (RModuleAttribute) i.next();
final Attribute att = rma.getAttribute();
if (!att.isUserAttribute() && rma.getActive() && isCommon(att))
{
matchingAttributes.add(att);
}
}
return matchingAttributes;
}
// in java/org/tigris/scarab/om/MITList.java
public List getCommonOptionAttributes() throws TorqueException, DataSetException
{
assertNotEmpty();
final List matchingAttributes = new ArrayList();
final MITListItem item = getFirstItem();
final List rmas = getModule(item).getRModuleAttributes(item.getIssueType());
final Iterator i = rmas.iterator();
while (i.hasNext())
{
final RModuleAttribute rma = (RModuleAttribute) i.next();
final Attribute att = rma.getAttribute();
if (att.isOptionAttribute() && rma.getActive() && isCommon(att))
{
matchingAttributes.add(att);
}
}
return matchingAttributes;
}
// in java/org/tigris/scarab/om/MITList.java
public List<Attribute> getCommonUserAttributes(final boolean activeOnly)
throws TorqueException, DataSetException
{
List<Attribute> attributes = null;
if (isSingleModuleIssueType())
{
attributes =
getModule().getUserAttributes(getIssueType(), activeOnly);
}
else
{
final List<Attribute> matchingAttributes = new ArrayList<Attribute>();
final MITListItem item = getFirstItem();
final List<RModuleAttribute> rmas =
getModule(item).getRModuleAttributes(
item.getIssueType(),
activeOnly,
Module.USER);
final Iterator<RModuleAttribute> i = rmas.iterator();
while (i.hasNext())
{
final RModuleAttribute rma = i.next();
final Attribute att = rma.getAttribute();
if ((!activeOnly || rma.getActive())
&& isCommon(att, activeOnly))
{
matchingAttributes.add(att);
}
}
attributes = matchingAttributes;
}
return attributes;
}
// in java/org/tigris/scarab/om/MITList.java
public List<Attribute> getCommonUserAttributes() throws TorqueException, DataSetException
{
return getCommonUserAttributes(false);
}
// in java/org/tigris/scarab/om/MITList.java
public List<ScarabUser> getPotentialAssignees(boolean includeCommitters)
throws TorqueException, DataSetException
{
List<ScarabUser> users = new ArrayList<ScarabUser>();
List<String> perms = getUserAttributePermissions();
if (includeCommitters && !perms.contains(ScarabSecurity.ISSUE__ENTER))
{
perms.add(ScarabSecurity.ISSUE__ENTER);
}
if (isSingleModule())
{
ScarabUser[] userArray = getModule().getUsers(perms);
for (int i = 0; i < userArray.length; i++)
{
users.add(userArray[i]);
}
}
else
{
MITListItem item = getFirstItem();
ScarabUser[] userArray = getModule(item).getUsers(perms);
List<Module> modules = getModules();
for (int i = 0; i < userArray.length; i++)
{
boolean validUser = false;
ScarabUser user = userArray[i];
for (Iterator<String> j = perms.iterator(); j.hasNext() && !validUser;)
{
validUser = user.hasPermission(j.next(), modules);
}
if (validUser)
{
users.add(user);
}
}
}
return users;
}
// in java/org/tigris/scarab/om/MITList.java
public List<String> getUserAttributePermissions() throws TorqueException, DataSetException
{
final List userAttrs = getCommonUserAttributes();
final List<String> permissions = new ArrayList<String>();
for (int i = 0; i < userAttrs.size(); i++)
{
final String permission = ((Attribute) userAttrs.get(i)).getPermission();
if (!permissions.contains(permission))
{
permissions.add(permission);
}
}
return permissions;
}
// in java/org/tigris/scarab/om/MITList.java
public List getAllRModuleUserAttributes()
throws TorqueException, DataSetException, TurbineSecurityException
{
List rmuas = getSavedRMUAs();
return rmuas;
}
// in java/org/tigris/scarab/om/MITList.java
public List getCommonRModuleUserAttributes()
throws TorqueException, DataSetException, TurbineSecurityException
{
final List matchingRMUAs = new ArrayList();
List rmuas = getSavedRMUAs();
Iterator i = rmuas.iterator();
final ScarabUser user = getScarabUser();
while (i.hasNext())
{
final RModuleUserAttribute rmua = (RModuleUserAttribute) i.next();
final Attribute att = rmua.getAttribute();
if (isCommon(att, false))
{
matchingRMUAs.add(rmua);
}
}
// None of the saved RMUAs are common for these pairs
// Delete them and seek new ones.
if (matchingRMUAs.isEmpty())
{
i = rmuas.iterator();
while (i.hasNext())
{
final RModuleUserAttribute rmua = (RModuleUserAttribute) i.next();
rmua.delete(user);
}
final int sizeGoal = 3;
int moreAttributes = sizeGoal;
// First try saved RMUAs for first module-issuetype pair
final MITListItem item = getFirstItem();
final Module module = getModule(item);
final IssueType issueType = item.getIssueType();
rmuas = user.getRModuleUserAttributes(module, issueType);
// Next try default RMUAs for first module-issuetype pair
if (rmuas.isEmpty())
{
rmuas = module.getDefaultRModuleUserAttributes(issueType);
}
// Loop through these and if find common ones, save the RMUAs
i = rmuas.iterator();
while (i.hasNext() && moreAttributes > 0)
{
final RModuleUserAttribute rmua = (RModuleUserAttribute) i.next();
final Attribute att = rmua.getAttribute();
if (isCommon(att, false) && !matchingRMUAs.contains(rmua))
{
final RModuleUserAttribute newRmua =
getNewRModuleUserAttribute(att);
newRmua.setOrder(1);
newRmua.save();
matchingRMUAs.add(rmua);
moreAttributes--;
}
}
// if nothing better, go with random common attributes
moreAttributes = sizeGoal - matchingRMUAs.size();
if (moreAttributes > 0)
{
Iterator attributes = getCommonAttributes(false).iterator();
int k = 1;
while (attributes.hasNext() && moreAttributes > 0)
{
Attribute att = (Attribute) attributes.next();
boolean isInList = false;
i = matchingRMUAs.iterator();
while (i.hasNext())
{
RModuleUserAttribute rmua =
(RModuleUserAttribute) i.next();
if (rmua.getAttribute().equals(att))
{
isInList = true;
break;
}
}
if (!isInList)
{
RModuleUserAttribute rmua =
getNewRModuleUserAttribute(att);
rmua.setOrder(k++);
rmua.save();
matchingRMUAs.add(rmua);
moreAttributes--;
}
}
}
}
return matchingRMUAs;
}
// in java/org/tigris/scarab/om/MITList.java
protected RModuleUserAttribute getNewRModuleUserAttribute(Attribute attribute)
throws TorqueException
{
RModuleUserAttribute result = RModuleUserAttributeManager.getInstance();
result.setUserId(getUserId());
result.setAttributeId(attribute.getAttributeId());
if (isSingleModuleIssueType())
{
result.setModuleId(getModule().getModuleId());
result.setIssueTypeId(getIssueType().getIssueTypeId());
}
if (!isNew())
{
result.setListId(getListId());
}
return result;
}
// in java/org/tigris/scarab/om/MITList.java
private List getMatchingRMOs(List rmos) throws TorqueException, Exception
{
List matchingRMOs = new ArrayList();
if (rmos != null)
{
for (Iterator i = rmos.iterator(); i.hasNext();)
{
RModuleOption rmo = (RModuleOption) i.next();
AttributeOption option = rmo.getAttributeOption();
if (rmo.getActive() && isCommon(option))
{
matchingRMOs.add(rmo);
}
}
}
return matchingRMOs;
}
// in java/org/tigris/scarab/om/MITList.java
protected List getSavedRMUAs() throws TorqueException
{
Criteria crit = new Criteria();
crit.add(RModuleUserAttributePeer.USER_ID, getUserId());
if (!isNew())
{
Long listId = getListId();
crit.add(RModuleUserAttributePeer.LIST_ID, listId);
}
else
{
Integer moduleId = null;
Integer issueTypeId = null;
if(isSingleModuleIssueType())
{
Module module = getModule();
moduleId = module.getModuleId();
IssueType issueType = getIssueType();
issueTypeId = issueType.getIssueTypeId();
}
else if (isSingleModule())
{
moduleId = getModule().getModuleId();
}
else if (isSingleIssueType())
{
IssueType issueType = getIssueType();
issueTypeId = issueType.getIssueTypeId();
}
crit.add(RModuleUserAttributePeer.LIST_ID, null);
crit.add(RModuleUserAttributePeer.MODULE_ID, moduleId);
crit.add(RModuleUserAttributePeer.ISSUE_TYPE_ID, issueTypeId);
}
crit.addAscendingOrderByColumn(
RModuleUserAttributePeer.PREFERRED_ORDER);
return RModuleUserAttributePeer.doSelect(crit);
}
// in java/org/tigris/scarab/om/MITList.java
public List getCommonLeafRModuleOptions(final Attribute attribute)
throws TorqueException, ScarabException
{
assertNotEmpty();
final MITListItem item = getFirstItem();
final List rmos =
getModule(item).getLeafRModuleOptions(
attribute,
item.getIssueType());
try
{
return getMatchingRMOs(rmos);
}
catch(Exception e)
{
throw new ScarabException(L10NKeySet.ExceptionGeneral,e);
}
}
// in java/org/tigris/scarab/om/MITList.java
public List getCommonRModuleOptionTree(Attribute attribute)
throws TorqueException, ScarabException
{
assertNotEmpty();
final MITListItem item = getFirstItem();
final List rmos =
getModule(item).getOptionTree(attribute, item.getIssueType());
try
{
return getMatchingRMOs(rmos);
}
catch (Exception ex)
{
throw new ScarabException(L10NKeySet.ExceptionGeneral,ex);
}
}
// in java/org/tigris/scarab/om/MITList.java
public List getAllRModuleOptionTree(Attribute attribute)
throws TorqueException
{
assertNotEmpty();
// Get all isse types from this MITList
List listItems = getExpandedMITListItems();
// Get all attribute options from all issue types for the requested attribute
List attributeOptions = new ArrayList();
if (listItems!=null) {
Iterator listItemIterator = listItems.iterator();
while (listItemIterator.hasNext()) {
MITListItem item = (MITListItem)listItemIterator.next();
List rmos = getModule(item).getOptionTree(attribute, item.getIssueType());
mergeRModuleOptionsIgnoreDuplicates(attributeOptions, rmos);
}
}
return attributeOptions;
}
// in java/org/tigris/scarab/om/MITList.java
private void mergeRModuleOptionsIgnoreDuplicates(List masterList, List addList)
throws TorqueException {
// Get a set of all existing option ids
Set optionIds = new HashSet();
Iterator masterIterator = masterList.iterator();
while (masterIterator.hasNext()) {
RModuleOption option = (RModuleOption)masterIterator.next();
optionIds.add(option.getOptionId());
}
// add all options not already present in the list, add only active options
Iterator addIterator = addList.iterator();
while (addIterator.hasNext()) {
RModuleOption rmo = (RModuleOption)addIterator.next();
if (rmo.getActive() && !optionIds.contains(rmo.getOptionId())) {
masterList.add(rmo);
}
}
}
// in java/org/tigris/scarab/om/MITList.java
public List getDescendantsUnion(AttributeOption option) throws TorqueException
{
assertNotEmpty();
List matchingRMOs = new ArrayList();
Iterator items = iterator();
while (items.hasNext())
{
MITListItem item = (MITListItem) items.next();
IssueType issueType = item.getIssueType();
RModuleOption parent =
getModule(item).getRModuleOption(option, issueType);
if (parent != null)
{
Iterator i = parent.getDescendants(issueType).iterator();
while (i.hasNext())
{
RModuleOption rmo = (RModuleOption) i.next();
if (!matchingRMOs.contains(rmo))
{
matchingRMOs.add(rmo);
}
}
}
}
return matchingRMOs;
}
// in java/org/tigris/scarab/om/MITList.java
public boolean isCommon(final AttributeOption option) throws TorqueException, DataSetException
{
return isCommon(option, true);
}
// in java/org/tigris/scarab/om/MITList.java
public boolean isCommon(final AttributeOption option, final boolean activeOnly)
throws TorqueException, DataSetException
{
final Criteria crit = new Criteria();
addToCriteria(
crit,
RModuleOptionPeer.MODULE_ID,
RModuleOptionPeer.ISSUE_TYPE_ID);
crit.add(RModuleOptionPeer.OPTION_ID, option.getOptionId());
if (activeOnly)
{
crit.add(RModuleOptionPeer.ACTIVE, true);
}
return size() == RModuleOptionPeer.count(crit);
}
// in java/org/tigris/scarab/om/MITList.java
public List<Module> getModules() throws TorqueException
{
assertNotEmpty();
List items = getExpandedMITListItems();
ArrayList modules = new ArrayList(items.size());
Iterator<MITListItem> i = items.iterator();
while (i.hasNext())
{
Module m = i.next().getModule();
if (!modules.contains(m))
{
modules.add(m);
}
}
return modules;
}
// in java/org/tigris/scarab/om/MITList.java
public void addToCriteria(Criteria crit) throws TorqueException
{
addToCriteria(crit, IssuePeer.MODULE_ID, IssuePeer.TYPE_ID);
}
// in java/org/tigris/scarab/om/MITList.java
private void addToCriteria(
Criteria crit,
String moduleField,
String issueTypeField)
throws TorqueException
{
if (!isSingleModule() && isSingleIssueType())
{
crit.addIn(moduleField, getModuleIds());
crit.add(issueTypeField, getIssueType().getIssueTypeId());
}
else if (isSingleModule() && !isSingleIssueType())
{
crit.add(moduleField, getModule().getModuleId());
crit.addIn(issueTypeField, getIssueTypeIds());
}
else if (isAllMITs)
{
crit.addIn(moduleField, getModuleIds());
// we do this to avoid including templates in results
crit.addIn(issueTypeField, getIssueTypeIds());
}
else if (size() > 0)
{
List items = getExpandedMITListItems();
Iterator i = items.iterator();
Criteria.Criterion c = null;
while (i.hasNext())
{
MITListItem item = (MITListItem) i.next();
Criteria.Criterion c1 =
crit.getNewCriterion(
moduleField,
item.getModuleId(),
Criteria.EQUAL);
Criteria.Criterion c2 =
crit.getNewCriterion(
issueTypeField,
item.getIssueTypeId(),
Criteria.EQUAL);
c1.and(c2);
if (c == null)
{
c = c1;
}
else
{
c.or(c1);
}
}
crit.add(c);
}
}
// in java/org/tigris/scarab/om/MITList.java
public void addAll(MITList list) throws TorqueException
{
List currentList = getExpandedMITListItems();
for (Iterator i = list.getExpandedMITListItems().iterator();
i.hasNext();
)
{
MITListItem item = (MITListItem) i.next();
if (!currentList.contains(item))
{
addMITListItem(item);
}
}
}
// in java/org/tigris/scarab/om/MITList.java
public void addMITListItem(MITListItem item) throws TorqueException
{
super.addMITListItem(item);
expandedList = null;
calculateIsAllMITs(item);
}
// in java/org/tigris/scarab/om/MITList.java
private void addIssueTypes(Module module, List items) throws TorqueException
{
Iterator rmits = module.getRModuleIssueTypes().iterator();
while (rmits.hasNext())
{
MITListItem newItem = MITListItemManager.getInstance();
newItem.setModuleId(module.getModuleId());
newItem.setIssueTypeId(
((RModuleIssueType) rmits.next()).getIssueTypeId());
newItem.setListId(getListId());
items.add(newItem);
}
}
// in java/org/tigris/scarab/om/MITList.java
public void save(Connection con) throws TorqueException
{
super.save(con);
if (itemsScheduledForDeletion != null
&& !itemsScheduledForDeletion.isEmpty())
{
List itemIds = new ArrayList(itemsScheduledForDeletion.size());
for (Iterator iter = itemsScheduledForDeletion.iterator();
iter.hasNext();
)
{
MITListItem item = (MITListItem) iter.next();
if (!item.isNew())
{
itemIds.add(item.getItemId());
}
}
if (!itemIds.isEmpty())
{
Criteria crit = new Criteria();
crit.addIn(MITListItemPeer.ITEM_ID, itemIds);
MITListItemPeer.doDelete(crit);
}
}
}
// in java/org/tigris/scarab/om/MITList.java
public String getAttributeDisplayName(final Attribute attribute)
throws TorqueException
{
String displayName = null;
for( MITListItem item : ((List<MITListItem>)getExpandedMITListItems()))
{
final String nameCandidate = item.getAttributeDisplayName(attribute);
displayName = displayName == null ? nameCandidate : displayName;
if(!displayName.equals(nameCandidate))
{
displayName = attribute.getName();
break;
}
}
return displayName;
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
GlobalParameter gp = (GlobalParameter)om;
Serializable moduleId = gp.getModuleId();
String name = gp.getName();
if (moduleId == null)
{
// if altering a global parameter, its possible the
// module overrides are invalid.
getMethodResult().removeAll(MANAGER_KEY, name);
}
else
{
getMethodResult().remove(MANAGER_KEY, name, GET_STRING,
moduleId);
}
return oldOm;
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
private static GlobalParameter getInstance(String name)
throws TorqueException
{
return getInstance(name, null);
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
private static GlobalParameter getInstance(String name, Module module)
throws TorqueException
{
GlobalParameter result = null;
Criteria crit = new Criteria();
crit.add(GlobalParameterPeer.NAME, name);
if (module == null)
{
crit.add(GlobalParameterPeer.MODULE_ID, null);
}
else
{
crit.add(GlobalParameterPeer.MODULE_ID, module.getModuleId());
}
List parameters = GlobalParameterPeer.doSelect(crit);
if (!parameters.isEmpty())
{
result = (GlobalParameter)parameters.get(0);
}
return result;
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
private static String getStringModule(String name, Module module )
throws TorqueException
{
String value = (String) getMethodResult()
.get(MANAGER_KEY, name, GET_STRING, module.getModuleId());
if(value == null)
{
GlobalParameter p = getInstance(name, module);
if (p != null)
{
value = p.getValue();
}
if(value==null)
{
value = "";
}
getMethodResult().put(value, MANAGER_KEY, name, GET_STRING, module.getModuleId());
}
return value;
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
private static String getStringGlobal(String name)
throws TorqueException
{
String value = (String) getMethodResult()
.get(MANAGER_KEY, name, GET_STRING );
if(value == null)
{
GlobalParameter p = getInstance(name);
if (p != null)
{
value = p.getValue();
}
if(value==null || value.equals(""))
{
value = Turbine.getConfiguration().getString(name);
}
if(value==null)
{
value = "";
}
getMethodResult().put(value, MANAGER_KEY, name, GET_STRING);
}
return value;
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
public static String getString(String name)
throws TorqueException
{
return getStringGlobal(name);
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
public static String getString(String name, Module module)
throws TorqueException
{
String value = getStringModule(name, module);
if (value.equals(""))
{
value = getStringGlobal(name);
}
return value;
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
public static String getStringFromHierarchy(String name, Module module, String def)
throws TorqueException
{
String value = getStringModule( name, module );
if(value.equals(""))
{
Module parentModule = module.getParent();
if(parentModule != null)
{
value = getStringFromHierarchy(name, parentModule, def);
}
}
if(value.equals(""))
{
value = getStringGlobal(name);
}
if(value.equals(""))
{
value = def;
}
return value;
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
public static void setString(String name, String value)
throws TorqueException
{
setString(name, null, value);
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
public static void setString(String name, Module module, String value)
throws TorqueException
{
GlobalParameter p = getInstance(name, module);
if (p == null)
{
p = getInstance();
p.setName(name);
p.setModuleId(module.getModuleId());
}
p.setValue(value);
p.save();
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
public static boolean getBoolean(String name)
throws TorqueException
{
return toBoolean(getString(name));
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
public static boolean getBoolean(String name, Module module)
throws TorqueException
{
return toBoolean(getString(name, module));
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
public static boolean getBooleanFromHierarchy(String name, Module module, boolean def)
throws TorqueException
{
String defAsString = (def)? "TRUE":"FALSE";
return toBoolean(getStringFromHierarchy(name, module, defAsString ));
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
public static void setBoolean(String name, boolean value)
throws TorqueException
{
setString(name, (value ? "TRUE" : "FALSE"));
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
public static void setBoolean(String name, Module module, boolean value)
throws TorqueException
{
setString(name, module, (value ? "TRUE" : "FALSE"));
}
// in java/org/tigris/scarab/om/GlobalParameterManager.java
public static List getStringList(String name)
throws TorqueException
{
return toStringList(getString(name));
}
// in java/org/tigris/scarab/om/Query.java
public ScarabUser getScarabUser()
throws TorqueException
{
ScarabUser user = this.scarabUser;
if (user == null)
{
user = super.getScarabUser();
}
return user;
}
// in java/org/tigris/scarab/om/Query.java
public void setScarabUser(ScarabUser v)
throws TorqueException
{
this.scarabUser = v;
super.setScarabUser(v);
}
// in java/org/tigris/scarab/om/Query.java
public void setModule(Module me)
throws TorqueException
{
if (me == null)
{
setModuleId((Integer)null);
}
else
{
Integer id = me.getModuleId();
if (id == null)
{
throw new TorqueException("Modules must be saved prior to " +
"being associated with other objects."); //EXCEPTION
}
setModuleId(id);
}
}
// in java/org/tigris/scarab/om/Query.java
public Module getModule()
throws TorqueException
{
Module module = null;
Integer id = getModuleId();
if ( id != null )
{
module = ModuleManager.getInstance(id);
}
return module;
}
// in java/org/tigris/scarab/om/Query.java
public boolean canDelete(ScarabUser user)
throws TorqueException
{
// can delete a query if they have delete permission
// Or if is their personal query
return (user.hasPermission(ScarabSecurity.ITEM__DELETE, getModule())
|| (user.getUserId().equals(getUserId())
&& (getScopeId().equals(Scope.PERSONAL__PK))));
}
// in java/org/tigris/scarab/om/Query.java
public boolean canEdit(ScarabUser user)
throws TorqueException
{
return canDelete(user);
}
// in java/org/tigris/scarab/om/Query.java
public boolean saveAndSendEmail(final ScarabUser user,
final Module module,
final TemplateContext context)
throws TorqueException, ScarabException
{
// If it's a module scoped query, user must have Item | Approve
// permission, Or its Approved field gets set to false
Exception exception=null; // temporary store a thrown exception
if (getScopeId().equals(Scope.PERSONAL__PK)
|| user.hasPermission(ScarabSecurity.ITEM__APPROVE, module))
{
setApproved(true);
}
else
{
setApproved(false);
// Send Email to the people with module edit ability so
// that they can approve the new template
if (context != null)
{
final String template = Turbine.getConfiguration().
getString("scarab.email.requireapproval.template",
"RequireApproval.vm");
final ScarabUser[] toUsers = module
.getUsers(ScarabSecurity.ITEM__APPROVE);
if (Log.get().isDebugEnabled())
{
if (toUsers == null || toUsers.length ==0)
{
Log.get().debug("No users to approve query.");
}
else
{
Log.get().debug("Users to approve query: ");
for (int i=0; i<toUsers.length; i++)
{
Log.get().debug(toUsers[i].getEmail());
}
}
}
final EmailContext ectx = new EmailContext();
ectx.setUser(user);
ectx.setModule(module);
ectx.setDefaultTextKey("NewQueryRequiresApproval");
final String fromUser = "scarab.email.default";
try
{
Email.sendEmail(ectx,
module,
fromUser,
module.getSystemEmail(),
Arrays.asList(toUsers),
null,
template);
}
catch (Exception e)
{
exception = e;
}
}
}
if (getMITList() != null)
{
getMITList().save();
// it would be good if this updated our list id, but it doesn't
// happen automatically so reset it.
setMITList(getMITList());
}
save();
if(exception != null)
{
throw new ScarabException(L10NKeySet.ExceptionGeneral, exception);
}
return true;
}
// in java/org/tigris/scarab/om/Query.java
public MITList getMITList()
throws TorqueException
{
MITList mitlist = super.getMITList();
if (mitlist == null)
{
mitlist = MITListManager.getSingleItemList(getModule(),
getIssueType(), null);
}
return mitlist;
}
// in java/org/tigris/scarab/om/Query.java
public void subscribe(ScarabUser user, Integer frequencyId)
throws TorqueException
{
RQueryUser rqu = getRQueryUser(user);
rqu.setSubscriptionFrequency(frequencyId);
rqu.setIsSubscribed(true);
rqu.save();
}
// in java/org/tigris/scarab/om/Query.java
public void unSubscribe(ScarabUser user)
throws TorqueException
{
RQueryUser rqu = getRQueryUser(user);
if (rqu.getIsdefault())
{
rqu.setIsSubscribed(false);
rqu.save();
}
else
{
rqu.delete(user);
}
}
// in java/org/tigris/scarab/om/Query.java
public RQueryUser getRQueryUser(ScarabUser user)
throws TorqueException
{
RQueryUser result = null;
Object obj = ScarabCache.get(this, GET_R_QUERY_USER, user);
if (obj == null)
{
Criteria crit = new Criteria();
crit.add(RQueryUserPeer.QUERY_ID, getQueryId());
crit.add(RQueryUserPeer.USER_ID, user.getUserId());
List rqus = RQueryUserPeer.doSelect(crit);
if (!rqus.isEmpty())
{
result = (RQueryUser)rqus.get(0);
}
else
{
result = new RQueryUser();
result.setQuery(this);
result.setUserId(user.getUserId());
}
ScarabCache.put(result, this, GET_R_QUERY_USER, user);
}
else
{
result = (RQueryUser)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Query.java
public void approve(final ScarabUser user, final boolean approved)
throws TorqueException, ScarabException
{
final Module module = getModule();
if (user.hasPermission(ScarabSecurity.ITEM__APPROVE, module))
{
setApproved(true);
if (!approved)
{
setScopeId(Scope.PERSONAL__PK);
}
save();
}
else
{
throw new ScarabException(L10NKeySet.YouDoNotHavePermissionToAction);
}
}
// in java/org/tigris/scarab/om/Query.java
public void delete(ScarabUser user)
throws TorqueException, ScarabException
{
final Module module = getModule();
if (user.hasPermission(ScarabSecurity.ITEM__APPROVE, module)
|| (user.getUserId().equals(getUserId())
&& getScopeId().equals(Scope.PERSONAL__PK)))
{
// Delete user-query maps.
final List rqus = getRQueryUsers();
for (int i=0; i<rqus.size(); i++)
{
final RQueryUser rqu = (RQueryUser)rqus.get(i);
rqu.delete(user);
}
setDeleted(true);
save();
}
else
{
throw new ScarabException(L10NKeySet.YouDoNotHavePermissionToAction);
}
}
// in java/org/tigris/scarab/om/Query.java
public void copyQuery(ScarabUser user)
throws TorqueException
{
Query newQuery = new Query();
newQuery.setName(getName() + " (copy)");
newQuery.setDescription(getDescription());
newQuery.setValue(getValue());
newQuery.setModuleId(getModuleId());
newQuery.setIssueTypeId(getIssueTypeId());
newQuery.setListId(getListId());
newQuery.setApproved(getApproved());
newQuery.setCreatedDate(new Date());
newQuery.setUserId(user.getUserId());
newQuery.setScopeId(getScopeId());
newQuery.save();
RQueryUser rqu = getRQueryUser(user);
if (rqu != null)
{
RQueryUser rquNew = new RQueryUser();
rquNew.setQueryId(newQuery.getQueryId());
rquNew.setUserId(user.getUserId());
rquNew.setSubscriptionFrequency(rqu.getSubscriptionFrequency());
rquNew.setIsdefault(rqu.getIsdefault());
rquNew.setIsSubscribed(rqu.getIsSubscribed());
rquNew.save();
}
}
// in java/org/tigris/scarab/om/ActivityManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap.get(ActivityPeer.ISSUE_ID);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity getInstance(String id)
throws TorqueException
{
return getInstance(new Long(id));
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity createNumericActivity(Issue issue, Attribute attribute,
ActivitySet activitySet,
Attachment attachment,
Integer oldNumericValue,
Integer newNumericValue)
throws TorqueException
{
return create(issue,attribute,activitySet,ActivityType.ATTRIBUTE_CHANGED,null,attachment,
oldNumericValue, newNumericValue,
null, null, null, null, null, null);
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity createUserActivity(Issue issue, Attribute attribute,
ActivitySet activitySet,
Attachment attachment,
Integer oldUserId,
Integer newUserId)
throws TorqueException
{
String oldUsername = null;
String newUsername = null;
if (oldUserId != null)
{
oldUsername = ScarabUserManager.getInstance(oldUserId).getUserName();
}
if (newUserId != null)
{
newUsername = ScarabUserManager.getInstance(newUserId).getUserName();
}
return create(issue,attribute,activitySet,ActivityType.USER_ATTRIBUTE_CHANGED,null,attachment,
null, null,
oldUserId, newUserId,
null, null, oldUsername, newUsername);
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity createAddDependencyActivity(Issue issue,
ActivitySet activitySet,
Depend depend)
throws TorqueException
{
return create(issue,null,activitySet,ActivityType.DEPENDENCY_CREATED,null,null,depend,
null, null,
null, null,
null, null,
null, depend.getDependType().getName(), null);
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity createChangeDependencyActivity(Issue issue,
ActivitySet activitySet,
Depend depend,
String oldTextValue,
String newTextValue)
throws TorqueException
{
return create(issue,null,activitySet,ActivityType.DEPENDENCY_CHANGED,null,null,depend,
null, null,
null, null,
null, null,
oldTextValue, newTextValue, null);
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity createDeleteDependencyActivity(Issue issue,
ActivitySet activitySet,
Depend depend)
throws TorqueException
{
return create(issue,null,activitySet,ActivityType.DEPENDENCY_DELETED,null,null,depend,
null, null,
null, null,
null, null,
depend.getDependType().getName(), null, null);
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity createTextActivity(Issue issue,
ActivitySet activitySet,
ActivityType type,
String newTextValue)
throws TorqueException
{
return create(issue,null,activitySet,type,null,null,
null, null,
null, null,
null, null,
null, newTextValue);
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity createTextActivity(Issue issue,
ActivitySet activitySet,
ActivityType type,
Attachment attachment)
throws TorqueException
{
return create(issue,null,activitySet,type,null,attachment,
null, null,
null, null,
null, null,
null, null);
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity createTextActivity(Issue issue, Attribute attribute,
ActivitySet activitySet,
ActivityType type,
String oldTextValue,
String newTextValue)
throws TorqueException
{
return create(issue,attribute,activitySet,type,null,null,
null, null,
null, null,
null, null,
oldTextValue, newTextValue);
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity createTextActivity(Issue issue,
ActivitySet activitySet,
ActivityType type,
Attachment attachment,
String oldTextValue,
String newTextValue)
throws TorqueException
{
return create(issue,null,activitySet,type,null,attachment,
null, null,
null, null,
null, null,
oldTextValue, newTextValue);
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity createTextActivity(Issue issue, Attribute attribute,
ActivitySet activitySet,
ActivityType type,
String description,
Attachment attachment,
String oldTextValue,
String newTextValue)
throws TorqueException
{
return create(issue,attribute,activitySet,type,description,attachment,
null, null,
null, null,
null, null,
oldTextValue, newTextValue);
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity createReportIssueActivity(Issue issue,
ActivitySet activitySet,
String message)
throws TorqueException
{
return create(issue, AttributeManager.getInstance(ScarabConstants.INTEGER_0),
activitySet, ActivityType.ISSUE_CREATED, null, null,
null, null, null, null, null, null, null, null);
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity createDeleteIssueActivity(Issue issue, ActivitySet activitySet)
throws TorqueException
{
return create(issue, AttributeManager.getInstance(ScarabConstants.INTEGER_0),
activitySet, ActivityType.ISSUE_DELETED, null, null,
null, null, null, null, null, null, null, null);
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity create(Issue issue, Attribute attribute,
ActivitySet activitySet, ActivityType type,
String description, Attachment attachment,
Integer oldNumericValue, Integer newNumericValue,
Integer oldUserId, Integer newUserId,
Integer oldOptionId, Integer newOptionId,
String oldTextValue, String newTextValue)
throws TorqueException
{
return create(issue,attribute,activitySet,type,description,attachment,null,
oldNumericValue, newNumericValue,
oldUserId, newUserId,
oldOptionId, newOptionId,
oldTextValue, newTextValue, null);
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity create(Issue issue, Attribute attribute,
ActivitySet activitySet, ActivityType type,
String description, Attachment attachment,
Integer oldNumericValue, Integer newNumericValue,
Integer oldUserId, Integer newUserId,
Integer oldOptionId, Integer newOptionId,
String oldTextValue, String newTextValue,
Connection dbCon)
throws TorqueException
{
return create(issue,attribute,activitySet,type,description,attachment,null,
oldNumericValue, newNumericValue,
oldUserId, newUserId,
oldOptionId, newOptionId,
oldTextValue, newTextValue, dbCon);
}
// in java/org/tigris/scarab/om/ActivityManager.java
public static Activity create(Issue issue, Attribute attribute,
ActivitySet activitySet, ActivityType type,
String description, Attachment attachment, Depend depend,
Integer oldNumericValue, Integer newNumericValue,
Integer oldUserId, Integer newUserId,
Integer oldOptionId, Integer newOptionId,
String oldTextValue, String newTextValue,
Connection dbCon)
throws TorqueException
{
Activity activity = ActivityManager.getInstance();
activity.setIssue(issue);
if (attribute == null)
{
attribute = Attribute.getInstance(0);
}
activity.setAttribute(attribute);
activity.setActivitySet(activitySet);
activity.setOldNumericValue(oldNumericValue);
activity.setNewNumericValue(newNumericValue);
activity.setOldUserId(oldUserId);
activity.setNewUserId(newUserId);
activity.setOldOptionId(oldOptionId);
activity.setNewOptionId(newOptionId);
activity.setOldValue(oldTextValue);
activity.setNewValue(newTextValue);
activity.setDepend(depend);
activity.setDescription(description);
activity.setActivityType(type!=null?type.getCode():null);
if (attachment != null)
{
activity.setAttachment(attachment);
}
if (dbCon == null)
{
try
{
activity.save();
}
catch (Exception e)
{
if (e instanceof TorqueException)
{
throw (TorqueException)e; //EXCEPTION
}
else
{
throw new TorqueException(e); //EXCEPTION
}
}
}
else
{
activity.save(dbCon);
}
// Make sure new activity is added to activity cache
try
{
issue.addActivity(activity);
}
catch (Exception e)
{
throw new TorqueException(e); //EXCEPTION
}
return activity;
}
// in java/org/tigris/scarab/om/PendingGroupUserRole.java
public void delete()
throws TorqueException
{
Criteria crit = new Criteria();
crit.add(PendingGroupUserRolePeer.GROUP_ID, getGroupId());
crit.add(PendingGroupUserRolePeer.USER_ID, getUserId());
crit.add(PendingGroupUserRolePeer.ROLE_NAME, getRoleName());
PendingGroupUserRolePeer.doDelete(crit);
}
// in java/org/tigris/scarab/om/ActivitySetManager.java
public static ActivitySet getInstance(String key)
throws TorqueException
{
return getInstance(new NumberKey(key));
}
// in java/org/tigris/scarab/om/ActivitySetManager.java
public static ActivitySet getInstance(Integer key)
throws TorqueException
{
return getInstance(new NumberKey(key));
}
// in java/org/tigris/scarab/om/ActivitySetManager.java
public static ActivitySet getInstance(final ActivitySetType tt,
final ScarabUser user)
throws TorqueException, ScarabException
{
return getInstance(tt.getTypeId(), user, null);
}
// in java/org/tigris/scarab/om/ActivitySetManager.java
public static ActivitySet getInstance(final ActivitySetType tt,
final ScarabUser user,
final Attachment attachment)
throws TorqueException, ScarabException
{
return getInstance(tt.getTypeId(), user, attachment);
}
// in java/org/tigris/scarab/om/ActivitySetManager.java
public static ActivitySet getInstance(final Integer typeId,
final ScarabUser user)
throws TorqueException,ScarabException
{
return getInstance(typeId, user, null);
}
// in java/org/tigris/scarab/om/ActivitySetManager.java
public static ActivitySet getInstance(final Integer typeId,
final ScarabUser user,
final Attachment attachment)
throws TorqueException,ScarabException
{
if (attachment != null && attachment.getAttachmentId() == null)
{
throw new ScarabException(L10NKeySet.ExceptionNeedToSaveAttachement);
}
final ActivitySet activitySet = new ActivitySet();
activitySet.setTypeId(typeId);
activitySet.setCreatedBy(user.getUserId());
activitySet.setCreatedDate(new Date());
if (attachment != null &&
attachment.getData() != null &&
attachment.getData().length() > 0)
{
activitySet.setAttachment(attachment);
}
return activitySet;
}
// in java/org/tigris/scarab/om/Activity.java
public AttributeOption getOldAttributeOption() throws TorqueException
{
if (oldAttributeOption==null && (getOldValue() != null))
{
oldAttributeOption = AttributeOptionManager
.getInstance(new Integer(getOldValue()));
}
return oldAttributeOption;
}
// in java/org/tigris/scarab/om/Activity.java
public AttributeOption getNewAttributeOption() throws TorqueException
{
if (newAttributeOption==null && (getNewValue() != null))
{
newAttributeOption = AttributeOptionManager
.getInstance(new Integer(getNewValue()));
}
return newAttributeOption;
}
// in java/org/tigris/scarab/om/Activity.java
public void save(Connection dbCon)
throws TorqueException
{
if (isNew())
{
Criteria crit = new Criteria();
// If there are previous activities on this attribute and value
// Set End Date
if (this.getOldValue() != null)
{
crit.add(ActivityPeer.ISSUE_ID, getIssueId());
crit.add(ActivityPeer.ATTRIBUTE_ID, getAttributeId());
crit.add(ActivityPeer.END_DATE, null);
crit.add(ActivityPeer.NEW_VALUE, this.getOldValue());
List<Activity> result = ActivityPeer.doSelect(crit);
int resultSize = result.size();
if (resultSize > 0)
{
for (int i=0; i<resultSize;i++)
{
Activity a = (Activity)result.get(i);
a.setEndDate(getActivitySet().getCreatedDate());
a.save(dbCon);
}
}
}
}
// If they have just deleted a user assignment, set end date
if (getAttribute().isUserAttribute() && this.getNewUserId() == null && this.getOldUserId() != null)
{
this.setEndDate(getActivitySet().getCreatedDate());
}
super.save(dbCon);
}
// in java/org/tigris/scarab/om/Activity.java
public Activity copy(Issue issue, ActivitySet activitySet)
throws TorqueException
{
Activity newA = new Activity();
newA.setIssueId(issue.getIssueId());
newA.setDescription(getDescription());
newA.setAttributeId(getAttributeId());
newA.setTransactionId(activitySet.getActivitySetId());
newA.setOldNumericValue(getOldNumericValue());
newA.setNewNumericValue(getNewNumericValue());
newA.setOldUserId(getOldUserId());
newA.setNewUserId(getNewUserId());
newA.setOldValue(getOldValue());
newA.setNewValue(getNewValue());
newA.setDependId(getDependId());
newA.setEndDate(getEndDate());
newA.setAttachmentId(getAttachmentId());
newA.setActivityType(getActivityType());
newA.save();
return newA;
}
// in java/org/tigris/scarab/om/RModuleAttribute.java
public void save(Connection con) throws TorqueException
{
if (isModified())
{
if (isNew())
{
super.save(con);
}
else
{
RIssueTypeAttribute ria = null;
try
{
ria = getIssueType().getRIssueTypeAttribute(getAttribute());
if ((ria != null && ria.getLocked()))
{
throw new TorqueException(getAttribute().getName() + " is locked"); //EXCEPTION
}
else
{
super.save(con);
}
}
catch (Exception e)
{
throw new TorqueException("An error has occurred.", e); //EXCEPTION
}
}
}
}
// in java/org/tigris/scarab/om/RModuleAttribute.java
public void setModule(Module me)
throws TorqueException
{
Integer id = me.getModuleId();
if (id == null)
{
throw new TorqueException("Modules must be saved prior to " +
"being associated with other objects."); //EXCEPTION
}
setModuleId(id);
}
// in java/org/tigris/scarab/om/RModuleAttribute.java
public Module getModule()
throws TorqueException
{
Module module = null;
Integer id = getModuleId();
if ( id != null )
{
module = ModuleManager.getInstance(id);
}
return module;
}
// in java/org/tigris/scarab/om/RModuleAttribute.java
public void delete()
throws TorqueException, ScarabException
{
delete(false);
}
// in java/org/tigris/scarab/om/RModuleAttribute.java
protected void delete(final boolean overrideLock)
throws TorqueException, ScarabException
{
final Module module = getModule();
final IssueType issueType = IssueTypeManager
.getInstance(getIssueTypeId(), false);
if (issueType.getLocked() && !overrideLock)
{
throw new ScarabException(L10NKeySet.CannotDeleteAttributeFromLockedIssueType);
}
else
{
final Criteria c = new Criteria()
.add(RModuleAttributePeer.MODULE_ID, getModuleId())
.add(RModuleAttributePeer.ISSUE_TYPE_ID, getIssueTypeId())
.add(RModuleAttributePeer.ATTRIBUTE_ID, getAttributeId());
RModuleAttributePeer.doDelete(c);
final Attribute attr = getAttribute();
String attributeType = null;
attributeType = (attr.isUserAttribute() ? Module.USER : Module.NON_USER);
module.getRModuleAttributes(getIssueType(), false, attributeType)
.remove(this);
WorkflowFactory.getInstance().deleteWorkflowsForAttribute(
attr, module, getIssueType());
// delete module-user-attribute mappings
final Criteria crit = new Criteria()
.add(RModuleUserAttributePeer.ATTRIBUTE_ID,
attr.getAttributeId())
.add(RModuleUserAttributePeer.MODULE_ID,
getModuleId())
.add(RModuleUserAttributePeer.ISSUE_TYPE_ID,
getIssueTypeId());
RModuleUserAttributePeer.doDelete(crit);
// delete module-option mappings
if (attr.isOptionAttribute())
{
final List optionList = module.getRModuleOptions(attr,
IssueTypePeer.retrieveByPK(getIssueTypeId()),
false);
if (optionList != null && !optionList.isEmpty())
{
final List optionIdList =
new ArrayList(optionList.size());
for (int i = 0; i < optionList.size(); i++)
{
optionIdList.add(((RModuleOption)
optionList.get(i))
.getOptionId());
}
final Criteria c2 = new Criteria()
.add(RModuleOptionPeer.MODULE_ID, getModuleId())
.add(RModuleOptionPeer.ISSUE_TYPE_ID,
getIssueTypeId())
.addIn(RModuleOptionPeer.OPTION_ID, optionIdList);
RModuleOptionPeer.doDelete(c2);
}
}
}
RModuleAttributeManager.removeInstanceFromCache(this);
}
// in java/org/tigris/scarab/om/RModuleAttribute.java
private static List getRMAs(Integer moduleId, Integer issueTypeId)
throws TorqueException
{
List result = null;
Object obj = ScarabCache.get(R_MODULE_ATTTRIBUTE, GET_RMAS,
moduleId, issueTypeId);
if (obj == null)
{
Criteria crit = new Criteria()
.add(RModuleAttributePeer.MODULE_ID, moduleId)
.add(RModuleAttributePeer.ISSUE_TYPE_ID, issueTypeId);
crit.addAscendingOrderByColumn(
RModuleAttributePeer.PREFERRED_ORDER);
result = RModuleAttributePeer.doSelect(crit);
ScarabCache.put(result, R_MODULE_ATTTRIBUTE, GET_RMAS,
moduleId, issueTypeId);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/RModuleAttribute.java
private static List<RModuleAttribute> getRMAs(Integer moduleId)
throws TorqueException
{
List<RModuleAttribute> result = null;
Object obj = ScarabCache.get(R_MODULE_ATTTRIBUTE, GET_RMAS, moduleId);
if (obj == null)
{
Criteria crit = new Criteria()
.add(RModuleAttributePeer.MODULE_ID, moduleId);
crit.addAscendingOrderByColumn(
RModuleAttributePeer.PREFERRED_ORDER);
result = (List<RModuleAttribute>)RModuleAttributePeer.doSelect(crit);
ScarabCache.put(result, R_MODULE_ATTTRIBUTE, GET_RMAS,
moduleId);
}
else
{
result = (List<RModuleAttribute>)obj;
}
return result;
}
// in java/org/tigris/scarab/om/RModuleAttribute.java
public static List<Integer> getRMAIds(Integer moduleId)
throws TorqueException
{
List<RModuleAttribute> rmas = getRMAs(moduleId);
Iterator<RModuleAttribute> iter = rmas.iterator();
List<Integer> result = new ArrayList();
while(iter.hasNext())
{
RModuleAttribute rma = iter.next();
result.add(rma.getAttributeId());
}
return result;
}
// in java/org/tigris/scarab/om/RModuleAttribute.java
public boolean getIsDefaultText()
throws TorqueException
{
boolean isDefault = getDefaultTextFlag();
if (!isDefault && getAttribute().isTextAttribute())
{
// get related RMAs
List rmas = getRMAs(getModuleId(), getIssueTypeId());
// check if another is chosen
boolean anotherIsDefault = false;
for (int i=0; i<rmas.size(); i++)
{
RModuleAttribute rma = (RModuleAttribute)rmas.get(i);
if (rma.getDefaultTextFlag())
{
anotherIsDefault = true;
break;
}
}
if (!anotherIsDefault)
{
// locate the default text attribute
for (int i=0; i<rmas.size(); i++)
{
RModuleAttribute rma = (RModuleAttribute)rmas.get(i);
if (rma.getAttribute().isTextAttribute())
{
if (rma.getAttributeId().equals(getAttributeId()))
{
isDefault = true;
}
else
{
anotherIsDefault = true;
}
break;
}
}
}
}
return isDefault;
}
// in java/org/tigris/scarab/om/RModuleAttribute.java
public void setIsDefaultText(boolean b)
throws TorqueException
{
if (b && !getDefaultTextFlag())
{
// get related RMAs
List rmas = getRMAs(getModuleId(), getIssueTypeId());
// make sure no other rma is selected
for (int i=0; i<rmas.size(); i++)
{
RModuleAttribute rma = (RModuleAttribute)rmas.get(i);
if (rma.getDefaultTextFlag())
{
rma.setDefaultTextFlag(false);
rma.save();
break;
}
}
}
setDefaultTextFlag(b);
}
// in java/org/tigris/scarab/om/RModuleAttribute.java
public List<Condition> getConditions() throws TorqueException
{
if (collConditions == null)
{
Criteria crit = new Criteria();
crit.add(ConditionPeer.ATTRIBUTE_ID, this.getAttributeId());
crit.add(ConditionPeer.MODULE_ID, this.getModuleId());
crit.add(ConditionPeer.ISSUE_TYPE_ID, this.getIssueTypeId());
crit.add(ConditionPeer.TRANSITION_ID, null);
collConditions = getConditions(crit);
}
return collConditions;
}
// in java/org/tigris/scarab/om/RModuleAttribute.java
public void setConditionsArray(Integer aOptionId[], Integer operator) throws TorqueException
{
Criteria crit = new Criteria();
crit.add(ConditionPeer.ATTRIBUTE_ID, this.getAttributeId());
crit.add(ConditionPeer.MODULE_ID, this.getModuleId());
crit.add(ConditionPeer.ISSUE_TYPE_ID, this.getIssueTypeId());
crit.add(ConditionPeer.TRANSITION_ID, null);
ConditionPeer.doDelete(crit);
this.getConditions().clear();
ConditionManager.clear();
if (aOptionId != null)
{
for (int i=0; i<aOptionId.length; i++)
{
if (aOptionId[i].intValue() != 0)
{
Condition cond = new Condition();
cond.setAttribute(this.getAttribute());
cond.setOptionId(aOptionId[i]);
cond.setTransitionId(null);
cond.setIssueTypeId(this.getIssueTypeId());
cond.setModuleId(this.getModuleId());
cond.setOperator(operator);
this.addCondition(cond);
cond.save();
}
}
}
}
// in java/org/tigris/scarab/om/RModuleAttribute.java
public boolean isRequiredIf(Integer optionID) throws TorqueException
{
Condition condition = new Condition();
condition.setAttribute(this.getAttribute());
condition.setModuleId(this.getModuleId());
condition.setIssueTypeId(this.getIssueTypeId());
condition.setTransitionId(new Integer(0));
condition.setOptionId(optionID);
return this.getConditions().contains(condition);
}
// in java/org/tigris/scarab/om/RModuleOption.java
public void setModule(Module me)
throws TorqueException
{
Integer id = me.getModuleId();
if (id == null)
{
throw new TorqueException("Modules must be saved prior to " +
"being associated with other objects."); //EXCEPTION
}
setModuleId(id);
}
// in java/org/tigris/scarab/om/RModuleOption.java
public Module getModule()
throws TorqueException
{
Module module = null;
Integer id = getModuleId();
if ( id != null )
{
module = ModuleManager.getInstance(id);
}
return module;
}
// in java/org/tigris/scarab/om/RModuleOption.java
public RModuleAttribute getRModuleAttribute(IssueType issueType)
throws TorqueException
{
Module module = ModuleManager.getInstance(getModuleId());
Attribute attribute = getAttributeOption().getAttribute();
return module.getRModuleAttribute(attribute, issueType);
}
// in java/org/tigris/scarab/om/RModuleOption.java
public List getDescendants(IssueType issueType)
throws TorqueException
{
List descendants = new ArrayList();
List attrDescendants = getAttributeOption().getDescendants();
for (int i =0;i < attrDescendants.size(); i++)
{
RModuleOption rmo = null;
AttributeOption option = (AttributeOption)attrDescendants.get(i);
rmo = getModule().getRModuleOption(option, issueType);
if (rmo != null && rmo.getOptionId().equals(option.getOptionId()))
{
descendants.add(rmo);
}
}
return descendants;
}
// in java/org/tigris/scarab/om/RModuleOption.java
public List<RModuleOption> getChildren(IssueType issueType) throws TorqueException {
List<RModuleOption> children = new ArrayList<RModuleOption>();
@SuppressWarnings("unchecked")
List<AttributeOption> l = (List<AttributeOption>) this.getAttributeOption().getChildren();
for (AttributeOption attrOption : l) {
RModuleOption rmo = getModule().getRModuleOption(attrOption, issueType);
if (rmo != null && rmo.getOptionId().equals(attrOption.getOptionId())) {
children.add(rmo);
}
}
return children;
}
// in java/org/tigris/scarab/om/RModuleOption.java
public void delete()
throws TorqueException, ScarabException
{
final Module module = getModule();
final IssueType issueType = IssueTypeManager
.getInstance(getIssueTypeId(), false);
if (issueType.getLocked())
{
throw new ScarabException(L10NKeySet.ExceptionDeleteOptionFromLockedIssueType);
}
else
{
Integer moduleId = getModuleId();
Integer issueTypeId = getIssueTypeId();
Integer optionId = getOptionId();
int orderNumber = getOrder();
// delete the option
final Criteria c = new Criteria()
.add(RModuleOptionPeer.MODULE_ID, moduleId)
.add(RModuleOptionPeer.ISSUE_TYPE_ID, issueTypeId)
.add(RModuleOptionPeer.OPTION_ID, optionId);
RModuleOptionPeer.doDelete(c);
// delete associated workflow
WorkflowFactory.getInstance().deleteWorkflowsForOption(getAttributeOption(),
module, issueType);
// ======================================================
// Correct the ordering of the remaining options
// ======================================================
// first retrieve the list of still available option ids
final List optIds = new ArrayList();
final List rmos = module.getRModuleOptions(getAttributeOption().getAttribute(), issueType, false);
for (int i=0; i<rmos.size();i++)
{
final RModuleOption rmo = (RModuleOption)rmos.get(i);
optIds.add(rmo.getOptionId());
}
// Need to perform the correction only if the deleted option had follow up options
if(optIds.size() > 0)
{
// update the list
final Criteria c2 = new Criteria()
.add(RModuleOptionPeer.MODULE_ID, moduleId)
.add(RModuleOptionPeer.ISSUE_TYPE_ID, issueTypeId)
.addIn(RModuleOptionPeer.OPTION_ID, optIds)
.add(RModuleOptionPeer.PREFERRED_ORDER, orderNumber, Criteria.GREATER_THAN);
final List adjustRmos = RModuleOptionPeer.doSelect(c2);
for (int j=0; j<adjustRmos.size();j++)
{
final RModuleOption rmo = (RModuleOption)adjustRmos.get(j);
//rmos.remove(rmo);
rmo.setOrder(rmo.getOrder() -1);
rmo.save();
//rmos.add(rmo);
}
}
}
// notify module cache of this change
((ModuleManager)Torque.getManager(ModuleManager.MANAGED_CLASS))
.refreshedObject(this);
}
// in java/org/tigris/scarab/om/RModuleOption.java
public void save(Connection con) throws TorqueException
{
if (isModified())
{
if (isNew())
{
super.save(con);
}
else
{
Attribute attr = getAttributeOption().getAttribute();
RIssueTypeAttribute ria = null;
try
{
ria = getIssueType().getRIssueTypeAttribute(attr);
if (ria != null && ria.getLocked())
{
throw new TorqueException(attr.getName() + "is locked"); //EXCEPTION
}
else
{
super.save(con);
}
}
catch (Exception e)
{
throw new TorqueException("An error has occurred."); //EXCEPTION
}
}
}
}
// in java/org/tigris/scarab/om/RModuleOption.java
public static List<Integer> getRMOIds(Integer moduleId) throws TorqueException
{
List<RModuleOption> rmos = getRMOs(moduleId);
Iterator<RModuleOption> iter = rmos.iterator();
List<Integer> result = new ArrayList();
while(iter.hasNext())
{
RModuleOption rmo = iter.next();
result.add(rmo.getOptionId());
}
return result;
}
// in java/org/tigris/scarab/om/RModuleOption.java
public static List<RModuleOption> getRMOs(Integer moduleId)
throws TorqueException
{
List<RModuleOption> result = null;
Object obj = ScarabCache.get(R_MODULE_OPTION, GET_RMOS, moduleId);
if (obj == null)
{
Criteria crit = new Criteria()
.add(RModuleOptionPeer.MODULE_ID, moduleId);
crit.addAscendingOrderByColumn(
RModuleOptionPeer.PREFERRED_ORDER);
result = (List<RModuleOption>)RModuleOptionPeer.doSelect(crit);
ScarabCache.put(result, R_MODULE_OPTION, GET_RMOS,
moduleId);
}
else
{
result = (List<RModuleOption>)obj;
}
return result;
}
// in java/org/tigris/scarab/om/RModuleOption.java
public static List<RModuleOption> getRMOs(Integer moduleId, Integer issueTypeId) throws TorqueException
{
List<RModuleOption> result = null;
Object obj = ScarabCache.get(R_MODULE_OPTION, GET_RMOS_FOR_ISSUETYPE , moduleId, issueTypeId);
if (obj == null)
{
Criteria crit = new Criteria()
.add(RModuleOptionPeer.MODULE_ID, moduleId)
.and(RModuleOptionPeer.ISSUE_TYPE_ID, issueTypeId);
crit.addAscendingOrderByColumn(
RModuleOptionPeer.PREFERRED_ORDER);
result = (List<RModuleOption>)RModuleOptionPeer.doSelect(crit);
ScarabCache.put(result, R_MODULE_OPTION, GET_RMOS_FOR_ISSUETYPE , moduleId, issueTypeId);
}
else
{
result = (List<RModuleOption>)obj;
}
return result;
}
// in java/org/tigris/scarab/om/RModuleOption.java
public static List<RModuleOption> getRMOs(Integer moduleId, Integer issueTypeId, String displayValue) throws TorqueException
{
List<RModuleOption> result = null;
Object obj = ScarabCache.get(R_MODULE_OPTION, GET_RMOS_FOR_ISSUETYPE_AND_VALUE , moduleId, issueTypeId, displayValue);
if (obj == null)
{
Criteria crit = new Criteria()
.add(RModuleOptionPeer.MODULE_ID, moduleId)
.and(RModuleOptionPeer.ISSUE_TYPE_ID, issueTypeId)
.and(RModuleOptionPeer.DISPLAY_VALUE, displayValue);
crit.addAscendingOrderByColumn(
RModuleOptionPeer.PREFERRED_ORDER);
result = (List<RModuleOption>)RModuleOptionPeer.doSelect(crit);
ScarabCache.put(result, R_MODULE_OPTION, GET_RMOS_FOR_ISSUETYPE_AND_VALUE , moduleId, issueTypeId, displayValue);
}
else
{
result = (List<RModuleOption>)obj;
}
return result;
}
// in java/org/tigris/scarab/om/RModuleOption.java
public static RModuleOption getFirstRMO(Integer moduleId, Integer issueTypeId, String displayValue) throws TorqueException
{
RModuleOption result = null;
List<RModuleOption> rmos = getRMOs(moduleId, issueTypeId, displayValue);
if (rmos != null && rmos.size() > 0)
{
result = rmos.get(0);
}
return result;
}
// in java/org/tigris/scarab/om/AttributeClassManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap
.get(AttributeClassPeer.ATTRIBUTE_CLASS_ID);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/AttachmentPeer.java
public static Attachment retrieveByPK(ObjectKey pk)
throws TorqueException
{
Attachment result = null;
Object obj = ScarabCache.get(ATTACHMENT_PEER, RETRIEVE_BY_PK, pk);
if (obj == null)
{
result = BaseAttachmentPeer.retrieveByPK(pk);
ScarabCache.put(result, ATTACHMENT_PEER, RETRIEVE_BY_PK, pk);
}
else
{
result = (Attachment)obj;
}
return result;
}
// in java/org/tigris/scarab/om/ActivityPeer.java
public static String getNewIssueUniqueId(Issue issue)
throws TorqueException
{
String id = issue.getUniqueId();
Criteria crit = new Criteria();
crit.add(ActivityPeer.OLD_VALUE, id);
crit.add(ActivityPeer.ACTIVITY_TYPE, ActivityType.ISSUE_MOVED.getCode());
crit.addDescendingOrderByColumn(ActivityPeer.ACTIVITY_ID);
List list = doSelect(crit);
if (list != null && list.size() > 0)
id = ((Activity)list.get(0)).getNewValue();
return id;
}
// in java/org/tigris/scarab/om/QueryManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
//List listeners = (List)listenersMap
// .get(AttributeTypePeer.ATTRIBUTE_TYPE_ID);
//notifyListeners(listeners, oldOm, om);
getMethodResult().removeAll(QueryPeer.QUERY_PEER,
QueryPeer.GET_QUERIES);
getMethodResult().removeAll(QueryPeer.QUERY_PEER,
QueryPeer.GET_USER_QUERIES);
getMethodResult().removeAll(QueryPeer.QUERY_PEER,
QueryPeer.GET_MODULE_QUERIES);
return oldOm;
}
// in java/org/tigris/scarab/om/ScarabUserManager.java
public static ScarabUser getInstance()
throws TorqueException
{
return new ScarabUserImpl();
}
// in java/org/tigris/scarab/om/ScarabUserManager.java
public static ScarabUser getInstance(final String username)
throws TorqueException
{
ScarabUser user = (ScarabUser) getMethodResult().get(SCARAB_USER_MANAGER, GET_INSTANCE, username );
if (user == null)
{
user = getManager().getInstanceImpl(username);
if(user!=null)
getMethodResult().put(user, SCARAB_USER_MANAGER, GET_INSTANCE, username);
}
return user;
}
// in java/org/tigris/scarab/om/ScarabUserManager.java
public static ScarabUser getInstanceByEmail(final String email)
throws TorqueException,ScarabException
{
return getManager().getInstanceByEmailImpl(email);
}
// in java/org/tigris/scarab/om/ScarabUserManager.java
public static List getUsers(final String[] usernames)
throws TorqueException
{
return getManager().getUsersImpl(usernames);
}
// in java/org/tigris/scarab/om/ScarabUserManager.java
protected ScarabUser getInstanceImpl(final String username)
throws TorqueException
{
ScarabUser user = null;
if (username != null)
{
final Criteria crit = new Criteria();
crit.add(ScarabUserImplPeer.USERNAME, username);
crit.setSingleRecord(true);
final List users = ScarabUserImplPeer.doSelect(crit);
if (users.size() == 1)
{
user = (ScarabUser)users.get(0);
}
}
return user;
}
// in java/org/tigris/scarab/om/ScarabUserManager.java
protected ScarabUser getInstanceByEmailImpl(final String email)
throws TorqueException,ScarabException
{
ScarabUser user = null;
if (email != null)
{
final Criteria crit = new Criteria();
crit.add(ScarabUserImplPeer.EMAIL, email);
final List users = ScarabUserImplPeer.doSelect(crit);
if (users.size() == 1)
{
user = (ScarabUser)users.get(0);
}
else if (users.size() > 1)
{
throw new ScarabException(L10NKeySet.ExceptionDuplicateUsername);
}
}
return user;
}
// in java/org/tigris/scarab/om/ScarabUserManager.java
protected List getUsersImpl(final String[] usernames)
throws TorqueException
{
List users = null;
if (usernames != null && usernames.length > 0)
{
final Criteria crit = new Criteria();
crit.addIn(ScarabUserImplPeer.USERNAME, usernames);
users = ScarabUserImplPeer.doSelect(crit);
}
return users;
}
// in java/org/tigris/scarab/om/ScarabUserManager.java
public static ScarabUser getAnonymousUser()
throws TorqueException
{
ScarabUser user = null;
if(anonymousAccessAllowed())
{
String username = getAnonymousUserName();
user = getInstance(username);
}
if (user == null)
{
try
{
user = (ScarabUser) TurbineSecurity.getAnonymousUser();
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
return user;
}
// in java/org/tigris/scarab/om/ScarabUserManager.java
public static String getAnonymousUserName()
throws TorqueException
{
String username = GlobalParameterManager.getString("scarab.anonymous.username");
return username;
}
// in java/org/tigris/scarab/om/ScarabUserManager.java
public static boolean anonymousAccessAllowed()
throws TorqueException
{
boolean allowed = GlobalParameterManager.getBoolean("scarab.anonymous.enable");
return allowed;
}
// in java/org/tigris/scarab/om/RModuleAttributePeer.java
public static int count(Criteria crit)
throws TorqueException, DataSetException
{
crit.addSelectColumn(COUNT);
return ((Record)IssuePeer.doSelectVillageRecords(crit).get(0))
.getValue(1).asInt();
}
// in java/org/tigris/scarab/om/RModuleAttributePeer.java
public static RModuleAttribute retrieveByPK(ObjectKey pk)
throws TorqueException
{
RModuleAttribute result = null;
Object obj = ScarabCache.get(RMODULEATTRIBUTE_PEER, RETRIEVE_BY_PK, pk);
if (obj == null)
{
result = BaseRModuleAttributePeer.retrieveByPK(pk);
ScarabCache.put(result, RMODULEATTRIBUTE_PEER, RETRIEVE_BY_PK, pk);
}
else
{
result = (RModuleAttribute)obj;
}
return result;
}
// in java/org/tigris/scarab/om/RModuleAttributePeer.java
public static void doDelete(RModuleAttribute rma) throws TorqueException
{
Criteria crit = new Criteria();
crit.add(ConditionPeer.MODULE_ID, rma.getModuleId());
crit.add(ConditionPeer.ISSUE_TYPE_ID, rma.getIssueTypeId());
crit.add(ConditionPeer.ATTRIBUTE_ID, rma.getAttributeId());
ConditionPeer.doDelete(crit);
BaseTransitionPeer.doDelete(crit);
}
// in java/org/tigris/scarab/om/AttributeOptionPeer.java
public static List getSortedAttributeOptions() throws TorqueException
{
List attributeOptions = null;
final Criteria crit = new Criteria();
crit.addAscendingOrderByColumn(AttributeOptionPeer.ATTRIBUTE_ID);
crit.addAscendingOrderByColumn(AttributeOptionPeer.OPTION_ID);
attributeOptions = doSelect(crit);
attributeOptions.remove(0);
return attributeOptions;
}
// in java/org/tigris/scarab/om/AttributeOptionPeer.java
public static List<AttributeOption> getSortedAttributeOptions(Module module) throws TorqueException
{
List<Integer> rmaIds = RModuleAttribute.getRMAIds(module.getModuleId());
//List<Integer> rmoIds = RModuleOption.getRMOIds(module.getModuleId());
List<AttributeOption> attributeOptions = null;
final Criteria crit = new Criteria();
//SELECT * FROM scarab_attribute_option s where attribute_id in (select distinct attribute_id from scarab_r_module_attribute where module_id=10001);
crit.addIn(AttributeOptionPeer.ATTRIBUTE_ID,rmaIds);
crit.add(AttributeOptionPeer.DELETED,0);
crit.addAscendingOrderByColumn(AttributeOptionPeer.ATTRIBUTE_ID);
crit.addAscendingOrderByColumn(AttributeOptionPeer.OPTION_ID);
attributeOptions = (List<AttributeOption>)doSelect(crit);
//attributeOptions.remove(0);
return attributeOptions;
}
// in java/org/tigris/scarab/om/RQueryUser.java
public void delete(ScarabUser user) throws TorqueException
{
if (user.getUserId().equals(getUserId()))
{
Criteria c = new Criteria()
.add(RQueryUserPeer.USER_ID, getUserId())
.add(RQueryUserPeer.QUERY_ID, getQueryId());
RQueryUserPeer.doDelete(c);
}
}
// in java/org/tigris/scarab/om/ParentChildAttributeOption.java
public AttributeOption getChildOption()
throws TorqueException
{
return AttributeOptionManager.getInstance(getOptionId());
}
// in java/org/tigris/scarab/om/ParentChildAttributeOption.java
public AttributeOption getParentOption()
throws TorqueException
{
return AttributeOptionManager.getInstance(getParentId());
}
// in java/org/tigris/scarab/om/ParentChildAttributeOption.java
public List getAncestors()
throws TorqueException, Exception
{
ancestors = new ArrayList();
AttributeOption parent = getParentOption();
if (!ROOT_ID.equals(parent.getOptionId()))
{
addAncestors(parent);
}
return ancestors;
}
// in java/org/tigris/scarab/om/ParentChildAttributeOption.java
private void addAncestors(AttributeOption option)
throws TorqueException, Exception
{
if (!ROOT_ID.equals(option.getParent().getOptionId()))
{
if (ancestors.contains(option.getParent()))
{
throw new TorqueException("Tried to add a recursive parent-child " +
"attribute option relationship."); //EXCEPTION
}
else
{
addAncestors(option.getParent());
}
}
ancestors.add(option.getOptionId());
}
// in java/org/tigris/scarab/om/ParentChildAttributeOption.java
public void save()
throws TorqueException, ScarabException
{
AttributeOption ao = null;
ROptionOption roo = null;
final Attribute tmpAttr = AttributeManager.getInstance(getAttributeId());
// if it is new, it won't already have an optionId
if (getOptionId() == null)
{
// if it is new, check for duplicates.
final AttributeOption duplicate =
AttributeOptionManager.getInstance(tmpAttr, getName().trim());
final AttributeOption parent =
AttributeOptionManager.getInstance(getParentId());
if (duplicate != null)
{
throw new ScarabException (new L10NKey("CannotCreateDuplicateOption")); //EXCEPTION
}
else if (parent.getDeleted())
{
throw new ScarabException (new L10NKey("CannotCreateChild")); //EXCEPTION
}
}
// if getOptionId() is null, then it will just create a new instance
final Integer optionId = getOptionId();
if (optionId == null)
{
ao = AttributeOptionManager.getInstance();
}
else
{
ao = AttributeOptionManager.getInstance(getOptionId());
}
ao.setName(getName());
ao.setDeleted(getDeleted());
ao.setAttribute(tmpAttr);
ao.setStyle(getStyle());
ao.save();
// clean out the caches for the AO
tmpAttr.doRemoveCaches();
// now set our option id from the saved AO
this.setOptionId(ao.getOptionId());
// now create the ROO mapping
try
{
// look for a cached ROptionOption
roo = ROptionOption.getInstance(getParentId(), getOptionId());
}
catch (ScarabException se)
{
// could not find a cached instance create new one
roo = ROptionOption.getInstance();
roo.setOption1Id(getParentId());
roo.setOption2Id(getOptionId());
}
roo.setPreferredOrder(getPreferredOrder());
roo.setWeight(getWeight());
roo.setRelationshipId(OptionRelationship.PARENT_CHILD);
roo.save();
}
// in java/org/tigris/scarab/om/AttributeGroupPeer.java
public static AttributeGroup retrieveByPK(ObjectKey pk)
throws TorqueException
{
AttributeGroup result = null;
Object obj = ScarabCache.get(ATTRIBUTEGROUP_PEER, RETRIEVE_BY_PK, pk);
if (obj == null)
{
result = BaseAttributeGroupPeer.retrieveByPK(pk);
ScarabCache.put(result, ATTRIBUTEGROUP_PEER, RETRIEVE_BY_PK, pk);
}
else
{
result = (AttributeGroup)obj;
}
return result;
}
// in java/org/tigris/scarab/om/AttributeOptionManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap.get(AttributeOptionPeer.OPTION_ID);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/AttributeOptionManager.java
public static AttributeOption getInstance(final Attribute attribute,
final String name)
throws TorqueException
{
return getInstance(attribute, name, (Module) null, (IssueType) null);
}
// in java/org/tigris/scarab/om/AttributeOptionManager.java
public static AttributeOption getInstance(final Attribute attribute,
final String name,
final Module module,
final IssueType issueType)
throws TorqueException
{
AttributeOption ao = null;
Criteria crit;
// FIXME: Optimize this implementation! It is grossly
// inefficient, which is problematic given how often it may be
// used.
if (module != null && issueType != null)
{
// Look for a module-scoped alias.
crit = new Criteria(4);
crit.add(AttributeOptionPeer.ATTRIBUTE_ID,
attribute.getAttributeId());
crit.addJoin(AttributeOptionPeer.OPTION_ID,
RModuleOptionPeer.OPTION_ID);
crit.add(RModuleOptionPeer.MODULE_ID, module.getModuleId());
crit.add(RModuleOptionPeer.ISSUE_TYPE_ID,
issueType.getIssueTypeId());
crit.add(RModuleOptionPeer.DISPLAY_VALUE, name);
final List rmos = RModuleOptionPeer.doSelect(crit);
if (rmos.size() == 1)
{
final RModuleOption rmo = (RModuleOption) rmos.get(0);
ao = rmo.getAttributeOption();
}
}
if (ao == null)
{
// TODO It seems that we might not necessarily get the global option.
// Do we want to add a criteria to limit to getting the global option?
// This would be either "= 0" or "is null".
crit = new Criteria(2);
crit.add(AttributeOptionPeer.OPTION_NAME, name);
crit.add(AttributeOptionPeer.ATTRIBUTE_ID,
attribute.getAttributeId());
crit.setIgnoreCase(true);
final List options = AttributeOptionPeer.doSelect(crit);
if (options.size() == 1)
{
ao = (AttributeOption) options.get(0);
}
}
return ao;
}
// in java/org/tigris/scarab/om/IssueTypeManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap.get(IssueTypePeer.ISSUE_TYPE_ID);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/ROptionOption.java
public static void doRemove(ROptionOption roo)
throws TorqueException
{
// using Criteria because there is a bug in Torque
// where doDelete(roo) doesn't work because it has
// multple primary keys
Criteria crit = new Criteria();
crit.add (ROptionOptionPeer.OPTION1_ID, roo.getOption1Id());
crit.add (ROptionOptionPeer.OPTION2_ID, roo.getOption2Id());
ROptionOptionPeer.doDelete(crit);
}
// in java/org/tigris/scarab/om/ROptionOption.java
public static void doRemove(Integer parent, Integer child)
throws TorqueException
{
ROptionOption roo = getInstance();
roo.setOption1Id(parent);
roo.setOption2Id(child);
ROptionOption.doRemove(roo);
}
// in java/org/tigris/scarab/om/ROptionOption.java
public AttributeOption getOption1Option()
throws TorqueException
{
return AttributeOptionManager.getInstance(getOption1Id());
}
// in java/org/tigris/scarab/om/ROptionOption.java
public AttributeOption getOption2Option()
throws TorqueException
{
return AttributeOptionManager.getInstance(getOption2Id());
}
// in java/org/tigris/scarab/om/FrequencyPeer.java
public static List getFrequencies() throws TorqueException
{
return doSelect(new Criteria());
}
// in java/org/tigris/scarab/om/UserPreference.java
public void save() throws TorqueException
{
if (!this.getScarabUser().isUserAnonymous())
{
super.save();
}
}
// in java/org/tigris/scarab/om/RModuleUserAttribute.java
public void delete(final ScarabUser user) throws TorqueException, TurbineSecurityException
{
boolean hasPermission = true;
if (getModule() != null)
{
hasPermission = user.hasPermission(ScarabSecurity.USER__EDIT_PREFERENCES,getModule());
}
else //getModule() is null for X Project queries, so get the modules from the MIT List
{
final List moduleList = user.getCurrentMITList().getModules();
for (Iterator iter = moduleList.iterator(); iter.hasNext(); )
{
hasPermission = user.hasPermission(ScarabSecurity.USER__EDIT_PREFERENCES,(Module)iter.next());
if (!hasPermission)
{
break;
}
}
}
if (hasPermission)
{
final Criteria c = new Criteria()
.add(RModuleUserAttributePeer.MODULE_ID, getModuleId())
.add(RModuleUserAttributePeer.USER_ID, getUserId())
.add(RModuleUserAttributePeer.ISSUE_TYPE_ID, getIssueTypeId())
.add(RModuleUserAttributePeer.LIST_ID, getListId())
.add(RModuleUserAttributePeer.ATTRIBUTE_ID, getAttributeId());
RModuleUserAttributePeer.doDelete(c);
}
else
{
throw new TurbineSecurityException(ScarabConstants.NO_PERMISSION_MESSAGE); //EXCEPTION
}
}
// in java/org/tigris/scarab/om/AttributeValueManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap.get(AttributeValuePeer.ISSUE_ID);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/ActivitySetType.java
public static ActivitySetType getInstance(final String activitySetTypeName)
throws TorqueException, ScarabException
{
return ActivitySetTypeManager.getInstance(activitySetTypeName);
}
// in java/org/tigris/scarab/om/ScarabUserImplPeer.java
public static int getUsersCount(final Criteria critCount)
throws TorqueException, DataSetException
{
final List resultCount = ScarabUserImplPeer.doSelectVillageRecords(critCount);
final Record record = (Record) resultCount.get(0);
return record.getValue(1).asInt();
}
// in java/org/tigris/scarab/om/IssuePeer.java
public static int count(Criteria crit)
throws TorqueException, DataSetException
{
crit.addSelectColumn(COUNT);
return ((Record)IssuePeer.doSelectVillageRecords(crit).get(0))
.getValue(1).asInt();
}
// in java/org/tigris/scarab/om/IssuePeer.java
public static int countDistinct(Criteria crit)
throws TorqueException, DataSetException
{
crit.addSelectColumn(COUNT_DISTINCT);
return ((Record)IssuePeer.doSelectVillageRecords(crit).get(0))
.getValue(1).asInt();
}
// in java/org/tigris/scarab/om/IssuePeer.java
public static Issue retrieveByPK(ObjectKey pk)
throws TorqueException
{
Issue result = null;
Object obj = ScarabCache.get(ISSUE_PEER, RETRIEVE_BY_PK, pk);
if (obj == null)
{
result = BaseIssuePeer.retrieveByPK(pk);
ScarabCache.put(result, ISSUE_PEER, RETRIEVE_BY_PK, pk);
}
else
{
result = (Issue)obj;
}
result = BaseIssuePeer.retrieveByPK(pk);
return result;
}
// in java/org/tigris/scarab/om/ScarabModule.java
public String getPort()
throws TorqueException
{
if (port == null)
{
port = GlobalParameterManager
.getString(ScarabConstants.HTTP_PORT);
}
return port;
}
// in java/org/tigris/scarab/om/ScarabModule.java
public String getScheme()
throws TorqueException
{
if (scheme == null)
{
scheme = GlobalParameterManager
.getString(ScarabConstants.HTTP_SCHEME);
}
return scheme;
}
// in java/org/tigris/scarab/om/ScarabModule.java
public String getScriptName()
throws TorqueException
{
if (scriptName == null)
{
scriptName = GlobalParameterManager
.getString(ScarabConstants.HTTP_SCRIPT_NAME);
}
return scriptName;
}
// in java/org/tigris/scarab/om/ScarabModule.java
public ScarabPaginatedList getUsers(final String name,
final String username,
final MITList mitList,
final int pageNum,
final int resultsPerPage,
final String sortColumn,
final String sortPolarity,
final boolean includeCommitters)
throws TorqueException, DataSetException
{
return getUsers(name, username, mitList, pageNum, resultsPerPage, sortColumn, sortPolarity, includeCommitters, false);
}
// in java/org/tigris/scarab/om/ScarabModule.java
public ScarabPaginatedList getUsers(final String name,
final String username,
final MITList mitList,
final int pageNum,
final int resultsPerPage,
final String sortColumn,
final String sortPolarity,
final boolean includeCommitters,
final boolean confirmedOnly)
throws TorqueException, DataSetException
{
final int polarity = sortPolarity.equals("asc") ? 1 : -1;
List result = null;
ScarabPaginatedList paginated = null;
final Comparator c = new Comparator()
{
public int compare(Object o1, Object o2)
{
int i = 0;
if ("username".equals(sortColumn))
{
i = polarity * ((ScarabUser)o1).getUserName()
.compareTo(((ScarabUser)o2).getUserName());
}
else
{
i = polarity * ((ScarabUser)o1).getName()
.compareTo(((ScarabUser)o2).getName());
}
return i;
}
};
final Criteria crit = new Criteria();//
final Criteria critCount = new Criteria();
critCount.addSelectColumn("COUNT(DISTINCT " + TurbineUserPeer.USERNAME + ")");
if (mitList != null)
{
final List modules = mitList.getModules();
for (Iterator it = modules.iterator(); it.hasNext(); )
{
final Module mod = (Module)it.next();
final List perms = mitList.getUserAttributePermissions();
if (includeCommitters && !perms.contains(org.tigris.scarab.services.security.ScarabSecurity.ISSUE__ENTER))
{
perms.add(org.tigris.scarab.services.security.ScarabSecurity.ISSUE__ENTER);
}
crit.addIn(TurbinePermissionPeer.PERMISSION_NAME, perms);
crit.setDistinct();
critCount.addIn(TurbinePermissionPeer.PERMISSION_NAME, perms);
}
crit.addIn(TurbineUserGroupRolePeer.GROUP_ID, mitList.getModuleIds());
critCount.addIn(TurbineUserGroupRolePeer.GROUP_ID, mitList.getModuleIds());
}
crit.addJoin(TurbineUserPeer.USER_ID, TurbineUserGroupRolePeer.USER_ID);
crit.addJoin(TurbineUserGroupRolePeer.ROLE_ID, TurbineRolePermissionPeer.ROLE_ID);
crit.addJoin(TurbineRolePermissionPeer.PERMISSION_ID, TurbinePermissionPeer.PERMISSION_ID);
critCount.addJoin(TurbineUserPeer.USER_ID, TurbineUserGroupRolePeer.USER_ID);
critCount.addJoin(TurbineUserGroupRolePeer.ROLE_ID, TurbineRolePermissionPeer.ROLE_ID);
critCount.addJoin(TurbineRolePermissionPeer.PERMISSION_ID, TurbinePermissionPeer.PERMISSION_ID);
//user by name
if (name != null)
{
int nameSeparator = name.indexOf(" ");
if (nameSeparator != -1)
{
final String firstName = name.substring(0, nameSeparator);
final String lastName = name.substring(nameSeparator+1, name.length());
crit.add(ScarabUserImplPeer.FIRST_NAME,
addWildcards(firstName), Criteria.LIKE);
crit.add(ScarabUserImplPeer.LAST_NAME,
addWildcards(lastName), Criteria.LIKE);
critCount.add(ScarabUserImplPeer.FIRST_NAME,
addWildcards(firstName), Criteria.LIKE);
critCount.add(ScarabUserImplPeer.LAST_NAME,
addWildcards(lastName), Criteria.LIKE);
}
else
{
String[] tableAndColumn = StringUtils.split(ScarabUserImplPeer.FIRST_NAME, ".");
final Criteria.Criterion fn = crit.getNewCriterion(tableAndColumn[0],
tableAndColumn[1],
addWildcards(name),
Criteria.LIKE);
tableAndColumn = StringUtils.split(ScarabUserImplPeer.LAST_NAME, ".");
final Criteria.Criterion ln = crit.getNewCriterion(tableAndColumn[0],
tableAndColumn[1],
addWildcards(name),
Criteria.LIKE);
fn.or(ln);
crit.add(fn);
critCount.add(fn);
}
}
if (username != null)
{
crit.add(ScarabUserImplPeer.LOGIN_NAME,
addWildcards(username), Criteria.LIKE);
critCount.add(ScarabUserImplPeer.LOGIN_NAME,
addWildcards(username), Criteria.LIKE);
}
String col = ScarabUserImplPeer.FIRST_NAME;
if (sortColumn.equals("username"))
col = ScarabUserImplPeer.USERNAME;
if (sortPolarity.equals("asc"))
{
crit.addAscendingOrderByColumn(col);
}
else
{
crit.addDescendingOrderByColumn(col);
}
//confirmed users only
if(confirmedOnly){
crit.add(ScarabUserImplPeer.CONFIRM_VALUE, (Object)"CONFIRMED", Criteria.EQUAL);
}
//finish query
final int totalResultSize = ScarabUserImplPeer.getUsersCount(critCount);
crit.setOffset((pageNum - 1)* resultsPerPage);
crit.setLimit(resultsPerPage);
result = ScarabUserImplPeer.doSelect(crit);
// if there are results, sort the result set
if (totalResultSize > 0 && resultsPerPage > 0)
{
paginated = new ScarabPaginatedList(result, totalResultSize,
pageNum,
resultsPerPage);
}
else
{
paginated = new ScarabPaginatedList();
}
return paginated;
}
// in java/org/tigris/scarab/om/ScarabModule.java
public List getUsers(String firstName, String lastName,
String username, String email, IssueType issueType)
throws TorqueException
{
List result = null;
Serializable[] keys = {this, GET_USERS, firstName, lastName,
username, email, issueType};
Object obj = ScarabCache.get(keys);
if (obj == null)
{
ScarabUser[] eligibleUsers = getUsers(getUserPermissions(issueType));
if (eligibleUsers == null || eligibleUsers.length == 0)
{
result = Collections.EMPTY_LIST;
}
else
{
List userIds = new ArrayList();
for (int i = 0; i < eligibleUsers.length; i++)
{
userIds.add(eligibleUsers[i].getUserId());
}
Criteria crit = new Criteria();
crit.addIn(ScarabUserImplPeer.USER_ID, userIds);
if (firstName != null)
{
crit.add(ScarabUserImplPeer.FIRST_NAME,
addWildcards(firstName), Criteria.LIKE);
}
if (lastName != null)
{
crit.add(ScarabUserImplPeer.LAST_NAME,
addWildcards(lastName), Criteria.LIKE);
}
if (username != null)
{
crit.add(ScarabUserImplPeer.LOGIN_NAME,
addWildcards(username), Criteria.LIKE);
}
if (email != null)
{
crit.add(ScarabUserImplPeer.EMAIL, addWildcards(email),
Criteria.LIKE);
}
result = ScarabUserImplPeer.doSelect(crit);
}
ScarabCache.put(result, keys);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/ScarabModule.java
public void setParent(Module v)
throws TorqueException
{
super.setModuleRelatedByParentId(v);
// setting the name to be null so that
// it gets rebuilt with the new information
setName(null);
resetAncestors();
}
// in java/org/tigris/scarab/om/ScarabModule.java
public Module getParent()
throws TorqueException
{
Module parent = super.getModuleRelatedByParentId();
// The top level module has itself as parent.
// Return null in this case, to avoid endless loops.
if (this.getModuleId() == parent.getModuleId())
{
parent = null;
}
return parent;
}
// in java/org/tigris/scarab/om/ScarabModule.java
public void setParentId(Integer id)
throws TorqueException
{
super.setParentId(id);
// setting the name to be null so that
// it gets rebuilt with the new information
setName(null);
resetAncestors();
}
// in java/org/tigris/scarab/om/ScarabModule.java
public List getRModuleIssueTypes()
throws TorqueException
{
return super.getRModuleIssueTypes("preferredOrder","asc");
}
// in java/org/tigris/scarab/om/ScarabModule.java
public int getIssueCount(ScarabUser user, AttributeOption attributeOption)
throws TorqueException, DataSetException
{
Criteria crit = new Criteria();
Integer attributeId = attributeOption.getAttributeId();
Integer optionId = attributeOption.getOptionId();
crit.add(AttributeValuePeer.ATTRIBUTE_ID, attributeId);
crit.add(AttributeValuePeer.OPTION_ID,optionId);
crit.add(IssuePeer.MODULE_ID,getModuleId());
crit.add(IssuePeer.MOVED, 0);
crit.add(IssuePeer.DELETED, 0);
crit.add(IssuePeer.ID_COUNT, 0, SqlEnum.GREATER_THAN);
crit.addJoin(AttributeValuePeer.ISSUE_ID, IssuePeer.ISSUE_ID);
crit.add(AttributeValuePeer.DELETED,0);
int count = AttributeValuePeer.count(crit);
return count;
}
// in java/org/tigris/scarab/om/ScarabModule.java
public int getIssueCount(ScarabUser user)
throws TorqueException, DataSetException
{
Criteria crit = new Criteria();
crit.add(IssuePeer.MODULE_ID,getModuleId());
crit.add(IssuePeer.DELETED,0);
crit.add(IssuePeer.MOVED,0);
crit.add(IssuePeer.ID_COUNT, 0, SqlEnum.GREATER_THAN);
int count = IssuePeer.count(crit);
return count;
}
// in java/org/tigris/scarab/om/ScarabModule.java
public List getRModuleAttributes(Criteria crit)
throws TorqueException
{
return super.getRModuleAttributes(crit);
}
// in java/org/tigris/scarab/om/ScarabModule.java
public List getRModuleOptions(Criteria crit)
throws TorqueException
{
crit.addJoin(RModuleOptionPeer.OPTION_ID,
AttributeOptionPeer.OPTION_ID)
.add(AttributeOptionPeer.DELETED, false);
return super.getRModuleOptions(crit);
}
// in java/org/tigris/scarab/om/ScarabModule.java
public List getDuplicatesByNameAndParent(String realName, Integer parentId) throws TorqueException{
final Criteria crit = new Criteria();
crit.add(ScarabModulePeer.MODULE_NAME, realName);
crit.add(ScarabModulePeer.PARENT_ID, parentId);
return ScarabModulePeer.doSelect(crit);
}
// in java/org/tigris/scarab/om/ScarabModule.java
public void save(final Connection dbCon)
throws TorqueException
{
// if new, make sure the code has a value.
if (isNew())
{
List result;
try {
result = getDuplicatesByNameAndParent(getRealName(), getParentId());
}
catch (TorqueException te)
{
throw new ScarabLocalizedTorqueException(
new ScarabException(
L10NKeySet.ExceptionTorqueGeneric, te));
}
if (result.size() > 0)
{
throw new ScarabLocalizedTorqueException(
new ScarabException(
L10NKeySet.ExceptionModuleAllreadyExists,
getRealName(),
getParent().getName()));
}
final String code = getCode();
if (code == null || code.length() == 0)
{
if (getParentId().equals(ROOT_ID))
{
throw new ScarabLocalizedTorqueException(new ScarabException(L10NKeySet.ExceptionTopLevelModuleWithoutCode));
}
try
{
setCode(getParent().getCode());
}
catch (Exception e)
{
throw new ScarabLocalizedTorqueException(new ScarabException(L10NKeySet.ExceptionCantPropagateModuleCode, e));
}
}
// need to do this before the relationship save below
// in order to set the moduleid for the new module.
super.save(dbCon);
try
{
dbCon.commit();
}
catch (Exception e)
{
throw new ScarabLocalizedTorqueException(new ScarabException(L10NKeySet.ExceptionGeneric, e));
}
if (getOwnerId() == null)
{
throw new ScarabLocalizedTorqueException(new ScarabException(L10NKeySet.ExceptionSaveNeedsOwner));
}
// grant the ower of the module the Project Owner role
try
{
final User user = ScarabUserManager.getInstance(getOwnerId());
final Role role = TurbineSecurity.getRole(PROJECT_OWNER_ROLE);
grant (user, role);
setInitialAttributesAndIssueTypes();
}
catch (Exception e)
{
throw new ScarabLocalizedTorqueException(new ScarabException(L10NKeySet.ExceptionGeneric, e));
}
}
else
{
super.save(dbCon);
}
// clear out the cache beause we want to make sure that
// things get updated properly.
ScarabCache.clear();
}
// in java/org/tigris/scarab/om/ScarabModule.java
public List getNotDeletedModuleReports()
throws TorqueException
{
return ReportManager.getManager().getNotDeletedModuleReports(this);
}
// in java/org/tigris/scarab/om/NotificationStatus.java
public ScarabUser getCreator() throws TorqueException
{
Integer id = this.getCreatorId();
ScarabUser user = ScarabUserManager.getInstance(id);
return user;
}
// in java/org/tigris/scarab/om/NotificationStatus.java
public ScarabUser getReceiver() throws TorqueException
{
Integer id = this.getReceiverId();
ScarabUser user = ScarabUserManager.getInstance(id);
return user;
}
// in java/org/tigris/scarab/om/NotificationStatus.java
public void delete() throws TorqueException
{
Criteria crit = new Criteria();
crit
.add(NotificationStatusPeer.ACTIVITY_ID, this
.getActivityId());
crit.add(NotificationStatusPeer.CREATOR_ID, this.getCreatorId());
crit.add(NotificationStatusPeer.RECEIVER_ID, this.getReceiverId());
NotificationStatusPeer.doDelete(crit);
}
// in java/org/tigris/scarab/om/NotificationStatus.java
public void markDeleted() throws TorqueException
{
this.setStatus(MARK_DELETED);
this.setChangeDate(new Date());
this.save();
}
// in java/org/tigris/scarab/om/Transition.java
public boolean isRequiredIf(Integer optionID) throws TorqueException
{
Condition cond = new Condition();
cond.setAttributeId(null);
cond.setOptionId(optionID);
cond.setModuleId(null);
cond.setIssueTypeId(null);
cond.setTransitionId(this.getTransitionId());
return this.getConditions().contains(cond);
}
// in java/org/tigris/scarab/om/Transition.java
public List<Condition> getConditions() throws TorqueException
{
List<Condition> conds = (List<Condition>)TransitionManager.getMethodResult().get(this, "getConditions");
if (conds == null)
{
conds = super.getConditions();
TransitionManager.getMethodResult().put(conds, this, "getConditions");
}
return conds;
}
// in java/org/tigris/scarab/om/Transition.java
public void setConditionsArray(Integer aOptionId[], Integer operator) throws TorqueException
{
Criteria crit = new Criteria();
crit.add(ConditionPeer.ATTRIBUTE_ID, null);
crit.add(ConditionPeer.MODULE_ID, null);
crit.add(ConditionPeer.ISSUE_TYPE_ID, null);
crit.add(ConditionPeer.TRANSITION_ID, this.getTransitionId());
ConditionPeer.doDelete(crit);
this.getConditions().clear();
ConditionManager.clear();
if (aOptionId != null)
{
for (int i=0; i<aOptionId.length; i++)
{
if (aOptionId[i].intValue() != 0)
{
Condition cond = new Condition();
cond.setTransitionId(this.getTransitionId());
cond.setOptionId(aOptionId[i]);
cond.setAttributeId(null);
cond.setModuleId(null);
cond.setIssueTypeId(null);
cond.setOperator(operator);
this.addCondition(cond);
cond.save();
}
}
}
}
// in java/org/tigris/scarab/om/IssueType.java
public IssueType getTemplateIssueType()
throws TorqueException, ScarabException
{
if (templateIssueType == null)
{
final Criteria crit = new Criteria();
crit.add(IssueTypePeer.PARENT_ID, getIssueTypeId());
final List results = IssueTypePeer.doSelect(crit);
if (results.isEmpty())
{
throw new ScarabException(L10NKeySet.ExceptionTemplateTypeForIssueType);
}
else
{
templateIssueType = (IssueType)results.get(0);
}
}
return templateIssueType;
}
// in java/org/tigris/scarab/om/IssueType.java
public IssueType getIssueTypeForTemplateType()
throws TorqueException
{
if (parentIssueType == null)
{
parentIssueType = getIssueTypeRelatedByParentId();
}
return parentIssueType;
}
// in java/org/tigris/scarab/om/IssueType.java
public Integer getTemplateId()
throws TorqueException, ScarabException
{
return getTemplateIssueType().getIssueTypeId();
}
// in java/org/tigris/scarab/om/IssueType.java
public boolean hasIssues()
throws TorqueException, DataSetException
{
return hasIssues((Module) null);
}
// in java/org/tigris/scarab/om/IssueType.java
public String getDisplayName(Module module)
throws TorqueException
{
String moduleName = module.getRModuleIssueType(this).getDisplayName();
String displayName = getName();
if (!moduleName.equals(displayName))
{
displayName = moduleName +" (" + displayName + ")";
}
return displayName;
}
// in java/org/tigris/scarab/om/IssueType.java
public boolean hasIssues(Module module)
throws TorqueException, DataSetException
{
Criteria crit = new Criteria();
crit.add(IssuePeer.TYPE_ID, getIssueTypeId());
if (module != null)
{
crit.add(IssuePeer.MODULE_ID, module.getModuleId());
}
return (IssuePeer.count(crit) > 0);
}
// in java/org/tigris/scarab/om/IssueType.java
public static IssueType getInstance(final String issueTypeName)
throws TorqueException,ScarabException
{
IssueType result = null;
Object obj = ScarabCache.get(ISSUE_TYPE, GET_INSTANCE, issueTypeName);
if (obj == null)
{
final Criteria crit = new Criteria();
crit.add(IssueTypePeer.NAME, issueTypeName);
final List issueTypes = IssueTypePeer.doSelect(crit);
if(issueTypes == null || issueTypes.size() == 0)
{
throw new ScarabException(L10NKeySet.ExceptionInvalidIssueType,
issueTypeName);
}
result = (IssueType)issueTypes.get(0);
ScarabCache.put(result, ISSUE_TYPE, GET_INSTANCE, issueTypeName);
}
else
{
result = (IssueType)obj;
}
return result;
}
// in java/org/tigris/scarab/om/IssueType.java
public IssueType copyIssueType()
throws TorqueException, ScarabException
{
final IssueType newIssueType = new IssueType();
newIssueType.setName(getName() + " (copy)");
newIssueType.setDescription(getDescription());
newIssueType.setParentId(ScarabConstants.INTEGER_0);
newIssueType.save();
final Integer newId = newIssueType.getIssueTypeId();
// Copy template type
final IssueType template = IssueTypePeer
.retrieveByPK(getTemplateId());
final IssueType newTemplate = new IssueType();
newTemplate.setName(template.getName());
newTemplate.setParentId(newId);
newTemplate.save();
// Copy user attributes
final List userRIAs = getRIssueTypeAttributes(false, USER);
for (int m=0; m<userRIAs.size(); m++)
{
final RIssueTypeAttribute userRia = (RIssueTypeAttribute)userRIAs.get(m);
final RIssueTypeAttribute newUserRia = userRia.copyRia();
newUserRia.setIssueTypeId(newId);
newUserRia.save();
}
// Copy attribute groups
final List attrGroups = getAttributeGroups(false);
for (int i = 0; i<attrGroups.size(); i++)
{
final AttributeGroup group = (AttributeGroup)attrGroups.get(i);
final AttributeGroup newGroup = group.copyGroup();
newGroup.setIssueTypeId(newId);
newGroup.save();
// add attributes
final List attrs = group.getAttributes();
if (attrs != null)
{
for (int j=0; j<attrs.size(); j++)
{
// save attribute-attribute group maps
final Attribute attr = (Attribute)attrs.get(j);
final RAttributeAttributeGroup raag = group.getRAttributeAttributeGroup(attr);
final RAttributeAttributeGroup newRaag = new RAttributeAttributeGroup();
newRaag.setAttributeId(raag.getAttributeId());
newRaag.setOrder(raag.getOrder());
newRaag.setGroupId(newGroup.getAttributeGroupId());
newRaag.save();
// save attribute-issueType maps
final RIssueTypeAttribute ria = getRIssueTypeAttribute(attr);
final RIssueTypeAttribute newRia = ria.copyRia();
newRia.setIssueTypeId(newId);
newRia.save();
// save options
final List rios = getRIssueTypeOptions(attr, false);
if (rios != null)
{
for (int k=0; k<rios.size(); k++)
{
final RIssueTypeOption rio = (RIssueTypeOption)rios.get(k);
final RIssueTypeOption newRio = rio.copyRio();
newRio.setIssueTypeId(newId);
newRio.save();
}
}
}
}
}
// add workflow
WorkflowFactory.getInstance().copyIssueTypeWorkflows(this, newIssueType);
return newIssueType;
}
// in java/org/tigris/scarab/om/IssueType.java
public void deleteModuleMappings(final ScarabUser user)
throws TorqueException, ScarabException
{
final Criteria crit = new Criteria();
crit.add(RModuleIssueTypePeer.ISSUE_TYPE_ID,
getIssueTypeId());
final List rmits = RModuleIssueTypePeer.doSelect(crit);
for (int i=0; i<rmits.size(); i++)
{
final RModuleIssueType rmit = (RModuleIssueType)rmits.get(i);
rmit.delete(user);
}
ScarabCache.clear();
}
// in java/org/tigris/scarab/om/IssueType.java
public void createDefaultGroups()
throws TorqueException
{
AttributeGroup ag = createNewGroup();
ag.setOrder(1);
ag.setDedupe(true);
ag.setDescription(null);
ag.save();
AttributeGroup ag2 = createNewGroup();
ag2.setOrder(3);
ag2.setDedupe(false);
ag2.setDescription(null);
ag2.save();
}
// in java/org/tigris/scarab/om/IssueType.java
public List getAttributeGroups(Module module)
throws TorqueException
{
return getAttributeGroups(module, false);
}
// in java/org/tigris/scarab/om/IssueType.java
public List getAttributeGroups(boolean activeOnly)
throws TorqueException
{
return getAttributeGroups(null, activeOnly);
}
// in java/org/tigris/scarab/om/IssueType.java
public List getAttributeGroups(Module module, boolean activeOnly)
throws TorqueException
{
List groups = null;
Boolean activeBool = activeOnly ? Boolean.TRUE : Boolean.FALSE;
Object obj = getMethodResult().get(this, GET_ATTRIBUTE_GROUPS,
module, activeBool);
if (obj == null)
{
Criteria crit = new Criteria()
.add(AttributeGroupPeer.ISSUE_TYPE_ID, getIssueTypeId())
.addAscendingOrderByColumn(AttributeGroupPeer.PREFERRED_ORDER);
if (activeOnly)
{
crit.add(AttributeGroupPeer.ACTIVE, true);
}
if (module != null)
{
crit.add(AttributeGroupPeer.MODULE_ID, module.getModuleId());
}
else
{
// TODO Change this to be crit.add(AttributeGroupPeer.MODULE_ID, Criteria.ISNULL) when torque is fixed
crit.add(AttributeGroupPeer.MODULE_ID,
(Object)(AttributeGroupPeer.MODULE_ID + " IS NULL"),
Criteria.CUSTOM);
}
groups = AttributeGroupPeer.doSelect(crit);
getMethodResult().put(groups, this, GET_ATTRIBUTE_GROUPS,
module, activeBool);
}
else
{
groups = (List)obj;
}
return groups;
}
// in java/org/tigris/scarab/om/IssueType.java
public AttributeGroup createNewGroup()
throws TorqueException
{
return createNewGroup(null);
}
// in java/org/tigris/scarab/om/IssueType.java
public AttributeGroup createNewGroup(Module module)
throws TorqueException
{
List groups = getAttributeGroups(module, false);
AttributeGroup ag = new AttributeGroup();
// Make default group name 'new attribute group'
ag.setName(Localization.getString("ScarabBundle",
ScarabConstants.DEFAULT_LOCALE, "NewAttributeGroup"));
ag.setActive(true);
ag.setIssueTypeId(getIssueTypeId());
if (module != null)
{
ag.setModuleId(module.getModuleId());
}
if (groups.size() == 0)
{
ag.setDedupe(true);
ag.setOrder(groups.size() +1);
}
else
{
ag.setDedupe(false);
ag.setOrder(groups.size() +2);
}
ag.save();
groups.add(ag);
return ag;
}
// in java/org/tigris/scarab/om/IssueType.java
public int getDedupeSequence()
throws TorqueException
{
return getDedupeSequence(null);
}
// in java/org/tigris/scarab/om/IssueType.java
int getDedupeSequence(Module module)
throws TorqueException
{
List groups = getAttributeGroups(module, false);
int sequence = groups.size() + 1;
for (int i = 1; i <= groups.size(); i++)
{
int order;
int previousOrder;
try
{
order = ((AttributeGroup) groups.get(i)).getOrder();
previousOrder = ((AttributeGroup) groups.get(i - 1)).getOrder();
}
catch (Exception e)
{
Log.get().warn("Error accessing dedupe sequence for issue "
+ "type '" + this + '\'', e);
return sequence;
}
if (order != previousOrder + 1)
{
sequence = order - 1;
break;
}
}
return sequence;
}
// in java/org/tigris/scarab/om/IssueType.java
public List getRIssueTypeAttributes(boolean activeOnly)
throws TorqueException
{
return getRIssueTypeAttributes(activeOnly, "all");
}
// in java/org/tigris/scarab/om/IssueType.java
public List getRIssueTypeAttributes(boolean activeOnly,
String attributeType)
throws TorqueException
{
List rias = null;
Boolean activeBool = (activeOnly ? Boolean.TRUE : Boolean.FALSE);
Object obj = getMethodResult().get(this, GET_R_ISSUETYPE_ATTRIBUTES,
activeBool, attributeType);
if (obj == null)
{
Criteria crit = new Criteria();
crit.add(RIssueTypeAttributePeer.ISSUE_TYPE_ID,
getIssueTypeId());
crit.addAscendingOrderByColumn(
RIssueTypeAttributePeer.PREFERRED_ORDER);
if (activeOnly)
{
crit.add(RIssueTypeAttributePeer.ACTIVE, true);
}
if (USER.equals(attributeType))
{
crit.add(AttributePeer.ATTRIBUTE_TYPE_ID,
AttributeTypePeer.USER_TYPE_KEY);
crit.addJoin(AttributePeer.ATTRIBUTE_ID,
RIssueTypeAttributePeer.ATTRIBUTE_ID);
}
else if (NON_USER.equals(attributeType))
{
crit.addJoin(AttributePeer.ATTRIBUTE_ID,
RIssueTypeAttributePeer.ATTRIBUTE_ID);
crit.add(AttributePeer.ATTRIBUTE_TYPE_ID,
AttributeTypePeer.USER_TYPE_KEY,
Criteria.NOT_EQUAL);
}
rias = RIssueTypeAttributePeer.doSelect(crit);
getMethodResult().put(rias, this, GET_R_ISSUETYPE_ATTRIBUTES,
activeBool, attributeType);
}
else
{
rias = (List)obj;
}
return rias;
}
// in java/org/tigris/scarab/om/IssueType.java
public List getAttributes(String attributeType)
throws TorqueException
{
ArrayList attrs = new ArrayList();
List rias = getRIssueTypeAttributes(true, attributeType);
for (int i=0; i<rias.size(); i++)
{
attrs.add(((RIssueTypeAttribute)rias.get(i)).getAttribute());
}
return attrs;
}
// in java/org/tigris/scarab/om/IssueType.java
public RIssueTypeAttribute addRIssueTypeAttribute(Attribute attribute)
throws TorqueException
{
String attributeType = null;
attributeType = (attribute.isUserAttribute() ? USER : NON_USER);
RIssueTypeAttribute ria = new RIssueTypeAttribute();
ria.setIssueTypeId(getIssueTypeId());
ria.setAttributeId(attribute.getAttributeId());
ria.setOrder(getLastAttribute(attributeType) + 1);
ria.save();
getRIssueTypeAttributes(false, attributeType).add(ria);
return ria;
}
// in java/org/tigris/scarab/om/IssueType.java
public RIssueTypeAttribute getRIssueTypeAttribute(Attribute attribute)
throws TorqueException
{
RIssueTypeAttribute ria = null;
List rias = null;
if (attribute.isUserAttribute())
{
rias = getRIssueTypeAttributes(false, USER);
}
else
{
rias = getRIssueTypeAttributes(false, NON_USER);
}
Iterator i = rias.iterator();
while (i.hasNext())
{
RIssueTypeAttribute tempRia = (RIssueTypeAttribute)i.next();
if (tempRia.getAttribute().equals(attribute))
{
ria = tempRia;
break;
}
}
return ria;
}
// in java/org/tigris/scarab/om/IssueType.java
public List getUserAttributes()
throws TorqueException
{
return getUserAttributes(true);
}
// in java/org/tigris/scarab/om/IssueType.java
public List getUserAttributes(boolean activeOnly)
throws TorqueException
{
List rIssueTypeAttributes = getRIssueTypeAttributes(activeOnly, USER);
List userAttributes = new ArrayList();
for (int i=0; i<rIssueTypeAttributes.size(); i++)
{
Attribute att = ((RIssueTypeAttribute)rIssueTypeAttributes.get(i)).getAttribute();
userAttributes.add(att);
}
return userAttributes;
}
// in java/org/tigris/scarab/om/IssueType.java
public int getLastAttribute(String attributeType)
throws TorqueException
{
List itAttributes = getRIssueTypeAttributes(false, attributeType);
int last = 0;
for (int i=0; i<itAttributes.size(); i++)
{
int order = ((RIssueTypeAttribute) itAttributes.get(i))
.getOrder();
if (order > last)
{
last = order;
}
}
return last;
}
// in java/org/tigris/scarab/om/IssueType.java
public int getLastAttributeOption(Attribute attribute)
throws TorqueException
{
List issueTypeOptions = getRIssueTypeOptions(attribute);
int last = 0;
for (int i=0; i<issueTypeOptions.size(); i++)
{
int order = ((RIssueTypeOption) issueTypeOptions.get(i))
.getOrder();
if (order > last)
{
last = order;
}
}
return last;
}
// in java/org/tigris/scarab/om/IssueType.java
public RIssueTypeOption addRIssueTypeOption(AttributeOption option)
throws TorqueException
{
RIssueTypeOption rio = new RIssueTypeOption();
rio.setIssueTypeId(getIssueTypeId());
rio.setOptionId(option.getOptionId());
rio.setOrder(getLastAttributeOption(option.getAttribute()) + 1);
rio.save();
getRIssueTypeOptions(option.getAttribute(), false).add(rio);
return rio;
}
// in java/org/tigris/scarab/om/IssueType.java
public List getRIssueTypeOptions(Attribute attribute)
throws TorqueException
{
return getRIssueTypeOptions(attribute, true);
}
// in java/org/tigris/scarab/om/IssueType.java
public List getRIssueTypeOptions(Attribute attribute, boolean activeOnly)
throws TorqueException
{
List allRIssueTypeOptions = null;
allRIssueTypeOptions = getAllRIssueTypeOptions(attribute);
if (allRIssueTypeOptions != null)
{
if (activeOnly)
{
List activeRIssueTypeOptions =
new ArrayList(allRIssueTypeOptions.size());
for (int i=0; i<allRIssueTypeOptions.size(); i++)
{
RIssueTypeOption rio =
(RIssueTypeOption)allRIssueTypeOptions.get(i);
if (rio.getActive())
{
activeRIssueTypeOptions.add(rio);
}
}
allRIssueTypeOptions = activeRIssueTypeOptions;
}
}
return allRIssueTypeOptions;
}
// in java/org/tigris/scarab/om/IssueType.java
private List getAllRIssueTypeOptions(Attribute attribute)
throws TorqueException
{
List rIssueTypeOpts;
Object obj = ScarabCache.get(this, GET_ALL_R_ISSUETYPE_OPTIONS,
attribute);
if (obj == null)
{
List options = attribute.getAttributeOptions(false);
Integer[] optIds = null;
if (options == null)
{
optIds = new Integer[0];
}
else
{
optIds = new Integer[options.size()];
}
for (int i=optIds.length-1; i>=0; i--)
{
optIds[i] = ((AttributeOption)options.get(i)).getOptionId();
}
if (optIds.length > 0)
{
Criteria crit = new Criteria();
crit.add(RIssueTypeOptionPeer.ISSUE_TYPE_ID, getIssueTypeId());
crit.addIn(RIssueTypeOptionPeer.OPTION_ID, optIds);
crit.addJoin(RIssueTypeOptionPeer.OPTION_ID, AttributeOptionPeer.OPTION_ID);
crit.addAscendingOrderByColumn(RIssueTypeOptionPeer.PREFERRED_ORDER);
crit.addAscendingOrderByColumn(AttributeOptionPeer.OPTION_NAME);
rIssueTypeOpts = RIssueTypeOptionPeer.doSelect(crit);
}
else
{
rIssueTypeOpts = new ArrayList(0);
}
ScarabCache.put(rIssueTypeOpts, this, GET_ALL_R_ISSUETYPE_OPTIONS,
attribute);
}
else
{
rIssueTypeOpts = (List)obj;
}
return rIssueTypeOpts;
}
// in java/org/tigris/scarab/om/IssueType.java
public RIssueTypeOption getRIssueTypeOption(AttributeOption option)
throws TorqueException
{
RIssueTypeOption rio = null;
List rios = getRIssueTypeOptions(option.getAttribute(), false);
Iterator i = rios.iterator();
while (i.hasNext())
{
rio = (RIssueTypeOption)i.next();
if (rio.getAttributeOption().equals(option))
{
break;
}
}
return rio;
}
// in java/org/tigris/scarab/om/IssueType.java
public List getAvailableAttributes(String attributeType)
throws TorqueException
{
List allAttributes = AttributePeer.getAttributes(attributeType);
List availAttributes = new ArrayList();
List rIssueTypeAttributes = getRIssueTypeAttributes(false,
attributeType);
List attrs = new ArrayList();
for (int i=0; i<rIssueTypeAttributes.size(); i++)
{
attrs.add(
((RIssueTypeAttribute) rIssueTypeAttributes.get(i)).getAttribute());
}
for (int i=0; i<allAttributes.size(); i++)
{
Attribute att = (Attribute)allAttributes.get(i);
if (!attrs.contains(att))
{
availAttributes.add(att);
}
}
return availAttributes;
}
// in java/org/tigris/scarab/om/IssueType.java
public List getAvailableAttributeOptions(Attribute attribute)
throws TorqueException
{
List rIssueTypeOptions = getRIssueTypeOptions(attribute, false);
List issueTypeOptions = new ArrayList();
if (rIssueTypeOptions != null)
{
for (int i=0; i<rIssueTypeOptions.size(); i++)
{
issueTypeOptions.add(
((RIssueTypeOption) rIssueTypeOptions.get(i)).getAttributeOption());
}
}
List allOptions = attribute.getAttributeOptions(false);
List availOptions = new ArrayList();
for (int i=0; i<allOptions.size(); i++)
{
AttributeOption option = (AttributeOption)allOptions.get(i);
if (!issueTypeOptions.contains(option))
{
availOptions.add(option);
}
}
return availOptions;
}
// in java/org/tigris/scarab/om/IssueType.java
public List getMatchingAttributeValuesList(Module oldModule, Module newModule,
IssueType newIssueType)
throws TorqueException
{
List matchingAttributes = new ArrayList();
List srcActiveAttrs = getActiveAttributes(oldModule);
List destActiveAttrs = newIssueType.getActiveAttributes(newModule);
for (int i = 0; i<srcActiveAttrs.size(); i++)
{
Attribute attr = (Attribute)srcActiveAttrs.get(i);
if (destActiveAttrs.contains(attr))
{
matchingAttributes.add(attr);
}
}
return matchingAttributes;
}
// in java/org/tigris/scarab/om/IssueType.java
public List getOrphanAttributeValuesList(Module oldModule, Module newModule,
IssueType newIssueType)
throws TorqueException
{
List orphanAttributes = new ArrayList();
List srcActiveAttrs = getActiveAttributes(oldModule);
List destActiveAttrs = newIssueType.getActiveAttributes(newModule);
for (int i = 0; i<srcActiveAttrs.size(); i++)
{
Attribute attr = (Attribute)srcActiveAttrs.get(i);
if (!destActiveAttrs.contains(attr))
{
orphanAttributes.add(attr);
}
}
return orphanAttributes;
}
// in java/org/tigris/scarab/om/IssueType.java
public boolean isSystemDefined()
throws TorqueException
{
boolean systemDefined = false;
String name = getName();
if (name != null)
{
systemDefined = "system".equalsIgnoreCase(SYSTEM_CONFIG.getProperty(name));
}
return systemDefined;
}
// in java/org/tigris/scarab/om/IssueType.java
public Attribute getDefaultTextAttribute(Module module)
throws TorqueException
{
Attribute result = null;
Object obj = ScarabCache.get(this, GET_DEFAULT_TEXT_ATTRIBUTE);
if (obj == null)
{
// get related RMAs
Criteria crit = new Criteria()
.add(RModuleAttributePeer.MODULE_ID,
module.getModuleId());
crit.addAscendingOrderByColumn(
RModuleAttributePeer.PREFERRED_ORDER);
List rmas = getRModuleAttributes(crit);
// the code to find the correct attribute could be quite simple by
// looping and calling RMA.isDefaultText(). The code from
// that method can be restructured here to more efficiently
// answer this question.
Iterator i = rmas.iterator();
while (i.hasNext())
{
RModuleAttribute rma = (RModuleAttribute)i.next();
if (rma.getDefaultTextFlag())
{
result = rma.getAttribute();
break;
}
}
if (result == null)
{
// locate the highest ranked text attribute
i = rmas.iterator();
while (i.hasNext())
{
RModuleAttribute rma = (RModuleAttribute)i.next();
Attribute testAttr = rma.getAttribute();
if (testAttr.isTextAttribute() &&
getAttributeGroup(module, testAttr).getActive())
{
result = testAttr;
break;
}
}
}
ScarabCache.put(result, this, GET_DEFAULT_TEXT_ATTRIBUTE);
}
else
{
result = (Attribute)obj;
}
return result;
}
// in java/org/tigris/scarab/om/IssueType.java
public List getQuickSearchAttributes(Module module)
throws TorqueException
{
List attributes = null;
Object obj = ScarabCache.get(this, GET_QUICK_SEARCH_ATTRIBUTES,
module);
if (obj == null)
{
Criteria crit = new Criteria(3)
.add(RModuleAttributePeer.QUICK_SEARCH, true);
addOrderByClause(crit, module);
attributes = getAttributes(crit);
ScarabCache.put(attributes, this, GET_QUICK_SEARCH_ATTRIBUTES,
module);
}
else
{
attributes = (List)obj;
}
return attributes;
}
// in java/org/tigris/scarab/om/IssueType.java
private List getAttributes(final Criteria criteria)
throws TorqueException
{
final List moduleAttributes = getRModuleAttributes(criteria);
final List attributes = new ArrayList(moduleAttributes.size());
for (int i=0; i<moduleAttributes.size(); i++)
{
attributes.add(
((RModuleAttribute) moduleAttributes.get(i)).getAttribute());
}
return attributes;
}
// in java/org/tigris/scarab/om/IssueType.java
public boolean canCreateIssueInScope(ScarabUser user, Module module) throws TorqueException, ScarabException
{
//[HD first check, if user has IssueCreate permission in this module
boolean isPermissionGranted = user.hasPermission(ScarabSecurity.ISSUE__ENTER, module);
if(isPermissionGranted)
{
List requiredAttributes = getRequiredAttributes(module);
Iterator iter = requiredAttributes.iterator();
while(iter.hasNext())
{
Attribute attribute = (Attribute)iter.next();
Workflow workflow = WorkflowFactory.getInstance();
if(attribute.isOptionAttribute())
{
boolean canDoPartial = workflow.canMakeTransitionsFrom(user, this, attribute, null);
if(!canDoPartial)
{
isPermissionGranted = false;
break;
}
}
}
}
return isPermissionGranted;
}
// in java/org/tigris/scarab/om/IssueType.java
public boolean canCreateAttributeInScope(ScarabUser user, Module module, Attribute attribute) throws TorqueException, ScarabException
{
boolean result = true;
Workflow workflow = WorkflowFactory.getInstance();
if(attribute.isOptionAttribute())
{
result = workflow.canMakeTransitionsFrom(user, this, attribute, null);
}
return result;
}
// in java/org/tigris/scarab/om/IssueType.java
public List getRequiredAttributes(Module module)
throws TorqueException
{
List attributes = null;
Object obj = ScarabCache.get(this, GET_REQUIRED_ATTRIBUTES,
module);
if (obj == null)
{
Criteria crit = new Criteria(3)
.add(RModuleAttributePeer.REQUIRED, true);
crit.add(RModuleAttributePeer.ACTIVE, true);
addOrderByClause(crit, module);
List temp = getAttributes(crit);
List requiredAttributes = new ArrayList();
for (int i=0; i <temp.size(); i++)
{
Attribute att = (Attribute)temp.get(i);
AttributeGroup group = getAttributeGroup(module, att);
if (group != null && group.getActive())
{
requiredAttributes.add(att);
}
}
attributes = requiredAttributes;
ScarabCache.put(attributes, this, GET_REQUIRED_ATTRIBUTES,
module);
}
else
{
attributes = (List)obj;
}
return attributes;
}
// in java/org/tigris/scarab/om/IssueType.java
public List<Attribute> getActiveAttributes(final Module module)
throws TorqueException
{
List attributes = null;
Object obj = ScarabCache.get(this, GET_ACTIVE_ATTRIBUTES, module);
if (obj == null)
{
final Criteria crit = new Criteria(2);
crit.add(RModuleAttributePeer.ACTIVE, true);
addOrderByClause(crit, module);
attributes = getAttributes(crit);
ScarabCache.put(attributes, this, GET_ACTIVE_ATTRIBUTES,
module);
}
else
{
attributes = (List)obj;
}
return attributes;
}
// in java/org/tigris/scarab/om/IssueType.java
private AttributeGroup getAttributeGroup(Module module,
Attribute attribute)
throws TorqueException
{
AttributeGroup group = null;
Object obj = ScarabCache.get(this, GET_ATTRIBUTE_GROUP,
module, attribute);
if (obj == null)
{
Criteria crit = new Criteria()
.add(AttributeGroupPeer.ISSUE_TYPE_ID, getIssueTypeId())
.add(AttributeGroupPeer.MODULE_ID,
module.getModuleId())
.addJoin(RAttributeAttributeGroupPeer.GROUP_ID,
AttributeGroupPeer.ATTRIBUTE_GROUP_ID)
.add(RAttributeAttributeGroupPeer.ATTRIBUTE_ID,
attribute.getAttributeId());
List results = AttributeGroupPeer.doSelect(crit);
if (results.size() > 0)
{
group = (AttributeGroup)results.get(0);
ScarabCache.put(group, this, GET_ATTRIBUTE_GROUP,
module, attribute);
}
}
else
{
group = (AttributeGroup)obj;
}
return group;
}
// in java/org/tigris/scarab/om/RModuleAttributeManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap
.get(RModuleAttributePeer.MODULE_ID);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/RModuleAttributeManager.java
public static final RModuleAttribute getInstance(Module module,
Attribute attribute, IssueType issueType)
throws TorqueException
{
SimpleKey[] keys = {
SimpleKey.keyFor(module.getModuleId()),
SimpleKey.keyFor(attribute.getAttributeId()),
SimpleKey.keyFor(issueType.getIssueTypeId())
};
return getInstance(new ComboKey(keys));
}
// in java/org/tigris/scarab/om/RModuleAttributeManager.java
public static final RModuleAttribute getInstance(Integer moduleId,
Integer attributeId, Integer issueTypeId)
throws TorqueException
{
SimpleKey[] keys = {
SimpleKey.keyFor(moduleId),
SimpleKey.keyFor(attributeId),
SimpleKey.keyFor(issueTypeId)
};
return getInstance(new ComboKey(keys));
}
// in java/org/tigris/scarab/om/RModuleAttributeManager.java
static void removeInstanceFromCache(RModuleAttribute rma)
throws TorqueException
{
RModuleAttributeManager thisManager = getManager();
thisManager.removeInstanceImpl(rma.getPrimaryKey());
List listeners = (List)thisManager.listenersMap
.get(RModuleAttributePeer.MODULE_ID);
thisManager.notifyListeners(listeners, rma, rma);
}
// in java/org/tigris/scarab/om/MITListManager.java
public static MITList getSingleItemList(Module module, IssueType issueType,
ScarabUser user)
throws TorqueException
{
MITList list = getInstance();
if (user != null)
{
list.setScarabUser(user);
}
MITListItem item = MITListItemManager.getInstance();
item.setModule(module);
item.setIssueType(issueType);
list.addMITListItem(item);
return list;
}
// in java/org/tigris/scarab/om/MITListManager.java
public static MITList getSingleModuleAllIssueTypesList(Module module,
ScarabUser user)
throws TorqueException
{
MITList list = MITListManager.getInstance();
list.setModifiable(false);
list.setScarabUser(user);
list.setName(Localization.format(ScarabConstants.DEFAULT_BUNDLE_NAME,
user.getLocale(),
"AllIssueTypesCurrentModule",
module.getRealName()));
MITListItem item = MITListItemManager.getInstance();
item.setModule(module);
item.setIssueTypeId(MITListItem.MULTIPLE_KEY);
list.addMITListItem(item);
return list;
}
// in java/org/tigris/scarab/om/MITListManager.java
public static MITList getAllModulesAllIssueTypesList(ScarabUser user)
throws TorqueException
{
MITList list = MITListManager.getInstance();
list.setModifiable(false);
list.setScarabUser(user);
list.setName(Localization.getString(ScarabConstants.DEFAULT_BUNDLE_NAME,
user.getLocale(),
"AllModulesAndIssueTypes"));
MITListItem item = MITListItemManager.getInstance();
item.setModuleId(MITListItem.MULTIPLE_KEY);
list.addMITListItem(item);
item.setIssueTypeId(MITListItem.MULTIPLE_KEY);
return list;
}
// in java/org/tigris/scarab/om/MITListManager.java
public static MITList getAllModulesSingleIssueTypeList(IssueType issueType,
ScarabUser user)
throws TorqueException
{
MITList list = MITListManager.getInstance();
list.setModifiable(false);
list.setScarabUser(user);
list.setName(Localization.format(ScarabConstants.DEFAULT_BUNDLE_NAME,
user.getLocale(),
"CurrentIssueTypeAllModules",
issueType.getName()));
MITListItem item = MITListItemManager.getInstance();
item.setModuleId(MITListItem.MULTIPLE_KEY);
item.setIssueType(issueType);
list.addMITListItem(item);
return list;
}
// in java/org/tigris/scarab/om/MITListManager.java
public static MITList getInstanceFromIssueList(List issues,
ScarabUser user)
throws TorqueException
{
if (issues == null)
{
throw new IllegalArgumentException("Null issue list is not allowed."); //EXCEPTION
}
if (user == null)
{
throw new IllegalArgumentException("Null user is not allowed."); //EXCEPTION
}
MITList list = getInstance();
list.setScarabUser(user);
List dupeCheck = list.getMITListItems();
Iterator i = issues.iterator();
if (i.hasNext())
{
Issue issue = (Issue)i.next();
MITListItem item = MITListItemManager.getInstance();
item.setModule(issue.getModule());
item.setIssueType(issue.getIssueType());
if (!dupeCheck.contains(item))
{
list.addMITListItem(item);
}
}
return list;
}
// in java/org/tigris/scarab/om/MITListManager.java
public static MITList getInstanceByName(String name, ScarabUser user)
throws TorqueException
{
MITList result = null;
Criteria crit = new Criteria();
crit.add(MITListPeer.NAME, name);
crit.add(MITListPeer.ACTIVE, true);
crit.add(MITListPeer.USER_ID, user.getUserId());
List mitLists = MITListPeer.doSelect(crit);
if (mitLists != null && !mitLists.isEmpty())
{
result = (MITList)mitLists.get(0);
// it is not good if more than one active list has the
// same name (per user). We could throw an exception here
// but its possible the system can still function under
// this circumstance, so just log it for now.
Log.get().error("Multiple active lists exist with list name="
+ name + " for user=" + user.getUserName() +
"("+user.getUserId()+")");
}
return result;
}
// in java/org/tigris/scarab/om/IssueManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
// saving an issue object could affect some cached results, since it could be a move
Serializable obj = (Serializable)om;
getMethodResult().removeAll(obj, Issue.GET_MODULE_ATTRVALUES_MAP);
getMethodResult().remove(obj, Issue.GET_USER_ATTRIBUTEVALUES);
return oldOm;
}
// in java/org/tigris/scarab/om/AttributeGroupManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap.get(AttributeGroupPeer.MODULE_ID);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/ActivitySetPeer.java
public static ActivitySet retrieveByPK(ObjectKey pk)
throws TorqueException
{
ActivitySet result = null;
Object obj = ScarabCache.get(TRANSACTION_PEER, RETRIEVE_BY_PK, pk);
if (obj == null)
{
result = BaseActivitySetPeer.retrieveByPK(pk);
ScarabCache.put(result, TRANSACTION_PEER, RETRIEVE_BY_PK, pk);
}
else
{
result = (ActivitySet)obj;
}
return result;
}
// in java/org/tigris/scarab/om/MITListItem.java
public int getIssueCount(ScarabUser user, AttributeOption attributeOption)
throws TorqueException, ScarabException, DataSetException
{
Criteria crit = new Criteria();
Integer attributeId = attributeOption.getAttributeId();
Integer optionId = attributeOption.getOptionId();
crit.add(AttributeValuePeer.ATTRIBUTE_ID, attributeId);
crit.add(AttributeValuePeer.OPTION_ID,optionId);
crit.add(AttributeValuePeer.DELETED,0);
crit.add(IssuePeer.MODULE_ID,getModuleId());
crit.add(IssuePeer.TYPE_ID,this.getIssueTypeId());
crit.add(IssuePeer.MOVED, 0);
crit.add(IssuePeer.DELETED, 0);
crit.addJoin(AttributeValuePeer.ISSUE_ID, IssuePeer.ISSUE_ID);
int count = AttributeValuePeer.count(crit);
return count;
}
// in java/org/tigris/scarab/om/MITListItem.java
public String getAttributeDisplayName(final Attribute attribute) throws TorqueException
{
if (!isSingleIssueType())
{
// FIXME: we should in fact use isSingleModuleIssueType() here
// but the reference of multiple modules
// is represented by moduleId == MULTIPE_KEY,
// which has the value of 0
// which is also the id of the global module
// probably null is a better value for MULTIPE_KEY
throw new IllegalStateException(
"method should not be called on an item " +
"including issue types");
}
Module module = getModule();
IssueType issueType = getIssueType();
RModuleAttribute rma = module.getRModuleAttribute(attribute, issueType);
String displayValue;
// FIXME: When would the rma be null ? I got this error today, while performing a cross module
// query. But i couldn't find the cause.
// It may be related to an inconsistent submodule definition ...
// In order to debug this behaviour, i added a generic displayValue here. Now the NPE
// is away, but the generic displayValues don't appear either on the GUI. So whatever happens
// here, the associated items seem to be irrelevant on the GUI... To be further examined!
if(rma != null)
{
displayValue = rma.getDisplayValue();
}
else
{
displayValue = "" + attribute.getName() + ":" + issueType.getName();
}
return displayValue;
}
// in java/org/tigris/scarab/om/NotificationRule.java
public static NotificationRule createDefaultRule(Integer moduleId,
Integer userId,
Integer managerId,
String activityType) throws TorqueException
{
NotificationRule rule = new NotificationRule();
rule.setModuleId(moduleId);
rule.setUserId(userId);
rule.setActivityType(activityType);
rule.setManagerId(managerId);
// default settings.
// currently hard coded. will later be
// replaced by a default customization
rule.setFilterState(true); // enabled by default
rule.setSendSelf(false); // don't send to myself by default
rule.setSendFailures(false); // don't notify me about failures by default
rule.save();
return rule;
}
// in java/org/tigris/scarab/om/AttributeTypeManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap
.get(AttributeTypePeer.ATTRIBUTE_TYPE_ID);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/NotificationRuleManager.java
public static boolean isNotificationEnabledFor(ScarabUser user, Issue issue, boolean isSelf, String activityType, ActivitySet activitySet) throws ScarabException, TorqueException
{
Integer userId = user.getUserId();
Module module = issue.getModule();
Integer moduleId = module.getModuleId();
NotificationRule rule = getNotificationRule(moduleId, userId, activityType);
boolean isEnabled;
if(isSelf)
{
isEnabled = rule.getSendSelf();
}
else
{
if(issue.isSealed() && !activitySet.hasTransitionSealed())
{
isEnabled = false; // Do not send notifications to other users when Issue is "closed"
}
else
{
isEnabled = rule.getFilterState();
}
}
if(isEnabled)
{
Notification notification = new Notification(user, issue);
isEnabled = notification.sendConditionsMatch();
}
return isEnabled;
}
// in java/org/tigris/scarab/om/RIssueTypeOption.java
public void delete(final ScarabUser user, final Module module)
throws TorqueException, ScarabException
{
if (user.hasPermission(ScarabSecurity.DOMAIN__EDIT, module))
{
final List rios = getIssueType().getRIssueTypeOptions(
getAttributeOption().getAttribute(), false);
final Criteria c = new Criteria()
.add(RIssueTypeOptionPeer.ISSUE_TYPE_ID, getIssueTypeId())
.add(RIssueTypeOptionPeer.OPTION_ID, getOptionId());
RIssueTypeOptionPeer.doDelete(c);
rios.remove(this);
if (rios.size() > 0)
{
// Correct the ordering of the remaining options
final ArrayList optIds = new ArrayList();
for (int i=0; i<rios.size();i++)
{
final RIssueTypeOption rio = (RIssueTypeOption)rios.get(i);
optIds.add(rio.getOptionId());
}
final Criteria c2 = new Criteria()
.addIn(RIssueTypeOptionPeer.OPTION_ID, optIds)
.add(RIssueTypeOptionPeer.PREFERRED_ORDER, getOrder(),
Criteria.GREATER_THAN);
final List adjustRios = RIssueTypeOptionPeer.doSelect(c2);
for (int j=0; j<adjustRios.size();j++)
{
final RIssueTypeOption rio = (RIssueTypeOption)adjustRios.get(j);
rio.setOrder(rio.getOrder() -1);
rio.save();
}
}
}
else
{
throw new ScarabException(L10NKeySet.YouDoNotHavePermissionToAction);
}
}
// in java/org/tigris/scarab/om/RIssueTypeOption.java
public RIssueTypeOption copyRio()
throws TorqueException
{
RIssueTypeOption rio = new RIssueTypeOption();
rio.setIssueTypeId(getIssueTypeId());
rio.setOptionId(getOptionId());
rio.setActive(getActive());
rio.setOrder(getOrder());
rio.setWeight(getWeight());
return rio;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public Issue getNewIssue(IssueType issueType)
throws TorqueException
{
Issue issue = Issue.getNewInstance(this, issueType);
issue.setDeleted(false);
return issue;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public synchronized List getAncestors()
throws TorqueException
{
if (parentModules == null)
{
parentModules = new ArrayList();
Module parent = getParent();
if (parent != null && !parent.getModuleId().equals(ROOT_ID) && !isEndlessLoop(parent))
{
addAncestors(parent);
}
}
return parentModules;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
private void addAncestors(Module module)
throws TorqueException
{
if (!module.getParentId().equals(ROOT_ID))
{
addAncestors(module.getParent());
}
parentModules.add(module);
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public boolean isEndlessLoop(Module parent)
throws TorqueException
{
if (parent.getModuleId() != ROOT_ID)
{
Module parentParent = parent.getParent();
if (parentParent != null && parentParent == this)
{
return true;
}
}
return false;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public AttributeGroup createNewGroup (IssueType issueType)
throws TorqueException
{
return issueType.createNewGroup(this);
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getDedupeGroupsWithAttributes(IssueType issueType)
throws TorqueException
{
List result = null;
if(issueType == null)
{
result = new Vector(0);
}
else
{
Object obj = getMethodResult().get(this,
GET_DEDUPE_GROUPS_WITH_ATTRIBUTES, issueType);
if (obj == null)
{
List attributeGroups = issueType.getAttributeGroups(this, true);
result = new ArrayList(attributeGroups.size());
for (Iterator itr = attributeGroups.iterator(); itr.hasNext();)
{
AttributeGroup ag = (AttributeGroup) itr.next();
if (ag.getDedupe() && !ag.getAttributes().isEmpty())
{
result.add(ag);
}
}
getMethodResult().put(result, this,
GET_DEDUPE_GROUPS_WITH_ATTRIBUTES, issueType);
}
else
{
result = (List) obj;
}
}
return result;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getDedupeAttributeGroups(IssueType issueType)
throws TorqueException
{
return getDedupeAttributeGroups(issueType, true);
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getDedupeAttributeGroups(IssueType issueType,
boolean activeOnly)
throws TorqueException
{
List groups = issueType.getAttributeGroups(this, activeOnly);
List dedupeGroups = new ArrayList();
for (int i =0;i< groups.size(); i++)
{
AttributeGroup group = (AttributeGroup)groups.get(i);
if (group.getDedupe())
{
dedupeGroups.add(group);
}
}
return dedupeGroups;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public int getDedupeSequence(IssueType issueType)
throws TorqueException
{
return issueType.getDedupeSequence(this);
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public ScarabUser[] getEligibleIssueReporters()
throws TorqueException
{
return getUsers(ScarabSecurity.ISSUE__ENTER);
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public ScarabUser[] getEligibleUsers(Attribute attribute)
throws TorqueException,ScarabException
{
ScarabUser[] users = null;
if (attribute.isUserAttribute())
{
String permission = attribute.getPermission();
if (permission == null)
{
throw new ScarabException(
L10NKeySet.ExceptionNoAttributePermission,
attribute.getName());
}
else
{
users = getUsers(permission);
}
}
return users;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getSavedReports(final ScarabUser user)
throws TorqueException,ScarabException
{
List reports = null;
final Object obj = ScarabCache.get(this, GET_SAVED_REPORTS, user);
if (obj == null)
{
final Criteria crit = new Criteria()
.add(ReportPeer.DELETED, 0);
final Criteria.Criterion cc = crit.getNewCriterion(
ReportPeer.SCOPE_ID, Scope.MODULE__PK, Criteria.EQUAL);
cc.and(crit.getNewCriterion(
ReportPeer.MODULE_ID, getModuleId(), Criteria.EQUAL));
final Criteria.Criterion personalcc = crit.getNewCriterion(
ReportPeer.SCOPE_ID, Scope.PERSONAL__PK, Criteria.EQUAL);
personalcc.and(crit.getNewCriterion(
ReportPeer.USER_ID, user.getUserId(), Criteria.EQUAL));
final Criteria.Criterion personalmodulecc = crit.getNewCriterion(
ReportPeer.MODULE_ID, getModuleId(), Criteria.EQUAL);
personalmodulecc.or(crit.getNewCriterion(
ReportPeer.MODULE_ID, null, Criteria.EQUAL));
personalcc.and(personalmodulecc);
cc.or(personalcc);
crit.add(cc);
crit.addAscendingOrderByColumn(ReportPeer.SCOPE_ID);
final List torqueReports = ReportPeer.doSelect(crit);
// create ReportBridge's from torque Reports.
if (!torqueReports.isEmpty())
{
reports = new ArrayList(torqueReports.size());
for (Iterator i = torqueReports.iterator(); i.hasNext();)
{
final Report torqueReport = (Report)i.next();
try
{
reports.add( new ReportBridge(torqueReport) );
}
catch (org.xml.sax.SAXException e)
{
getLog().warn("Could not parse the report id=" +
torqueReport.getReportId() +
", so it has been marked as deleted.");
torqueReport.setDeleted(true);
torqueReport.save();
}
catch(Exception e)
{
throw new ScarabException(L10NKeySet.ExceptionGeneral,e);
}
}
}
else
{
reports = Collections.EMPTY_LIST;
}
ScarabCache.put(reports, this, GET_SAVED_REPORTS, user);
}
else
{
reports = (List)obj;
}
return reports;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getAttributes(final IssueType issueType)
throws TorqueException
{
final Criteria crit = new Criteria();
crit.add(RModuleAttributePeer.ISSUE_TYPE_ID, issueType.getIssueTypeId());
return getAttributes(crit);
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getAttributes(final Criteria criteria)
throws TorqueException
{
final List moduleAttributes = getRModuleAttributes(criteria);
final List attributes = new ArrayList(moduleAttributes.size());
for (int i=0; i<moduleAttributes.size(); i++)
{
attributes.add(
((RModuleAttribute) moduleAttributes.get(i)).getAttribute());
}
return attributes;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getUserAttributes(IssueType issueType)
throws TorqueException
{
return getUserAttributes(issueType, true);
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getUserAttributes(IssueType issueType, boolean activeOnly)
throws TorqueException
{
List rModuleAttributes = getRModuleAttributes(issueType, activeOnly, USER);
List userAttributes = new ArrayList();
for (int i=0; i<rModuleAttributes.size(); i++)
{
Attribute att = ((RModuleAttribute)rModuleAttributes.get(i)).getAttribute();
userAttributes.add(att);
}
return userAttributes;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getUserPermissions(IssueType issueType)
throws TorqueException
{
List userAttrs = getUserAttributes(issueType, true);
List permissions = new ArrayList();
for (int i = 0; i < userAttrs.size(); i++)
{
String permission = ((Attribute)userAttrs.get(i)).getPermission();
if (!permissions.contains(permission))
{
permissions.add(permission);
}
}
return permissions;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public int getLastAttribute(IssueType issueType, String attributeType)
throws TorqueException
{
List moduleAttributes = getRModuleAttributes(issueType, false, attributeType);
int last = 0;
for (int i=0; i<moduleAttributes.size(); i++)
{
int order = ((RModuleAttribute) moduleAttributes.get(i))
.getOrder();
if (order > last)
{
last = order;
}
}
return last;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public int getLastAttributeOption(Attribute attribute,
IssueType issueType)
throws TorqueException
{
List moduleOptions = getRModuleOptions(attribute, issueType);
int last = 0;
for (int i=0; i<moduleOptions.size(); i++)
{
int order = ((RModuleOption) moduleOptions.get(i))
.getOrder();
if (order > last)
{
last = order;
}
}
return last;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public void shiftAttributeOption(Attribute attribute,
IssueType issueType,
int offset)
throws TorqueException
{
List moduleOptions = getRModuleOptions(attribute, issueType, false);
RModuleOption rmo;
for (int i=0; i<moduleOptions.size(); i++)
{
rmo = (RModuleOption) moduleOptions.get(i);
int order = rmo.getOrder();
if (order >= offset && !rmo.getActive())
{
rmo.setOrder(order+1);
rmo.save();
}
}
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getAvailableAttributes(IssueType issueType,
String attributeType)
throws TorqueException
{
List allAttributes = AttributePeer.getAttributes(attributeType);
List availAttributes = new ArrayList();
List rModuleAttributes = getRModuleAttributes(issueType, false,
attributeType);
List moduleAttributes = new ArrayList();
if (rModuleAttributes.isEmpty())
{
availAttributes = allAttributes;
}
else
{
for (int i=0; i<rModuleAttributes.size(); i++)
{
moduleAttributes.add(
((RModuleAttribute) rModuleAttributes.get(i)).getAttribute());
}
for (int i=0; i<allAttributes.size(); i++)
{
Attribute att = (Attribute)allAttributes.get(i);
if (!moduleAttributes.contains(att))
{
availAttributes.add(att);
}
}
}
return availAttributes;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getAvailableAttributeOptions(Attribute attribute,
IssueType issueType)
throws TorqueException
{
List rModuleOptions = getRModuleOptions(attribute, issueType, false);
List moduleOptions = new ArrayList();
if (rModuleOptions != null)
{
for (int i=0; i<rModuleOptions.size(); i++)
{
moduleOptions.add(
((RModuleOption) rModuleOptions.get(i)).getAttributeOption());
}
}
List allOptions = attribute.getAttributeOptions(true);
List availOptions = new ArrayList();
for (int i=0; i<allOptions.size(); i++)
{
AttributeOption option = (AttributeOption)allOptions.get(i);
if (!moduleOptions.contains(option) && !option.getDeleted())
{
availOptions.add(option);
}
}
return availOptions;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getDefaultRModuleUserAttributes(IssueType issueType)
throws TorqueException
{
List result = null;
Object obj = ScarabCache.get(this, GET_DEFAULT_RMODULE_USERATTRIBUTES,
issueType);
if (obj == null)
{
result = new LinkedList();
Attribute[] attributes = new Attribute[3];
int count = 0;
//attributes[count++] = issueType.getDefaultTextAttribute(this);
//if (attributes[0] == null)
//{
// count = 0;
//}
List rma1s = getRModuleAttributes(issueType, true, NON_USER);
Iterator i = rma1s.iterator();
// Find first default text attribute ...
while (i.hasNext())
{
RModuleAttribute rmat = (RModuleAttribute)i.next();
Attribute a = rmat.getAttribute();
if (a.isTextAttribute() && rmat.getIsDefaultText())
{
attributes[count++] = a;
break;
}
}
// Add all UserAttributes
List rma2s = getRModuleAttributes(issueType, true, USER);
i = rma2s.iterator();
while (i.hasNext() && count < 3)
{
Attribute a = ((RModuleAttribute)i.next()).getAttribute();
attributes[count++] = a;
}
// if we still have less than 3 attributes, give the non user
// attributes another try
i = rma1s.iterator();
while (i.hasNext() && count < 3)
{
Attribute a = ((RModuleAttribute)i.next()).getAttribute();
if (!a.equals(attributes[0]) && !a.equals(attributes[1]))
{
attributes[count++] = a;
}
}
for (int j=0; j<attributes.length; j++)
{
if (attributes[j] != null)
{
RModuleUserAttribute rmua =
RModuleUserAttributeManager.getInstance();
rmua.setAttribute(attributes[j]);
rmua.setIssueType(issueType);
rmua.setOrder(j+1);
result.add(rmua);
}
}
ScarabCache.put(result, this, GET_DEFAULT_RMODULE_USERATTRIBUTES,
issueType);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public Issue getIssueById(String id)
throws TorqueException
{
return IssueManager.getIssueById(id, getCode());
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getIssueTypes()
throws TorqueException
{
return getIssueTypes(true);
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getIssueTypes(boolean activeOnly)
throws TorqueException
{
List types = null;
Boolean activeOnlyValue = activeOnly ? Boolean.TRUE : Boolean.FALSE;
Object obj = ScarabCache.get(this, GET_ISSUE_TYPES, activeOnlyValue);
if (obj == null)
{
Criteria crit = new Criteria();
crit.addJoin(RModuleIssueTypePeer.ISSUE_TYPE_ID,
IssueTypePeer. ISSUE_TYPE_ID);
crit.add(RModuleIssueTypePeer.MODULE_ID, getModuleId());
if (activeOnly)
{
crit.add(RModuleIssueTypePeer.ACTIVE, true);
}
crit.add(IssueTypePeer.PARENT_ID, 0);
crit.add(IssueTypePeer.DELETED, 0);
crit.addAscendingOrderByColumn(RModuleIssueTypePeer.PREFERRED_ORDER);
types = IssueTypePeer.doSelect(crit);
ScarabCache.put(types, this, "getIssueTypes", activeOnlyValue);
}
else
{
types = (List)obj;
}
return types;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getNavIssueTypes()
throws TorqueException
{
List types = null;
Object obj = getMethodResult().get(this, GET_NAV_ISSUE_TYPES);
if (obj == null)
{
Criteria crit = new Criteria();
crit.addJoin(RModuleIssueTypePeer.ISSUE_TYPE_ID,
IssueTypePeer. ISSUE_TYPE_ID);
crit.add(RModuleIssueTypePeer. MODULE_ID, getModuleId());
crit.add(RModuleIssueTypePeer.ACTIVE, true);
crit.add(RModuleIssueTypePeer.DISPLAY, true);
crit.add(IssueTypePeer.PARENT_ID, 0);
crit.add(IssueTypePeer.DELETED, 0);
crit.addAscendingOrderByColumn(
RModuleIssueTypePeer.PREFERRED_ORDER);
types = IssueTypePeer.doSelect(crit);
getMethodResult().put(types, this, GET_NAV_ISSUE_TYPES);
}
else
{
types = (List)obj;
}
return types;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getAvailableIssueTypes()
throws TorqueException
{
List availIssueTypes = null;
Object obj = ScarabCache.get(this, GET_AVAILABLE_ISSUE_TYPES);
if (obj == null)
{
availIssueTypes = new ArrayList();
List allIssueTypes = IssueTypePeer.getAllIssueTypes(false);
List currentIssueTypes = getIssueTypes(false);
Iterator iter = allIssueTypes.iterator();
while (iter.hasNext())
{
IssueType issueType = (IssueType)iter.next();
if (IssueTypePeer.getRootKey().equals(issueType.getParentId())
&& !IssueTypePeer.getRootKey().equals(issueType.getIssueTypeId())
&& !currentIssueTypes.contains(issueType))
{
availIssueTypes.add(issueType);
}
}
ScarabCache.put(availIssueTypes, this, GET_AVAILABLE_ISSUE_TYPES);
}
else
{
availIssueTypes = (List)obj;
}
return availIssueTypes;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getRModuleAttributes(Criteria crit)
throws TorqueException
{
crit.add(RModuleAttributePeer.MODULE_ID, getModuleId());
crit.addJoin(RModuleAttributePeer.ATTRIBUTE_ID,
AttributePeer.ATTRIBUTE_ID);
crit.add(AttributePeer.DELETED, false);
return RModuleAttributePeer.doSelect(crit);
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public RModuleAttribute addRModuleAttribute(final IssueType issueType,
final Attribute attribute)
throws TorqueException, ScarabException
{
String attributeType = null;
attributeType = (attribute.isUserAttribute() ? USER : NON_USER);
final RModuleAttribute rma = new RModuleAttribute();
rma.setModuleId(getModuleId());
rma.setIssueTypeId(issueType.getIssueTypeId());
rma.setAttributeId(attribute.getAttributeId());
rma.setOrder(getLastAttribute(issueType, attributeType) + 1);
rma.setConditionsArray(attribute.getConditionsArray(), attribute.getConditionOperator());
rma.save();
getRModuleAttributes(issueType, false, attributeType).add(rma);
// Add to template type
final IssueType templateType = IssueTypeManager
.getInstance(issueType.getTemplateId(), false);
final RModuleAttribute rma2 = new RModuleAttribute();
rma2.setModuleId(getModuleId());
rma2.setIssueTypeId(templateType.getIssueTypeId());
rma2.setAttributeId(attribute.getAttributeId());
rma2.setOrder(getLastAttribute(templateType, attributeType) + 1);
rma2.save();
return rma;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public RModuleOption addRModuleOption(IssueType issueType,
AttributeOption option)
throws TorqueException
{
RModuleOption rmo = new RModuleOption();
rmo.setModuleId(getModuleId());
rmo.setIssueTypeId(issueType.getIssueTypeId());
rmo.setOptionId(option.getOptionId());
rmo.setDisplayValue(option.getName());
rmo.setOrder(getLastAttributeOption(option.getAttribute(), issueType) + 1);
return rmo;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public RModuleAttribute getRModuleAttribute(Attribute attribute,
IssueType issueType) throws TorqueException {
RModuleAttribute rma = null;
if (attribute != null && issueType != null) {
List rmas = null;
if (attribute.isUserAttribute()) {
rmas = getRModuleAttributes(issueType, false, USER);
} else {
rmas = getRModuleAttributes(issueType, false, NON_USER);
}
Iterator i = rmas.iterator();
while (i.hasNext()) {
rma = (RModuleAttribute) i.next();
if (rma.getAttribute().equals(attribute)) {
break;
} else {
rma = null;
}
}
}
return rma;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getRModuleAttributes(IssueType issueType)
throws TorqueException
{
return getRModuleAttributes(issueType, false);
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public boolean hasAttributes(final IssueType issueType)
throws TorqueException, DataSetException
{
final Criteria crit = new Criteria();
crit.add(RModuleAttributePeer.ISSUE_TYPE_ID, issueType.getIssueTypeId());
crit.add(RModuleAttributePeer.MODULE_ID, getModuleId());
crit.addSelectColumn("count(" + RModuleAttributePeer.ATTRIBUTE_ID + ")");
return ((Record)IssuePeer.doSelectVillageRecords(crit).get(0))
.getValue(1).asInt() > 0;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getRModuleAttributes(IssueType issueType, boolean activeOnly)
throws TorqueException
{
return getRModuleAttributes(issueType, activeOnly, "all");
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getRModuleAttributes(IssueType issueType, boolean activeOnly,
String attributeType)
throws TorqueException
{
List rmas = null;
Boolean activeBool = (activeOnly ? Boolean.TRUE : Boolean.FALSE);
Object obj = getMethodResult().get(this, GET_R_MODULE_ATTRIBUTES,
issueType, activeBool, attributeType);
if (obj == null)
{
Criteria crit = new Criteria();
Integer issueTypeId = issueType.getIssueTypeId();
Integer moduleId = getModuleId();
crit.add(RModuleAttributePeer.ISSUE_TYPE_ID, issueTypeId);
crit.add(RModuleAttributePeer.MODULE_ID, moduleId);
crit.addAscendingOrderByColumn(RModuleAttributePeer.PREFERRED_ORDER);
crit.addAscendingOrderByColumn(RModuleAttributePeer.DISPLAY_VALUE);
if (activeOnly)
{
crit.add(RModuleAttributePeer.ACTIVE, true);
}
crit.addJoin(AttributePeer.ATTRIBUTE_ID, RModuleAttributePeer.ATTRIBUTE_ID);
if (USER.equals(attributeType))
{
crit.add(AttributePeer.ATTRIBUTE_TYPE_ID,
AttributeTypePeer.USER_TYPE_KEY);
}
else if (NON_USER.equals(attributeType))
{
crit.add(AttributePeer.ATTRIBUTE_TYPE_ID,
AttributeTypePeer.USER_TYPE_KEY,
Criteria.NOT_EQUAL);
}
rmas = RModuleAttributePeer.doSelect(crit);
getMethodResult().put(rmas, this, GET_R_MODULE_ATTRIBUTES,
issueType, activeBool, attributeType);
}
else
{
rmas = (List)obj;
}
return rmas;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getAllAttributes()
throws TorqueException
{
Criteria crit = new Criteria();
crit.addJoin(RModuleAttributePeer.ATTRIBUTE_ID, AttributePeer.ATTRIBUTE_ID);
crit.add(RModuleAttributePeer.MODULE_ID, getModuleId());
crit.setDistinct();
List result = AttributePeer.doSelect(crit);
return result;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getAllOptionAttributes()
throws TorqueException
{
Criteria crit = new Criteria();
crit.addJoin(RModuleAttributePeer.ATTRIBUTE_ID, AttributePeer.ATTRIBUTE_ID);
crit.addIn(AttributePeer.ATTRIBUTE_TYPE_ID, OptionAttributeIds );
crit.add(AttributePeer.DELETED, false);
crit.add(RModuleAttributePeer.ACTIVE, true);
crit.add(RModuleAttributePeer.MODULE_ID, getModuleId());
crit.addAscendingOrderByColumn(
AttributePeer.ATTRIBUTE_NAME);
crit.setDistinct();
List result = AttributePeer.doSelect(crit);
return result;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getAllAttributeOptions(Integer attributeId)
throws TorqueException, ScarabException
{
List result;
if (attributeId == null)
{
this.getLog().warn(
"No attribute specified while fetching attribute options.");
result = Collections.EMPTY_LIST;
} else
{
int id = attributeId.intValue();
Attribute attribute = Attribute.getInstance(id);
if (attribute == null)
{
this.getLog().warn(
"No options found for Attribute [" + attributeId + "]");
// L10NMessage msg = new
// L10NMessage(L10NKeySet.AttributeNotInSession,""+attributeId);
// throw new ScarabException(msg);
result = Collections.EMPTY_LIST;
} else
{
// Integer attributeId = attribute.getAttributeId();
Criteria crit = new Criteria();
crit.add(AttributeOptionPeer.ATTRIBUTE_ID, attributeId);
crit.add(AttributeOptionPeer.DELETED, false);
result = AttributeOptionPeer.doSelect(crit);
}
}
return result;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getActiveAttributesByName(IssueType issueType,
String attributeType)
throws TorqueException
{
Criteria crit = new Criteria();
crit.add(RModuleAttributePeer.MODULE_ID, getModuleId());
crit.add(RModuleAttributePeer.ISSUE_TYPE_ID,
issueType.getIssueTypeId());
crit.addJoin(RModuleAttributePeer.ATTRIBUTE_ID,
AttributePeer.ATTRIBUTE_ID);
crit.add(AttributePeer.DELETED, false);
crit.add(RModuleAttributePeer.ACTIVE, true);
if (USER.equals(attributeType))
{
crit.add(AttributePeer.ATTRIBUTE_TYPE_ID,
AttributeTypePeer.USER_TYPE_KEY);
crit.addJoin(AttributePeer.ATTRIBUTE_ID,
RModuleAttributePeer.ATTRIBUTE_ID);
}
else if (NON_USER.equals(attributeType))
{
crit.add(AttributePeer.ATTRIBUTE_TYPE_ID,
AttributeTypePeer.USER_TYPE_KEY,
Criteria.NOT_EQUAL);
}
crit.addAscendingOrderByColumn(
RModuleAttributePeer.DISPLAY_VALUE);
return AttributePeer.doSelect(crit);
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getRModuleOptions(Attribute attribute, IssueType issueType)
throws TorqueException
{
return getRModuleOptions(attribute, issueType, true);
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getRModuleOptions(Attribute attribute, IssueType issueType,
boolean activeOnly)
throws TorqueException
{
List allRModuleOptions = getAllRModuleOptions(attribute, issueType);
List resultRModuleOptions = null;
if (allRModuleOptions != null)
{
resultRModuleOptions = new ArrayList(allRModuleOptions.size());
int orderIndex = 0;
for (int i = 0; i < allRModuleOptions.size(); i++)
{
RModuleOption rmo = (RModuleOption) allRModuleOptions.get(i);
if (!activeOnly || rmo.getActive())
{
rmo.setOrder(++orderIndex); // take care that the option order is consecutive
resultRModuleOptions.add(rmo);
}
}
}
return resultRModuleOptions;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
private List getAllRModuleOptions(Attribute attribute, IssueType issueType)
throws TorqueException
{
List rModOpts = EmptyList;
if(attribute != null)
{
Object obj = getMethodResult().get(this, GET_ALL_R_MODULE_OPTIONS, attribute, issueType);
if (obj == null)
{
List options = attribute.getAttributeOptions(true);
if (options != null && options.size() > 0)
{
Integer[] optIds = new Integer[options.size()];
for (int i=optIds.length-1; i>=0; i--)
{
optIds[i] = ((AttributeOption)options.get(i)).getOptionId();
}
Criteria crit = new Criteria();
crit.add(RModuleOptionPeer.ISSUE_TYPE_ID, issueType.getIssueTypeId());
crit.add(RModuleOptionPeer.MODULE_ID, getModuleId());
crit.addIn(RModuleOptionPeer.OPTION_ID, optIds);
crit.addAscendingOrderByColumn(RModuleOptionPeer.PREFERRED_ORDER);
crit.addAscendingOrderByColumn(RModuleOptionPeer.DISPLAY_VALUE);
rModOpts = getRModuleOptions(crit);
// It would be extremely suspicious to see a null value here.
assert (rModOpts != null); // for development
if(rModOpts == null) // for production
{
rModOpts = EmptyList;
}
}
getMethodResult().put(rModOpts, this, GET_ALL_R_MODULE_OPTIONS, attribute, issueType);
}
else
{
rModOpts = (List)obj;
}
}
return rModOpts;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public RModuleOption getRModuleOption(AttributeOption option,
IssueType issueType)
throws TorqueException
{
RModuleOption rmo = null;
List rmos = getRModuleOptions(option.getAttribute(),
issueType, false);
RModuleOption testRMO = null;
for (Iterator i = rmos.iterator();i.hasNext();)
{
testRMO = (RModuleOption)i.next();
if (testRMO.getAttributeOption().equals(option))
{
rmo = testRMO;
break;
}
}
return rmo;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getAttributeOptions (Attribute attribute, IssueType issueType)
throws TorqueException
{
List attributeOptions = null;
try
{
List rModuleOptions = getOptionTree(attribute, issueType, false);
attributeOptions = new ArrayList(rModuleOptions.size());
for (int i=0; i<rModuleOptions.size(); i++)
{
attributeOptions.add(
((RModuleOption)rModuleOptions.get(i)).getAttributeOption());
}
}
catch (Exception e)
{
}
return attributeOptions;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getLeafRModuleOptions(Attribute attribute, IssueType issuetype)
throws TorqueException
{
try
{
return getLeafRModuleOptions(attribute, issuetype, true);
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getLeafRModuleOptions(Attribute attribute,
IssueType issueType,
boolean activeOnly)
throws TorqueException
{
List rModOpts = null;
Boolean activeBool = (activeOnly ? Boolean.TRUE : Boolean.FALSE);
Object obj = getMethodResult().get(this, GET_LEAF_R_MODULE_OPTIONS,
attribute, issueType, activeBool);
if (obj == null)
{
rModOpts = getRModuleOptions(attribute, issueType, activeOnly);
if (rModOpts != null)
{
// put options in a map for searching
Map optionsMap = new HashMap((int)(rModOpts.size()*1.5));
for (int i=rModOpts.size()-1; i>=0; i--)
{
RModuleOption rmo = (RModuleOption)rModOpts.get(i);
optionsMap.put(rmo.getOptionId(), null);
}
// remove options with descendants in the list
for (int i=rModOpts.size()-1; i>=0; i--)
{
AttributeOption option =
((RModuleOption)rModOpts.get(i)).getAttributeOption();
List descendants = option.getChildren();
if (descendants != null)
{
for (int j=descendants.size()-1; j>=0; j--)
{
AttributeOption descendant =
(AttributeOption)descendants.get(j);
if (optionsMap
.containsKey(descendant.getOptionId()))
{
rModOpts.remove(i);
break;
}
}
}
}
getMethodResult().put(rModOpts, this, GET_LEAF_R_MODULE_OPTIONS,
attribute, issueType, activeBool);
}
}
else
{
rModOpts = (List)obj;
}
return rModOpts;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getOptionTree(Attribute attribute, IssueType issueType)
throws TorqueException
{
return getOptionTree(attribute, issueType, true);
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getOptionTree(Attribute attribute, IssueType issueType,
boolean activeOnly)
throws TorqueException
{
// I think this code should place an option that had multiple parents -
// OSX and Mac,BSD is usual example - into the list in multiple places
// and it should have the level set differently for the two locations.
// The code is currently only placing the option in the list once.
// Since the behavior is not well spec'ed, leaving as it is. - jdm
List moduleOptions = null;
moduleOptions = getRModuleOptions(attribute, issueType, activeOnly);
if (moduleOptions == null)
{
return moduleOptions;
}
int size = moduleOptions.size();
List[] ancestors = new List[size];
// find all ancestors
for (int i=size-1; i>=0; i--)
{
AttributeOption option =
((RModuleOption)moduleOptions.get(i)).getAttributeOption();
ancestors[i] = option.getAncestors();
}
for (int i=0; i<size; i++)
{
RModuleOption moduleOption = (RModuleOption)moduleOptions.get(i);
int level = 1;
if (ancestors[i] != null)
{
// Set level for first ancestor as the option is only
// shown once.
for (int j=ancestors[i].size()-1; j>=0; j--)
{
AttributeOption ancestor =
(AttributeOption)ancestors[i].get(j);
for (int k=0; k<i; k++)
{
RModuleOption potentialParent = (RModuleOption)
moduleOptions.get(k);
if (ancestor.getOptionId()
.equals(potentialParent.getOptionId()) &&
!ancestor.getOptionId()
.equals(moduleOption.getOptionId()) )
{
moduleOption.setLevel(level++);
}
}
}
}
}
return moduleOptions;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public String getOptionsTreeAsJSON(RunData data, String fromValue, Attribute attribute, Issue issue, boolean activeOnly) throws TorqueException
{
getLog().debug("Build options tree for Attribute [" + attribute.getName() + "]");
List<RModuleOption> moduleOptions = (List<RModuleOption>) getRModuleOptions(attribute, issue.getIssueType(), activeOnly);
if (moduleOptions == null) {
return null;
}
StringBuffer json = new StringBuffer("{ 'attributeId' : ");
json.append(attribute.getAttributeId());
json.append(", 'name' : '");
json.append(attribute.getName());
json.append("', '_children': [");
boolean first = true;
for (RModuleOption moduleOption : moduleOptions) {
if (!AbstractScarabModule.canMakeTransitionForOption(data, fromValue, moduleOption, issue, false)) continue;
if (moduleOption.getAttributeOption().getAncestors().size() == 1) {
if (!first) {
json.append(", ");
}
json.append(this.getModuleOptionAsJSON(data, fromValue, attribute, issue, moduleOption));
first = false;
}
}
json.append("]}");
return json.toString();
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
private String getModuleOptionAsJSON(RunData data, String fromValue, Attribute attribute, Issue issue, RModuleOption moduleOption) throws TorqueException {
StringBuffer json = new StringBuffer("{ 'optionId': ");
json.append(moduleOption.getOptionId());
json.append(", 'displayValue': '");
json.append(moduleOption.getDisplayValue());
json.append("', '_children': [");
boolean first = true;
moduleOption.getChildren(moduleOption.getIssueType());
for (RModuleOption rmo : (List<RModuleOption>) moduleOption.getChildren(moduleOption.getIssueType())) {
if (!AbstractScarabModule.canMakeTransitionForOption(data, fromValue, rmo, issue, false)) continue;
if (!first) {
json.append(", ");
}
json.append(this.getModuleOptionAsJSON(data, fromValue, attribute, issue, rmo));
first = false;
}
json.append("]}");
return json.toString();
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getRModuleIssueTypes(String sortColumn, String sortPolarity)
throws TorqueException
{
List types = null;
Object obj = ScarabCache.get(this, GET_R_MODULE_ISSUE_TYPES);
if (obj == null)
{
Criteria crit = new Criteria();
crit.add(RModuleIssueTypePeer.MODULE_ID, getModuleId())
.addJoin(RModuleIssueTypePeer.ISSUE_TYPE_ID,
IssueTypePeer.ISSUE_TYPE_ID)
.add(IssueTypePeer.PARENT_ID, 0)
.add(IssueTypePeer.DELETED, 0);
if (sortColumn.equals("name"))
{
if (sortPolarity.equals("desc"))
{
crit.addDescendingOrderByColumn(IssueTypePeer.NAME);
}
else
{
crit.addAscendingOrderByColumn(IssueTypePeer.NAME);
}
}
else
{
// sortColumn defaults to sequence #
if (sortPolarity.equals("desc"))
{
crit.addDescendingOrderByColumn(RModuleIssueTypePeer
.PREFERRED_ORDER);
}
else
{
crit.addAscendingOrderByColumn(RModuleIssueTypePeer
.PREFERRED_ORDER);
}
}
types = RModuleIssueTypePeer.doSelect(crit);
ScarabCache.put(types, this, GET_R_MODULE_ISSUE_TYPES);
}
else
{
types = (List) obj;
}
return types;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public void addAttributeOption(final IssueType issueType,
final AttributeOption option)
throws TorqueException, ScarabException
{
final RModuleOption rmo = addRModuleOption(issueType, option);
rmo.save();
shiftAttributeOption(option.getAttribute(), issueType, rmo.getOrder());
// add module-attributeoption mappings to template type
final IssueType templateType = IssueTypeManager
.getInstance(issueType.getTemplateId());
final RModuleOption rmo2 = addRModuleOption(templateType, option);
rmo2.save();
//FIXME: is it useful to shift options for the templateType?
//shiftAttributeOption(option.getAttribute(), templateType, rmo.getOrder());
//if the cache is not cleared, when two options are added at the same time,
//getLastAttributeOption does not take into account the newest active options.
ScarabCache.clear();
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public void setRmaBasedOnIssueType(final RIssueTypeAttribute ria)
throws TorqueException, ScarabException
{
final RModuleAttribute rma = new RModuleAttribute();
rma.setModuleId(getModuleId());
rma.setIssueTypeId(ria.getIssueTypeId());
rma.setAttributeId(ria.getAttributeId());
rma.setActive(ria.getActive());
rma.setRequired(ria.getRequired());
rma.setOrder(ria.getOrder());
rma.setQuickSearch(ria.getQuickSearch());
rma.setDefaultTextFlag(ria.getDefaultTextFlag());
rma.save();
final RModuleAttribute rma2 = rma.copy();
rma2.setModuleId(getModuleId());
rma2.setIssueTypeId(ria.getIssueType().getTemplateId());
rma2.setAttributeId(ria.getAttributeId());
rma2.setActive(ria.getActive());
rma2.setRequired(ria.getRequired());
rma2.setOrder(ria.getOrder());
rma2.setQuickSearch(ria.getQuickSearch());
rma2.setDefaultTextFlag(ria.getDefaultTextFlag());
rma2.save();
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public void setRmoBasedOnIssueType(final RIssueTypeOption rio)
throws TorqueException, ScarabException
{
final RModuleOption rmo = new RModuleOption();
rmo.setModuleId(getModuleId());
rmo.setIssueTypeId(rio.getIssueTypeId());
rmo.setOptionId(rio.getOptionId());
rmo.setActive(rio.getActive());
rmo.setOrder(rio.getOrder());
rmo.setWeight(rio.getWeight());
rmo.save();
final RModuleOption rmo2 = rmo.copy();
rmo2.setModuleId(getModuleId());
rmo2.setIssueTypeId(rio.getIssueType().getTemplateId());
rmo2.setOptionId(rio.getOptionId());
rmo2.setActive(rio.getActive());
rmo2.setOrder(rio.getOrder());
rmo2.setWeight(rio.getWeight());
rmo2.save();
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public boolean includesIssueType(final IssueType issueType)
throws TorqueException, DataSetException
{
final Criteria crit = new Criteria();
crit.add(RModuleIssueTypePeer.MODULE_ID,
getModuleId());
crit.add(RModuleIssueTypePeer.ISSUE_TYPE_ID,
issueType.getIssueTypeId());
return RModuleIssueTypePeer.count(crit) > 0;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public void addIssueType(final IssueType issueType)
throws TorqueException, ValidationException, DataSetException, ScarabException
{
// do some validation, refuse to add an issue type that is in a bad
// state
if (issueType == null)
{
throw new ValidationException(L10NKeySet.ExceptionIntegrityCheckFailure,
"NULL",
getName(),
"Issue type was null");
}
// check that the issueType is not already added.
if (includesIssueType(issueType))
{
throw new ValidationException(L10NKeySet.ExceptionDuplicateIssueType,
issueType,
getName());
}
final String typeName = issueType.getName();
// check attribute groups
final List testGroups = issueType.getAttributeGroups(null, false);
try
{
if (testGroups == null)
{
final Localizable l10nMessage = new L10NMessage(L10NKeySet.IssueTypeWasNull);
throw new ValidationException(L10NKeySet.ExceptionIntegrityCheckFailure,
typeName,
getName(),
l10nMessage);
}
else
{
for (Iterator i = testGroups.iterator(); i.hasNext();)
{
final AttributeGroup group = (AttributeGroup)i.next();
// check attributes
final List attrs = group.getAttributes();
if (attrs != null)
{
for (Iterator j = attrs.iterator(); j.hasNext();)
{
// check attribute-attribute group maps
final Attribute attr = (Attribute)j.next();
if (attr == null)
{
final L10NMessage l10nMessage = new L10NMessage(L10NKeySet.AttributesContainsNull);
throw new ValidationException(L10NKeySet.ExceptionIntegrityCheckFailure,
typeName,
getName(),
l10nMessage);
}
// TODO: add workflow validation
final RAttributeAttributeGroup raag = group.getRAttributeAttributeGroup(attr);
if (raag == null)
{
final L10NMessage l10nMessage = new L10NMessage(L10NKeySet.AttributeMappingIsMissing, attr.getName());
throw new ValidationException(L10NKeySet.ExceptionIntegrityCheckFailure,
typeName,
getName(),
l10nMessage);
}
// check attribute-issue type maps
final RIssueTypeAttribute ria = issueType.getRIssueTypeAttribute(attr);
if (ria == null)
{
final L10NMessage l10nMessage = new L10NMessage(L10NKeySet.AttributeToIssueTypeMappingIsMissing, attr.getName());
throw new ValidationException(L10NKeySet.ExceptionIntegrityCheckFailure,
typeName,
getName(),
l10nMessage);
}
// check options
final List rios = issueType.getRIssueTypeOptions(attr, false);
if (rios != null)
{
for (Iterator k=rios.iterator(); k.hasNext();)
{
if (k.next() == null)
{
final L10NMessage l10nMessage = new L10NMessage(L10NKeySet.ListOfOptionsMissing, attr.getName());
throw new ValidationException(L10NKeySet.ExceptionIntegrityCheckFailure,
typeName,
getName(),
l10nMessage);
}
}
}
}
}
}
}
}
catch (ValidationException ve)
{
throw ve;
}
catch (Exception e)
{
throw new ScarabException(
L10NKeySet.ExceptionGeneral,
e.getMessage(),
e);
}
// okay we passed, start modifying tables
// add module-issue type mapping
final RModuleIssueType rmit = new RModuleIssueType();
rmit.setModuleId(getModuleId());
rmit.setIssueTypeId(issueType.getIssueTypeId());
rmit.setActive(true);
rmit.setDisplay(false);
rmit.setOrder(getRModuleIssueTypes().size() + 1);
rmit.setDedupe(issueType.getDedupe());
rmit.save();
// add user attributes
final List userRIAs = issueType.getRIssueTypeAttributes(false, "user");
for (int m=0; m<userRIAs.size(); m++)
{
final RIssueTypeAttribute userRia = (RIssueTypeAttribute)userRIAs.get(m);
setRmaBasedOnIssueType(userRia);
}
// add workflow
WorkflowFactory.getInstance().addIssueTypeWorkflowToModule(this, issueType);
// add attribute groups
final List groups = issueType.getAttributeGroups(null, false);
if (groups.isEmpty())
{
// Create default groups
final AttributeGroup ag = createNewGroup(issueType);
ag.setOrder(1);
ag.setDedupe(true);
ag.setDescription(null);
ag.save();
final AttributeGroup ag2 = createNewGroup(issueType);
ag2.setOrder(3);
ag2.setDedupe(false);
ag2.setDescription(null);
ag2.save();
}
else
{
// Inherit attribute groups from issue type
for (int i=0; i<groups.size(); i++)
{
final AttributeGroup group = (AttributeGroup)groups.get(i);
final AttributeGroup moduleGroup = group.copyGroup();
moduleGroup.setModuleId(getModuleId());
moduleGroup.setIssueTypeId(issueType.getIssueTypeId());
moduleGroup.save();
// add attributes
final List attrs = group.getAttributes();
if (attrs != null)
{
for (int j=0; j<attrs.size(); j++)
{
// save attribute-attribute group maps
final Attribute attr = (Attribute)attrs.get(j);
final RAttributeAttributeGroup raag = group.getRAttributeAttributeGroup(attr);
final RAttributeAttributeGroup moduleRaag = new RAttributeAttributeGroup();
moduleRaag.setAttributeId(raag.getAttributeId());
moduleRaag.setOrder(raag.getOrder());
moduleRaag.setGroupId(moduleGroup.getAttributeGroupId());
moduleRaag.save();
// save attribute-module maps
final RIssueTypeAttribute ria = issueType.getRIssueTypeAttribute(attr);
setRmaBasedOnIssueType(ria);
// save options
final List rios = issueType.getRIssueTypeOptions(attr, false);
if (rios != null)
{
for (int k=0; k<rios.size(); k++)
{
final RIssueTypeOption rio = (RIssueTypeOption)rios.get(k);
setRmoBasedOnIssueType(rio);
}
}
}
}
}
}
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public RModuleIssueType getRModuleIssueType(final IssueType issueType)
throws TorqueException
{
RModuleIssueType rmit = null;
try
{
final SimpleKey[] keys = { SimpleKey.keyFor(getModuleId()),
SimpleKey.keyFor(issueType.getIssueTypeId())
};
rmit = RModuleIssueTypeManager.getInstance(new ComboKey(keys));
}
catch (NoRowsException e)
{
// ignore and return null, if the rmit does not exist
}
return rmit;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getTemplateTypes()
throws TorqueException, ScarabException
{
List templateTypes = new ArrayList();
final Object obj = ScarabCache.get(this, GET_TEMPLATE_TYPES);
if (obj == null)
{
final Criteria crit = new Criteria();
crit.add(RModuleIssueTypePeer.MODULE_ID, getModuleId())
.addJoin(RModuleIssueTypePeer.ISSUE_TYPE_ID,
IssueTypePeer.ISSUE_TYPE_ID)
.add(IssueTypePeer.DELETED, 0);
final List rmits = RModuleIssueTypePeer.doSelect(crit);
for (int i=0; i<rmits.size(); i++)
{
final RModuleIssueType rmit = (RModuleIssueType)rmits.get(i);
final IssueType templateType = rmit.getIssueType().getTemplateIssueType();
templateTypes.add(templateType);
}
ScarabCache.put(templateTypes, this, GET_TEMPLATE_TYPES);
}
else
{
templateTypes = (List)obj;
}
return templateTypes;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getUnapprovedQueries() throws TorqueException
{
List queries = null;
Object obj = ScarabCache.get(this, GET_UNAPPROVED_QUERIES);
if (obj == null)
{
Criteria crit = new Criteria(3);
crit.add(QueryPeer.APPROVED, 0)
.add(QueryPeer.DELETED, 0)
.add(QueryPeer.MODULE_ID, getModuleId());
queries = QueryPeer.doSelect(crit);
ScarabCache.put(queries, this, GET_UNAPPROVED_QUERIES);
}
else
{
queries = (List)obj;
}
return queries;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public List getUnapprovedTemplates() throws TorqueException
{
List templates = null;
Object obj = ScarabCache.get(this, GET_UNAPPROVED_TEMPLATES);
if (obj == null)
{
Criteria crit = new Criteria(3);
crit.add(IssueTemplateInfoPeer.APPROVED, 0)
.addJoin(IssuePeer.ISSUE_ID, IssueTemplateInfoPeer.ISSUE_ID)
.add(IssuePeer.DELETED, 0)
.add(IssuePeer.MOVED, 0)
.add(IssuePeer.MODULE_ID, getModuleId());
templates = IssuePeer.doSelect(crit);
ScarabCache.put(templates, this, GET_UNAPPROVED_TEMPLATES);
}
else
{
templates = (List)obj;
}
return templates;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
protected void setInitialAttributesAndIssueTypes()
throws TorqueException, DataSetException, ScarabException
{
isInitializing = true;
ValidationException ve = null;
try
{
// Add defaults for issue types and attributes
// from parent module
final Module parentModule = ModuleManager.getInstance(getParentId());
if(parentModule != null && parentModule.getModuleId().intValue() != 0){
inheritFromParent(parentModule); //don't inherit anything from global data/module
}
final List defaultIssueTypes = IssueTypePeer.getDefaultIssueTypes();
for (int i=0; i< defaultIssueTypes.size(); i++)
{
final IssueType defaultIssueType = (IssueType)defaultIssueTypes.get(i);
if (!includesIssueType(defaultIssueType))
{
try
{
addIssueType(defaultIssueType);
}
catch (ValidationException e)
{
// if one issue type is bad, continue with the rest, if
// more than one bad issue type is found, stop.
if (ve == null)
{
ve = e;
}
else
{
ve = new ValidationException(
L10NKeySet.ExceptionMultipleProblems,
ve.getMessage(),
e);//WORK: what about the stack trace ?
isInitializing = false;
throw ve;
}
}
}
}
}
finally
{
isInitializing = false;
}
if (ve != null)
{
throw ve;
}
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
protected void inheritFromParent(final Module parentModule)
throws TorqueException, ScarabException
{
final Integer newModuleId = getModuleId();
AttributeGroup ag1;
AttributeGroup ag2;
RModuleAttribute rma1 = null;
RModuleAttribute rma2 = null;
//save RModuleAttributes for template types.
final List templateTypes = parentModule.getTemplateTypes();
for (int i=0; i<templateTypes.size(); i++)
{
final IssueType it = (IssueType)templateTypes.get(i);
final List rmas = parentModule.getRModuleAttributes(it);
for (int j=0; j<rmas.size(); j++)
{
rma1 = (RModuleAttribute)rmas.get(j);
rma2 = rma1.copy();
rma2.setModuleId(newModuleId);
rma2.setAttributeId(rma1.getAttributeId());
rma2.setIssueTypeId(rma1.getIssueTypeId());
getLog().debug("[ASM] Saving rma for new template type: " +
rma2.getModuleId()
+ "-" + rma2.getIssueTypeId() + "-" +
rma2.getAttributeId());
rma2.save();
}
}
// set module-issue type mappings
final List rmits = parentModule.getRModuleIssueTypes();
for (int i=0; i<rmits.size(); i++)
{
final RModuleIssueType rmit1 = (RModuleIssueType)rmits.get(i);
final RModuleIssueType rmit2 = rmit1.copy();
rmit2.setModuleId(newModuleId);
rmit2.save();
final IssueType issueType = rmit1.getIssueType();
// set attribute group defaults
final List attributeGroups = issueType
.getAttributeGroups(parentModule, true);
for (int j=0; j<attributeGroups.size(); j++)
{
ag1 = (AttributeGroup)attributeGroups.get(j);
ag2 = ag1.copy();
ag2.setModuleId(newModuleId);
ag2.getRAttributeAttributeGroups().clear(); // are saved later
ag2.save();
final List attributes = ag1.getAttributes();
for (int k=0; k<attributes.size(); k++)
{
final Attribute attribute = (Attribute)attributes.get(k);
// set attribute-attribute group defaults
final RAttributeAttributeGroup raag1 = ag1
.getRAttributeAttributeGroup(attribute);
final RAttributeAttributeGroup raag2 = raag1.copy();
raag2.setGroupId(ag2.getAttributeGroupId());
raag2.setAttributeId(raag1.getAttributeId());
raag2.setOrder(raag1.getOrder());
raag2.save();
}
}
// set module-attribute defaults
final List rmas = parentModule.getRModuleAttributes(issueType);
if (rmas != null && rmas.size() >0)
{
for (int j=0; j<rmas.size(); j++)
{
rma1 = (RModuleAttribute)rmas.get(j);
rma2 = rma1.copy();
rma2.setModuleId(newModuleId);
rma2.setAttributeId(rma1.getAttributeId());
rma2.setIssueTypeId(rma1.getIssueTypeId());
rma2.save();
// set module-option mappings
final Attribute attribute = rma1.getAttribute();
if (attribute.isOptionAttribute())
{
final List rmos = parentModule.getRModuleOptions(attribute,
issueType);
if (rmos != null && rmos.size() > 0)
{
for (int m=0; m<rmos.size(); m++)
{
final RModuleOption rmo1 = (RModuleOption)rmos.get(m);
final RModuleOption rmo2 = rmo1.copy();
rmo2.setOptionId(rmo1.getOptionId());
rmo2.setModuleId(newModuleId);
rmo2.setIssueTypeId(issueType.getIssueTypeId());
rmo2.save();
// Save module-option mappings for template types
final RModuleOption rmo3 = rmo1.copy();
rmo3.setOptionId(rmo1.getOptionId());
rmo3.setModuleId(newModuleId);
rmo3.setIssueTypeId(issueType.getTemplateId());
rmo3.save();
}
}
}
}
}
}
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public boolean isInitializing()
throws TorqueException
{
return isInitializing;
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public String getIssueRegexString()
throws TorqueException
{
// regex = /(issue|bug)\s+#?\d+/i
List rmitsList = getRModuleIssueTypes();
StringBuffer regex = new StringBuffer(30 + 10 * rmitsList.size());
regex.append(REGEX_PREFIX);
Iterator rmits = rmitsList.iterator();
while (rmits.hasNext())
{
regex.append('|')
.append(((RModuleIssueType)rmits.next()).getDisplayName());
}
regex.append(REGEX_SUFFIX);
return regex.toString();
}
// in java/org/tigris/scarab/om/AbstractScarabModule.java
public REProgram getIssueRegex()
throws TorqueException
{
String regex = getIssueRegexString();
RECompiler rec = new RECompiler();
REProgram rep = null;
try
{
rep = rec.compile(regex);
}
catch (RESyntaxException e)
{
getLog().error("Could not compile regex: " + regex, e);
try
{
rep = rec.compile(REGEX_PREFIX + REGEX_SUFFIX);
}
catch (RESyntaxException ee)
{
// this should not happen, but it might when we localize
getLog().error("Could not compile standard regex", ee);
try
{
rep = rec.compile("[:alpha:]+\\d+");
}
catch (RESyntaxException eee)
{
// this will never happen, but log it, just in case
getLog().error("Could not compile simple id regex", eee);
}
}
}
// FIXME: we should cache the above result
return rep;
}
// in java/org/tigris/scarab/om/Attribute.java
public static Attribute getInstance(int id)
throws TorqueException
{
return getInstance(new Integer(id));
}
// in java/org/tigris/scarab/om/Attribute.java
public static Attribute getInstance(Integer id)
throws TorqueException
{
return AttributeManager.getInstance(id);
}
// in java/org/tigris/scarab/om/Attribute.java
public static Attribute getInstance(final String attributeName)
throws TorqueException
{
Attribute result = null;
// TODO Should attributes even be cached by name? What if the name is changed?
Object obj = ScarabCache.get(ATTRIBUTE, GET_INSTANCE, attributeName.toLowerCase());
if (obj == null)
{
final Criteria crit = new Criteria();
crit.add (AttributePeer.ATTRIBUTE_NAME, attributeName);
crit.setIgnoreCase(true);
final List attributes = AttributePeer.doSelect(crit);
if (attributes.size() > 0)
{
result = (Attribute) attributes.get(0);
ScarabCache.put(result, ATTRIBUTE, GET_INSTANCE, attributeName.toLowerCase());
}
}
else
{
result = (Attribute)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Attribute.java
public static boolean checkForDuplicate(String attributeName)
throws TorqueException
{
return (getInstance(attributeName) != null);
}
// in java/org/tigris/scarab/om/Attribute.java
public static boolean checkForDuplicate(String attributeName,
Attribute attribute)
throws TorqueException
{
return (checkForDuplicate(attributeName) &&
!attributeName.equals(attribute.getName()));
}
// in java/org/tigris/scarab/om/Attribute.java
public String getCreatedUserName() throws TorqueException
{
final Integer userId = getCreatedBy();
String userName = null;
if (userId == null || userId.intValue() == 0)
{
userName = DEFAULT.getMessage();
}
else
{
final ScarabUser su = ScarabUserManager
.getInstance(SimpleKey.keyFor(userId));
userName = su.getName();
}
return userName;
}
// in java/org/tigris/scarab/om/Attribute.java
public static List getAllAttributeTypes()
throws TorqueException
{
List result = null;
Object obj = ScarabCache.get(ATTRIBUTE, GET_ALL_ATTRIBUTE_TYPES);
if (obj == null)
{
result = AttributeTypePeer.doSelect(new Criteria());
ScarabCache.put(result, ATTRIBUTE, GET_ALL_ATTRIBUTE_TYPES);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Attribute.java
public List getCompatibleAttributeTypes()
throws TorqueException, DataSetException
{
List result = null;
final Object obj = ScarabCache.get(this, GET_COMPATIBLE_ATTRIBUTE_TYPES);
if (obj == null)
{
boolean inUse = !isNew();
if (inUse)
{
// check to see if attribute really has been used
final Criteria crit = new Criteria();
crit.add(AttributeValuePeer.ATTRIBUTE_ID, getAttributeId());
inUse = AttributeValuePeer.count(crit) > 0;
}
if (inUse)
{
if (isTextAttribute())
{
final Criteria crit = new Criteria();
crit.addIn(AttributeTypePeer.ATTRIBUTE_TYPE_ID, AttributeTypePeer.TEXT_PKS);
result = AttributeTypePeer.doSelect(crit);
}
else if (this.isOptionAttribute())
{
final Criteria crit = new Criteria();
crit.addIn(AttributeTypePeer.ATTRIBUTE_TYPE_ID, AttributeTypePeer.OPTION_PKS);
result = AttributeTypePeer.doSelect(crit);
}
else
{
result = Collections.EMPTY_LIST;
}
}
else
{
result = getAllAttributeTypes();
}
ScarabCache.put(result, this, GET_COMPATIBLE_ATTRIBUTE_TYPES);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Attribute.java
public AttributeType getAttributeType()
throws TorqueException
{
AttributeType result = null;
Object obj = ScarabCache.get(this, GET_ATTRIBUTE_TYPE);
if (obj == null)
{
result = super.getAttributeType();
ScarabCache.put(result, this, GET_ATTRIBUTE_TYPE);
}
else
{
result = (AttributeType)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Attribute.java
public static List getAllAttributes()
throws TorqueException
{
List result = null;
Object obj = ScarabCache.get(ATTRIBUTE, GET_ALL_ATTRIBUTES);
if (obj == null)
{
result = AttributePeer.doSelect(new Criteria());
ScarabCache.put(result, ATTRIBUTE, GET_ALL_ATTRIBUTES);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Attribute.java
public boolean isOptionAttribute()
throws TorqueException
{
if (getTypeId() != null)
{
return getAttributeType().getAttributeClass().getName()
.equals(SELECT_ONE);
}
return false;
}
// in java/org/tigris/scarab/om/Attribute.java
public boolean isUserAttribute()
throws TorqueException
{
if (getTypeId() != null)
{
return getAttributeType().getAttributeClass().getName()
.equals(USER_ATTRIBUTE);
}
return false;
}
// in java/org/tigris/scarab/om/Attribute.java
public boolean isTextAttribute()
throws TorqueException
{
boolean isText = false;
if (getTypeId() != null)
{
for (int i=0; i<TEXT_TYPES.length && !isText; i++)
{
isText = TEXT_TYPES[i].equals(getAttributeType().getName());
}
}
return isText;
}
// in java/org/tigris/scarab/om/Attribute.java
public boolean isIntegerAttribute()
throws TorqueException
{
return getTypeId() != null
&& INTEGER_ATTRIBUTE.equals(getAttributeType().getName());
}
// in java/org/tigris/scarab/om/Attribute.java
public boolean isDateAttribute()
throws TorqueException
{
boolean isDate = false;
if(getTypeId() != null)
{
isDate = "date".equals(getAttributeType().getName());
}
return isDate;
}
// in java/org/tigris/scarab/om/Attribute.java
public AttributeOption getAttributeOption(Integer pk)
throws TorqueException
{
if (optionsMap == null)
{
buildOptionsMap();
}
return (AttributeOption)optionsMap.get(pk);
}
// in java/org/tigris/scarab/om/Attribute.java
public AttributeOption getAttributeOption(String optionID)
throws TorqueException
{
if (optionID == null || optionID.length() == 0)
{
throw new TorqueException("optionId is empty"); //EXCEPTION
}
return getAttributeOption(new Integer(optionID));
}
// in java/org/tigris/scarab/om/Attribute.java
private List getAllAttributeOptions()
throws TorqueException
{
List result = null;
Object obj = ScarabCache.get(this, GET_ALL_ATTRIBUTE_OPTIONS);
if (obj == null)
{
Criteria crit = new Criteria();
crit.addJoin(AttributeOptionPeer.OPTION_ID,
ROptionOptionPeer.OPTION2_ID);
crit.add(AttributeOptionPeer.ATTRIBUTE_ID, this.getAttributeId());
crit.addAscendingOrderByColumn(ROptionOptionPeer.PREFERRED_ORDER);
result = AttributeOptionPeer.doSelect(crit);
ScarabCache.put(result, this, GET_ALL_ATTRIBUTE_OPTIONS);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Attribute.java
public List getParentChildAttributeOptions()
throws TorqueException
{
if (parentChildAttributeOptions == null)
{
List rooList = getOrderedROptionOptionList();
List aoList = getOrderedAttributeOptionList();
parentChildAttributeOptions = new ArrayList(rooList.size());
for (int i=0; i<rooList.size();i++)
{
ROptionOption roo = (ROptionOption)rooList.get(i);
AttributeOption ao = (AttributeOption)aoList.get(i);
ParentChildAttributeOption pcao = ParentChildAttributeOption
.getInstance(roo.getOption1Id(), roo.getOption2Id());
pcao.setParentId(roo.getOption1Id());
pcao.setOptionId(roo.getOption2Id());
pcao.setPreferredOrder(roo.getPreferredOrder());
pcao.setWeight(roo.getWeight());
pcao.setName(ao.getName());
pcao.setDeleted(ao.getDeleted());
pcao.setAttributeId(this.getAttributeId());
pcao.setStyle(ao.getStyle());
parentChildAttributeOptions.add(pcao);
}
}
return parentChildAttributeOptions;
}
// in java/org/tigris/scarab/om/Attribute.java
public List getOrderedROptionOptionList()
throws TorqueException
{
List result = null;
Object obj = ScarabCache.get(this, GET_ORDERED_ROPTIONOPTION_LIST);
if (obj == null)
{
if (orderedROptionOptionList == null)
{
Criteria crit = new Criteria();
crit.addJoin(AttributeOptionPeer.OPTION_ID,
ROptionOptionPeer.OPTION2_ID);
crit.add(AttributeOptionPeer.ATTRIBUTE_ID, getAttributeId());
crit.addAscendingOrderByColumn(
ROptionOptionPeer.PREFERRED_ORDER);
orderedROptionOptionList = ROptionOptionPeer.doSelect(crit);
}
result = orderedROptionOptionList;
ScarabCache.put(result, this, GET_ORDERED_ROPTIONOPTION_LIST);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Attribute.java
public List getOrderedAttributeOptionList()
throws TorqueException
{
if (orderedAttributeOptionList == null)
{
Criteria crit = new Criteria();
crit.addJoin(AttributeOptionPeer.OPTION_ID, ROptionOptionPeer.OPTION2_ID);
crit.add(AttributeOptionPeer.ATTRIBUTE_ID, this.getAttributeId());
crit.addAscendingOrderByColumn(ROptionOptionPeer.PREFERRED_ORDER);
orderedAttributeOptionList = AttributeOptionPeer.doSelect(crit);
}
return orderedAttributeOptionList;
}
// in java/org/tigris/scarab/om/Attribute.java
public List getAttributeOptions(boolean includeDeleted)
throws TorqueException
{
List allOptions = getAllAttributeOptions();
List nonDeleted = new ArrayList(allOptions.size());
if (includeDeleted)
{
return allOptions;
}
else
{
for (int i=0; i<allOptions.size(); i++)
{
AttributeOption option = (AttributeOption)allOptions.get(i);
if (!option.getDeleted())
{
nonDeleted.add(option);
}
}
return nonDeleted;
}
}
// in java/org/tigris/scarab/om/Attribute.java
public synchronized void buildOptionsMap()
throws TorqueException
{
if (getAttributeType().getAttributeClass().getName()
.equals(SELECT_ONE))
{
// synchronized method due to getattributeOptionsWithDeleted, this needs
// further investigation !FIXME!
attributeOptionsWithDeleted = this.getAllAttributeOptions();
optionsMap = new HashMap((int)(1.25*attributeOptionsWithDeleted.size()+1));
attributeOptionsWithoutDeleted = new ArrayList(attributeOptionsWithDeleted.size());
for (int i=0; i<attributeOptionsWithDeleted.size(); i++)
{
AttributeOption option = (AttributeOption)attributeOptionsWithDeleted.get(i);
optionsMap.put(option.getOptionId(), option);
if (!option.getDeleted())
{
attributeOptionsWithoutDeleted.add(attributeOptionsWithDeleted.get(i));
}
}
}
}
// in java/org/tigris/scarab/om/Attribute.java
public List getActivitys() throws TorqueException
{
return null;
}
// in java/org/tigris/scarab/om/Attribute.java
public Attribute copyAttribute(ScarabUser user)
throws TorqueException
{
Attribute newAttribute = new Attribute();
newAttribute.setName(getName() + " (copy)");
newAttribute.setDescription(getDescription());
newAttribute.setStyle(getStyle());
newAttribute.setFieldSize(getFieldSize());
newAttribute.setFormat(getFormat());
newAttribute.setHint(getHint());
newAttribute.setTypeId(getTypeId());
newAttribute.setPermission(getPermission());
newAttribute.setRequiredOptionId(getRequiredOptionId());
newAttribute.setConditionsArray(getConditionsArray(), getConditionOperator());
newAttribute.setAction(getAction());
newAttribute.setCreatedBy(user.getUserId());
newAttribute.setCreatedDate(new Date());
newAttribute.setDeleted(getDeleted());
newAttribute.setMultiValue(getMultiValue());
newAttribute.save();
List attributeOptions = getAttributeOptions();
for (int i=0;i<attributeOptions.size();i++)
{
AttributeOption option = (AttributeOption)attributeOptions.get(i);
AttributeOption newOption = new AttributeOption();
newOption.setOptionId(option.getOptionId());
newOption.setAttributeId(newAttribute.getAttributeId());
newOption.setName(option.getName());
newOption.setDeleted(option.getDeleted());
newOption.save();
// Copy options's record in R_OPTION_OPTION table
List roos = option.getROptionOptionsRelatedByOption2Id();
for (int j=0;j<roos.size();j++)
{
ROptionOption roo = (ROptionOption)roos.get(j);
ROptionOption newRoo = new ROptionOption();
newRoo.setOption2Id(newOption.getOptionId());
newRoo.setOption1Id(roo.getOption1Id());
newRoo.setRelationshipId(roo.getRelationshipId());
newRoo.setWeight(roo.getWeight());
newRoo.setPreferredOrder(roo.getPreferredOrder());
newRoo.save();
}
}
return newAttribute;
}
// in java/org/tigris/scarab/om/Attribute.java
public boolean hasModuleMappings()
throws TorqueException, DataSetException
{
return hasMapping((Module) null, (IssueType) null);
}
// in java/org/tigris/scarab/om/Attribute.java
public boolean hasMapping(final Module module, final IssueType issueType)
throws TorqueException, DataSetException
{
final Criteria crit = new Criteria();
crit.add(RModuleAttributePeer.ATTRIBUTE_ID,
getAttributeId());
if (module != null)
{
crit.add(RModuleAttributePeer.MODULE_ID,
module.getModuleId());
}
if (issueType != null)
{
crit.add(RModuleAttributePeer.ISSUE_TYPE_ID,
issueType.getIssueTypeId());
}
crit.addSelectColumn("count(" + RModuleAttributePeer.ATTRIBUTE_ID + ")");
return ((Record)IssuePeer.doSelectVillageRecords(crit).get(0))
.getValue(1).asInt() > 0;
}
// in java/org/tigris/scarab/om/Attribute.java
public boolean hasGlobalIssueTypeMappings()
throws TorqueException, DataSetException
{
return hasGlobalMapping((IssueType) null);
}
// in java/org/tigris/scarab/om/Attribute.java
public boolean hasGlobalMapping(IssueType issueType)
throws TorqueException, DataSetException
{
final Criteria crit = new Criteria();
crit.add(RIssueTypeAttributePeer.ATTRIBUTE_ID,
getAttributeId());
if (issueType != null)
{
crit.add(RIssueTypeAttributePeer.ISSUE_TYPE_ID,
issueType.getIssueTypeId());
}
crit.addSelectColumn("count(" + RIssueTypeAttributePeer.ATTRIBUTE_ID
+ ')');
return ((Record)IssuePeer.doSelectVillageRecords(crit).get(0))
.getValue(1).asInt() > 0;
}
// in java/org/tigris/scarab/om/Attribute.java
public void deleteModuleMappings()
throws TorqueException, ScarabException
{
Criteria crit = new Criteria();
crit.add(RAttributeAttributeGroupPeer.ATTRIBUTE_ID,
getAttributeId());
crit.addJoin(RAttributeAttributeGroupPeer.GROUP_ID,
AttributeGroupPeer.ATTRIBUTE_GROUP_ID);
crit.add(AttributeGroupPeer.MODULE_ID, (Object)null, Criteria.NOT_EQUAL);
final List raags = RAttributeAttributeGroupPeer.doSelect(crit);
for (Iterator i = raags.iterator(); i.hasNext();)
{
((RAttributeAttributeGroup)i.next()).delete();
}
crit = new Criteria();
crit.add(RModuleAttributePeer.ATTRIBUTE_ID,
getAttributeId());
final List rmas = RModuleAttributePeer.doSelect(crit);
for (int i=0; i<rmas.size(); i++)
{
final RModuleAttribute rma = (RModuleAttribute)rmas.get(i);
rma.delete(true);
}
ScarabCache.clear();
}
// in java/org/tigris/scarab/om/Attribute.java
public void deleteIssueTypeMappings()
throws TorqueException
{
Criteria crit = new Criteria();
crit.add(RAttributeAttributeGroupPeer.ATTRIBUTE_ID,
getAttributeId());
crit.addJoin(RAttributeAttributeGroupPeer.GROUP_ID,
AttributeGroupPeer.ATTRIBUTE_GROUP_ID);
crit.add(AttributeGroupPeer.MODULE_ID, null);
List raags = RAttributeAttributeGroupPeer.doSelect(crit);
for (Iterator i = raags.iterator(); i.hasNext();)
{
((RAttributeAttributeGroup)i.next()).delete();
}
crit = new Criteria();
crit.add(RIssueTypeAttributePeer.ATTRIBUTE_ID,
getAttributeId());
List rias = RIssueTypeAttributePeer.doSelect(crit);
for (Iterator i = rias.iterator(); i.hasNext();)
{
((RIssueTypeAttribute)i.next()).delete();
}
ScarabCache.clear();
}
// in java/org/tigris/scarab/om/Attribute.java
private List getAssociatedIssueTypes()
throws TorqueException
{
Criteria crit = new Criteria();
crit.add(RIssueTypeAttributePeer.ATTRIBUTE_ID,
getAttributeId());
crit.addJoin(RIssueTypeAttributePeer.ISSUE_TYPE_ID,
IssueTypePeer.ISSUE_TYPE_ID);
List issueTypeList = IssueTypePeer.doSelect(crit);
return issueTypeList;
}
// in java/org/tigris/scarab/om/Attribute.java
public boolean isSystemDefined()
throws TorqueException
{
boolean systemDefined = false;
List issueTypeList = getAssociatedIssueTypes();
for (Iterator i = issueTypeList.iterator(); i.hasNext();)
{
if (((IssueType)i.next()).isSystemDefined())
{
systemDefined = true;
break;
}
}
return systemDefined;
}
// in java/org/tigris/scarab/om/Attribute.java
public List<Condition> getConditions() throws TorqueException
{
if (collConditions == null)
{
Criteria crit = new Criteria();
crit.add(ConditionPeer.ATTRIBUTE_ID, this.getAttributeId());
crit.add(ConditionPeer.MODULE_ID, null);
crit.add(ConditionPeer.TRANSITION_ID, null);
crit.add(ConditionPeer.ISSUE_TYPE_ID, null);
collConditions = getConditions(crit);
}
return collConditions;
}
// in java/org/tigris/scarab/om/Attribute.java
public void setConditionsArray(Integer aOptionId[], Integer operator) throws TorqueException
{
Criteria crit = new Criteria();
crit.add(ConditionPeer.ATTRIBUTE_ID, this.getAttributeId());
crit.add(ConditionPeer.OPERATOR, this.getConditionOperator());
crit.add(ConditionPeer.MODULE_ID, null);
crit.add(ConditionPeer.ISSUE_TYPE_ID, null);
crit.add(ConditionPeer.TRANSITION_ID, null);
ConditionPeer.doDelete(crit);
this.save();
this.getConditions().clear();
ConditionManager.clear();
if (aOptionId != null)
for (int i=0; i<aOptionId.length; i++)
{
if (aOptionId[i].intValue() != 0)
{
Condition cond = new Condition();
cond.setAttributeId(this.getAttributeId());
cond.setOptionId(aOptionId[i]);
cond.setModuleId(null);
cond.setIssueTypeId(null);
cond.setTransitionId(null);
cond.setUserId(null);
cond.setOperator(operator);
this.addCondition(cond);
cond.save();
}
}
}
// in java/org/tigris/scarab/om/Attribute.java
public boolean isRequiredIf(Integer optionID) throws TorqueException
{
Condition cond = new Condition();
cond.setAttributeId(this.getAttributeId());
cond.setOptionId(optionID);
cond.setModuleId(null);
cond.setIssueTypeId(null);
cond.setTransitionId(null);
return this.getConditions().contains(cond);
}
// in java/org/tigris/scarab/om/ReportManager.java
public List getNotDeletedModuleReports(Module module)
throws TorqueException
{
Criteria crit=new Criteria()
.add(ReportPeer.DELETED,false)
.add(ReportPeer.MODULE_ID,module.getModuleId())
.add(ReportPeer.SCOPE_ID,Scope.MODULE__PK);
List reports=ReportPeer.doSelect(crit);
return reports;
}
// in java/org/tigris/scarab/om/ReportManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap.get(ReportPeer.REPORT_ID);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/ActivitySetTypeManager.java
public static ActivitySetType getInstance(final String activitySetTypeName)
throws TorqueException,ScarabException
{
ActivitySetType ttype = null;
Object obj = ScarabCache.get(TRANSACTION_TYPE, GET_INSTANCE,
activitySetTypeName);
if (obj == null)
{
final Criteria crit = new Criteria();
crit.add(ActivitySetTypePeer.NAME, activitySetTypeName);
final List activitySetTypes = ActivitySetTypePeer.doSelect(crit);
if (activitySetTypes.size() < 1)
{
throw new ScarabException(
L10NKeySet.ExceptionActivitySetTypenameNotFound,
activitySetTypeName);
}
if (activitySetTypes.size() > 1)
{
throw new ScarabException(
L10NKeySet.ExceptionActivitySetDuplicateTypename,
activitySetTypeName);
}
ttype = (ActivitySetType)activitySetTypes.get(0);
ScarabCache.put(ttype, "ActivitySetType", "getInstance",
activitySetTypeName);
}
else
{
ttype = (ActivitySetType)obj;
}
return ttype;
}
// in java/org/tigris/scarab/om/RModuleOptionManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap.get(RModuleOptionPeer.MODULE_ID);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/RModuleOptionManager.java
public static final RModuleOption getInstance(Integer moduleId,
Integer issueTypeId, Integer optionId)
throws TorqueException
{
SimpleKey[] keys = {
new NumberKey(moduleId.toString()),
new NumberKey(issueTypeId.toString()),
new NumberKey(optionId.toString())
};
return getInstance(new ComboKey(keys));
}
// in java/org/tigris/scarab/om/RModuleOptionManager.java
public static final RModuleOption getInstance(Module module,
IssueType issueType, AttributeOption option)
throws TorqueException
{
SimpleKey[] keys = {
SimpleKey.keyFor(module.getModuleId()),
SimpleKey.keyFor(issueType.getIssueTypeId()),
SimpleKey.keyFor(option.getOptionId())
};
return getInstance(new ComboKey(keys));
}
// in java/org/tigris/scarab/om/TransitionPeer.java
public static void doDelete(Transition tran) throws TorqueException
{
Criteria crit = new Criteria();
crit.add(ConditionPeer.TRANSITION_ID, tran.getTransitionId());
ConditionPeer.doDelete(crit);
BaseTransitionPeer.doDelete(tran);
}
// in java/org/tigris/scarab/om/NotificationRulePeer.java
static public List<NotificationRule> getCustomization(Object moduleId, Object userId, Object activityType) throws TorqueException
{
List<NotificationRule> entries = null;
Criteria crit = new Criteria();
crit.add(MODULE_ID, moduleId, Criteria.EQUAL);
crit.add(USER_ID, userId, Criteria.EQUAL);
crit.add(ACTIVITY_TYPE, activityType, Criteria.EQUAL);
try {
entries = (List<NotificationRule>)doSelect(crit);
} catch (TorqueException e) {
log.error("getPendingNotifications(): " + e);
}
/*
if(entries.size()==0)
{
NotificationRule rule =
NotificationRule.createDefaultRule(
(Integer)moduleId,
(Integer)userId,
NotificationManagerFactory.getInstance().getManagerId(),
ActivityType.getActivityType((String)activityType));
}
*/
return entries;
}
// in java/org/tigris/scarab/om/NotificationRulePeer.java
static public Map<String,List<NotificationRule>> getCustomization(Object moduleId, Object userId) throws TorqueException
{
Map<String,List<NotificationRule>> entries = new Hashtable<String,List<NotificationRule>>();
Set<String> codes = (Set<String>)ActivityType.getActivityTypeCodes();
Iterator<String> iter = codes.iterator();
while(iter.hasNext())
{
String code = (String)iter.next();
List<NotificationRule> items = getCustomization(moduleId, userId, code);
entries.put(code,items);
}
return entries;
}
// in java/org/tigris/scarab/om/NotificationRulePeer.java
static public List<NotificationRule> getNotificationRules(ScarabUser user, Module module) throws TorqueException
{
List<NotificationRule> entries = new ArrayList<NotificationRule>();
Set<String> codes = (Set<String>)ActivityType.getActivityTypeCodes();
Iterator<String> iter = codes.iterator();
Integer moduleId = module.getModuleId();
Integer userId = user.getUserId();
while(iter.hasNext())
{
String code = (String)iter.next();
List<NotificationRule> items = getCustomization(moduleId, userId, code);
if(items != null && items.size()>0)
entries.add(items.get(0));
}
return entries;
}
// in java/org/tigris/scarab/om/NotificationRulePeer.java
public static void saveConditions(ScarabUser user, Module module, Integer[] aOptionId, Integer operator) throws TorqueException
{
deleteConditions(user, module);
ConditionManager.clear();
if (aOptionId != null)
for (int i=0; i<aOptionId.length; i++)
{
if (aOptionId[i].intValue() != 0)
{
Condition cond = new Condition();
cond.setAttributeId(null);
cond.setOptionId(aOptionId[i]);
cond.setModuleId(module.getModuleId());
cond.setIssueTypeId(null);
cond.setTransitionId(null);
cond.setUserId(user.getUserId());
cond.setOperator(operator);
cond.save();
}
}
}
// in java/org/tigris/scarab/om/NotificationRulePeer.java
public static List<Condition> getConditions(ScarabUser user, Module module) throws TorqueException
{
List<Condition> result = null;
Criteria crit = new Criteria();
crit.add(ConditionPeer.USER_ID, user.getUserId());
crit.add(ConditionPeer.MODULE_ID, module.getModuleId());
result = (List<Condition>)ConditionPeer.doSelect(crit);
return result;
}
// in java/org/tigris/scarab/om/NotificationRulePeer.java
public static Notification getEmptyNotificationFor(ScarabUser user, Module module) throws TorqueException
{
Notification notification = null;
return notification;
}
// in java/org/tigris/scarab/om/NotificationRulePeer.java
public static void deleteConditions(ScarabUser user, Module module) throws TorqueException
{
Criteria crit = new Criteria();
crit.add(ConditionPeer.ATTRIBUTE_ID, null);
crit.add(ConditionPeer.MODULE_ID, module.getModuleId());
crit.add(ConditionPeer.ISSUE_TYPE_ID, null);
crit.add(ConditionPeer.TRANSITION_ID, null);
crit.add(ConditionPeer.USER_ID, user.getUserId());
ConditionPeer.doDelete(crit);
}
// in java/org/tigris/scarab/om/Issue.java
public static Issue getNewInstance(Module module,
IssueType issueType)
throws TorqueException
{
Issue issue = new Issue(module, issueType);
return issue;
}
// in java/org/tigris/scarab/om/Issue.java
public String getUniqueId()
throws TorqueException
{
if (getIdPrefix() == null)
{
setIdPrefix(getModule().getCode());
}
return getIdPrefix() + getIdCount();
}
// in java/org/tigris/scarab/om/Issue.java
public String getFederatedId()
throws TorqueException
{
if (getIdDomain() != null)
{
return getIdDomain() + '-' + getUniqueId();
}
return getUniqueId();
}
// in java/org/tigris/scarab/om/Issue.java
public static List parseIssueList(final Module module, final String theList)
throws TorqueException, DataSetException
{
final String[] issues = StringUtils.split(theList, ",");
final List results = new ArrayList();
for (int i = 0; i < issues.length; i++)
{
if (issues[i].indexOf('*') != -1)
{
// Probably better to use more Torque here, but this
// is definitely going to be faster and more
// efficient.
final String sql = "SELECT CONCAT(" + IssuePeer.ID_PREFIX + ',' +
IssuePeer.ID_COUNT + ") FROM " + IssuePeer.TABLE_NAME +
" WHERE " + IssuePeer.ID_PREFIX + " = '" +
module.getCode() + '\'';
final List records = BasePeer.executeQuery(sql);
for (Iterator j = records.iterator(); j.hasNext();)
{
final Record rec = (Record)j.next();
results.add(rec.getValue(1).asString());
}
}
// check for a -
else if (issues[i].indexOf('-') == -1)
{
// Make sure user is not trying to access issues from another
// module.
final FederatedId fid = createFederatedId(module, issues[i]);
if (!fid.getPrefix().equalsIgnoreCase(module.getCode()))
{
final String[] args = { fid.getPrefix(), module.getCode() };
throw new TorqueException(Localization.format
(ScarabConstants.DEFAULT_BUNDLE_NAME,
module.getLocale(),
"IssueIDPrefixNotForModule", args)); //EXCEPTION
}
results.add(issues[i]);
}
else
{
final String[] issue = StringUtils.split(issues[i], "-");
if (issue.length != 2)
{
throw new TorqueException(Localization.format
(ScarabConstants.DEFAULT_BUNDLE_NAME,
module.getLocale(),
"IssueIDRangeNotValid", issues[i])); //EXCEPTION
}
FederatedId fidStart = createFederatedId(module, issue[0]);
FederatedId fidStop = createFederatedId(module, issue[1]);
if (!fidStart.getPrefix().equalsIgnoreCase(module.getCode()) ||
!fidStop.getPrefix().equalsIgnoreCase(module.getCode()))
{
throw new TorqueException(Localization.format
(ScarabConstants.DEFAULT_BUNDLE_NAME,
module.getLocale(),
"IssueIDPrefixesNotForModule",
module.getCode())); //EXCEPTION
}
else if (!fidStart.getPrefix()
.equalsIgnoreCase(fidStop.getPrefix()))
{
final String[] args = { fidStart.getPrefix(),
fidStop.getPrefix() };
throw new TorqueException(Localization.format
(ScarabConstants.DEFAULT_BUNDLE_NAME,
module.getLocale(),
"IssueIDPrefixesDoNotMatch", args)); //EXCEPTION
}
else if (fidStart.getCount() > fidStop.getCount())
{
FederatedId swap = fidStart;
fidStart = fidStop;
fidStop = swap;
}
for (int j = fidStart.getCount(); j <= fidStop.getCount();j++)
{
results.add(fidStart.getPrefix() + j);
}
}
}
return results;
}
// in java/org/tigris/scarab/om/Issue.java
private static FederatedId createFederatedId(Module module, String id)
throws TorqueException
{
FederatedId fid = null;
try
{
fid = new FederatedId(id.trim());
if (fid.getPrefix() == null || fid.getPrefix().length() == 0)
{
fid.setPrefix(module.getCode());
}
}
catch (Exception e)
{
throw new TorqueException("Invalid federated id: " + id); //EXCEPTION
}
return fid;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet addUrl(final Attachment attachment, final ScarabUser user)
throws TorqueException, ScarabException
{
return addUrl(null, attachment, user);
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet addUrl(ActivitySet activitySet,
final Attachment attachment,
final ScarabUser user)
throws TorqueException, ScarabException
{
attachment.setTextFields(user, this, Attachment.URL__PK);
attachment.save();
activitySet = attachActivitySet(activitySet, user);
// Save activity record
ActivityManager
.createTextActivity(this, activitySet, ActivityType.URL_ADDED, attachment);
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
private Locale getLocale()
throws TorqueException
{
return getModule().getLocale();
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet addComment(final Attachment attachment, final ScarabUser user)
throws TorqueException, ScarabException
{
return addComment(null, attachment, user);
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet addComment(ActivitySet activitySet,
Attachment attachment, ScarabUser user)
throws TorqueException, ScarabException
{
String comment = attachment.getData();
if (comment == null || comment.length() == 0)
{
throw new ScarabException(L10NKeySet.NoDataInComment);
}
activitySet = attachActivitySet(activitySet, user);
// populates the attachment with data to be a comment
attachment = AttachmentManager
.getComment(attachment, this, user);
ActivityManager
.createTextActivity(this, activitySet,
ActivityType.COMMENT_ADDED, attachment);
NotificationManagerFactory.getInstance().addActivityNotification(
ActivityType.COMMENT_ADDED, activitySet, this, user);
index();
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public synchronized void addFile(Attachment attachment,
ScarabUser user)
throws TorqueException
{
attachment.setTypeId(Attachment.FILE__PK);
attachment.setCreatedBy(user.getUserId());
if (unSavedAttachments == null)
{
unSavedAttachments = new ArrayList();
}
unSavedAttachments.add(attachment);
}
// in java/org/tigris/scarab/om/Issue.java
public synchronized List getAttachments()
throws TorqueException
{
if (unSavedAttachments != null &&
unSavedAttachments.size() > 0)
{
return unSavedAttachments;
}
else
{
return super.getAttachments();
}
}
// in java/org/tigris/scarab/om/Issue.java
public synchronized ActivitySet doSaveFileAttachments(final ScarabUser user)
throws TorqueException, ScarabException
{
return doSaveFileAttachments(null, user);
}
// in java/org/tigris/scarab/om/Issue.java
public synchronized ActivitySet doSaveFileAttachments(ActivitySet activitySet,
final ScarabUser user)
throws TorqueException, ScarabException
{
if (unSavedAttachments == null)
{
return activitySet;
}
activitySet = attachActivitySet(activitySet, user);
final Iterator itr = unSavedAttachments.iterator();
while (itr.hasNext())
{
final Attachment attachment = (Attachment)itr.next();
// make sure we set the issue to the newly created issue
attachment.setIssue(this);
attachment.save();
// Save activity record
ActivityManager
.createTextActivity(this, activitySet, ActivityType.ATTACHMENT_CREATED, attachment);
}
// reset the super method so that the query has to hit the database again
// so that all of the information is cleaned up and reset.
super.collAttachments = null;
// we don't need this one anymore either.
this.unSavedAttachments = null;
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public void removeFile(String index)
throws TorqueException
{
int indexInt = Integer.parseInt(index) - 1;
if (indexInt >= 0)
{
if (unSavedAttachments != null && unSavedAttachments.size() > 0)
{
unSavedAttachments.remove(indexInt);
}
else
{
List attachList = getAttachments();
if (attachList != null && attachList.size() > 0)
{
attachList.remove(indexInt);
}
}
}
}
// in java/org/tigris/scarab/om/Issue.java
public void setModule(Module me)
throws TorqueException
{
Integer id = me.getModuleId();
if (id == null)
{
throw new TorqueException("Modules must be saved prior to " +
"being associated with other objects."); //EXCEPTION
}
setModuleId(id);
}
// in java/org/tigris/scarab/om/Issue.java
public Module getModule()
throws TorqueException
{
Module module = null;
Integer id = getModuleId();
if ( id != null )
{
module = ModuleManager.getInstance(id);
}
return module;
}
// in java/org/tigris/scarab/om/Issue.java
public RModuleIssueType getRModuleIssueType()
throws TorqueException
{
RModuleIssueType rmit = null;
Module module = getModule();
IssueType issueType = getIssueType();
if (module != null && issueType != null)
{
rmit = module.getRModuleIssueType(issueType);
}
return rmit;
}
// in java/org/tigris/scarab/om/Issue.java
public LinkedMap getModuleAttributeValuesMap()
throws TorqueException
{
return getModuleAttributeValuesMap(true);
}
// in java/org/tigris/scarab/om/Issue.java
public LinkedMap getModuleAttributeValuesMap(final boolean isActive)
throws TorqueException
{
LinkedMap result = null;
Object obj = getCachedObject(GET_MODULE_ATTRVALUES_MAP, isActive ? Boolean.TRUE : Boolean.FALSE);
if (obj == null)
{
List attributes = null;
Module module = getModule();
IssueType issueType = getIssueType();
if (isActive)
{
attributes = issueType.getActiveAttributes(module);
}
else
{
attributes = module.getAttributes(issueType);
}
Map siaValuesMap = getAttributeValuesMap();
result = new LinkedMap((int)(1.25*attributes.size() + 1));
for (int i=0; i<attributes.size(); i++)
{
String key = ((Attribute)attributes.get(i)).getName().toUpperCase();
if (siaValuesMap.containsKey(key))
{
result.put(key, siaValuesMap.get(key));
}
else
{
Attribute attr = (Attribute)attributes.get(i);
AttributeValue aval = AttributeValue.getNewInstance(attr, this);
addAttributeValue(aval);
result.put(key, aval);
}
}
putCachedObject(result, GET_MODULE_ATTRVALUES_MAP, isActive ? Boolean.TRUE : Boolean.FALSE);
}
else
{
result = (LinkedMap)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public LinkedMap getModuleOptionAttributeValuesMap()
throws TorqueException
{
LinkedMap result = null;
//Object obj = getCachedObject(GET_MODULE_OPTION_ATTRVALUES_MAP);
Object obj = ScarabCache.get(this, GET_MODULE_OPTION_ATTRVALUES_MAP);
if (obj == null)
{
List attributes = null;
Module module = getModule();
IssueType issueType = getIssueType();
attributes = issueType.getActiveAttributes(module);
Map siaValuesMap = getAttributeValuesMap();
result = new LinkedMap((int)(1.25*attributes.size() + 1));
for (int i=0; i<attributes.size(); i++)
{
String key = ((Attribute)attributes.get(i)).getName().toUpperCase();
AttributeValue aval;
if (siaValuesMap.containsKey(key))
{
aval = (AttributeValue)siaValuesMap.get(key);
}
else
{
Attribute attr = (Attribute)attributes.get(i);
aval = AttributeValue.getNewInstance(attr, this);
addAttributeValue(aval);
}
if(aval.getOptionId() != null)
{
result.put(key, aval);
}
}
//putCachedObject(result, GET_MODULE_OPTION_ATTRVALUES_MAP);
ScarabCache.put(result, this, GET_MODULE_OPTION_ATTRVALUES_MAP);
}
else
{
result = (LinkedMap)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public void addAttributeValue(AttributeValue aval)
throws TorqueException
{
List avals = getAttributeValues();
if (!avals.contains(aval))
{
super.addAttributeValue(aval);
}
}
// in java/org/tigris/scarab/om/Issue.java
public AttributeValue getAttributeValue(String attributeName)
throws TorqueException
{
Attribute attribute = Attribute.getInstance(attributeName);
AttributeValue result;
if(attribute == null)
{
result = null;
}
else
{
result = getAttributeValue(attribute);
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public AttributeValue getAttributeValue(int id)
throws TorqueException
{
Attribute attribute = Attribute.getInstance(id);
return getAttributeValue(attribute);
}
// in java/org/tigris/scarab/om/Issue.java
public AttributeValue getAttributeValue(Attribute attribute)
throws TorqueException
{
AttributeValue result = null;
Object obj = ScarabCache.get(this, GET_ATTRVALUE, attribute);
if (obj == null)
{
if (isNew())
{
List avals = getAttributeValues();
if (avals != null)
{
Iterator i = avals.iterator();
while (i.hasNext())
{
AttributeValue tempAval = (AttributeValue)i.next();
if (tempAval.getAttribute().equals(attribute))
{
result = tempAval;
break;
}
}
}
}
else
{
Criteria crit = new Criteria(2)
.add(AttributeValuePeer.ISSUE_ID, getIssueId())
.add(AttributeValuePeer.DELETED, false)
.add(AttributeValuePeer.ATTRIBUTE_ID,
attribute.getAttributeId());
List avals = getAttributeValues(crit);
if (avals.size() > 0)
{
result = (AttributeValue)avals.get(0);
}
if (avals.size() > 1)
{
getLog().error("getAttributeValue(): Error when retrieving attribute values of attribute. Expected 1 and found " + avals.size() + ". List follows: " + avals);
}
}
ScarabCache.put(result, this, GET_ATTRVALUE, attribute);
}
else
{
result = (AttributeValue)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public List getAttributeValues(Integer id)
throws TorqueException
{
Attribute attribute = Attribute.getInstance(id);
return getAttributeValues(attribute);
}
// in java/org/tigris/scarab/om/Issue.java
public List getAttributeValues(final Attribute attribute)
throws TorqueException
{
List aval = (List)IssueManager.getMethodResult().get(this, GET_ATTRVALUES, attribute);
if (aval == null)
{
if (isNew())
{
final List avals = getAttributeValues();
aval = new ArrayList();
if (avals != null)
{
final Iterator i = avals.iterator();
while (i.hasNext())
{
final AttributeValue tempAval = (AttributeValue)i.next();
if (tempAval.getAttribute().equals(attribute))
{
aval.add(tempAval);
}
}
}
}
else
{
final Criteria crit = new Criteria(2)
.add(AttributeValuePeer.DELETED, false)
.add(AttributeValuePeer.ATTRIBUTE_ID,
attribute.getAttributeId());
aval = getAttributeValues(crit);
IssueManager.getMethodResult().put(aval, this, GET_ATTRVALUES, attribute);
}
}
return aval;
}
// in java/org/tigris/scarab/om/Issue.java
public boolean isAttributeValue(AttributeValue attVal)
throws TorqueException
{
boolean isValue = false;
List attValues = getAttributeValues(attVal.getAttribute());
if (attValues.contains(attVal))
{
isValue = true;
}
return isValue;
}
// in java/org/tigris/scarab/om/Issue.java
private AttributeValue getAttributeValueWithValue(Attribute att, String strVal, Integer numVal)
throws TorqueException
{
AttributeValue val = null;
boolean bFound = false;
List attValues = getAttributeValues(att);
for (Iterator it = attValues.iterator(); !bFound && it.hasNext(); )
{
val = (AttributeValue)it.next();
if (strVal != null)
bFound = val.getValue().equals(strVal);
else if (!bFound && numVal != null)
bFound = val.getNumericValue().equals(numVal);
}
return val;
}
// in java/org/tigris/scarab/om/Issue.java
public Map getAttributeValuesMap() throws TorqueException
{
Map result = null;
Object obj = getCachedObject(GET_ATTRIBUTE_VALUES_MAP);
if (obj == null)
{
final Criteria crit = new Criteria(2)
.add(AttributeValuePeer.DELETED, false);
final List siaValues = getAttributeValues(crit);
result = new HashMap((int)(1.25*siaValues.size() + 1));
for (Iterator i = siaValues.iterator(); i.hasNext(); )
{
final AttributeValue att = (AttributeValue) i.next();
result.put(att.getAttribute().getName().toUpperCase(), att);
}
putCachedObject(result, GET_ATTRIBUTE_VALUES_MAP);
}
else
{
result = (Map)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public Map getAllAttributeValuesMap()
throws TorqueException
{
Map moduleAtts = getModuleAttributeValuesMap();
Map issueAtts = getAttributeValuesMap();
Map allValuesMap = new HashMap((int)(1.25*(moduleAtts.size() +
issueAtts.size())+1));
allValuesMap.putAll(moduleAtts);
allValuesMap.putAll(issueAtts);
return allValuesMap;
}
// in java/org/tigris/scarab/om/Issue.java
public boolean containsMinimumAttributeValues()
throws TorqueException
{
List attributes = getIssueType()
.getRequiredAttributes(getModule());
boolean result = true;
LinkedMap avMap = getModuleAttributeValuesMap();
MapIterator i = avMap.mapIterator();
while (i.hasNext())
{
AttributeValue aval = (AttributeValue)avMap.get(i.next());
if (aval.getOptionId() == null && aval.getValue() == null)
{
for (int j=attributes.size()-1; j>=0; j--)
{
if (aval.getAttribute().getPrimaryKey().equals(
((Attribute)attributes.get(j)).getPrimaryKey()))
{
result = false;
break;
}
}
if (!result)
{
break;
}
}
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public List getEligibleUsers(Attribute attribute)
throws TorqueException, ScarabException
{
ScarabUser[] users = getModule().getEligibleUsers(attribute);
// remove those already assigned
List assigneeAVs = getAttributeValues(attribute);
if (users != null && assigneeAVs != null)
{
for (int i=users.length-1; i>=0; i--)
{
for (int j=assigneeAVs.size()-1; j>=0; j--)
{
AttributeValue av = (AttributeValue)assigneeAVs.get(j);
Integer avUserId = av.getUserId();
Integer userUserId = users[i].getUserId();
if ( av != null && avUserId != null &&
userUserId != null &&
avUserId.equals(userUserId))
{
users[i] = null;
break;
}
}
}
}
List eligibleUsers = new ArrayList(users.length);
for (int i=0; i<users.length; i++)
{
if (users[i] != null)
{
eligibleUsers.add(users[i]);
}
}
return eligibleUsers;
}
// in java/org/tigris/scarab/om/Issue.java
protected Set<ScarabUser> getUsersToEmail(String action, Issue issue, Set<ScarabUser> users)
throws TorqueException
{
if (users == null)
{
users = new HashSet<ScarabUser>(1);
}
Module module = getModule();
ScarabUser createdBy = issue.getCreatedBy();
if (createdBy != null && !users.contains(createdBy) &&
AttributePeer.EMAIL_TO.equals(action) &&
createdBy.hasPermission(ScarabSecurity.ISSUE__ENTER, module))
{
users.add(createdBy);
}
Criteria crit = new Criteria()
.add(AttributeValuePeer.ISSUE_ID, issue.getIssueId())
.addJoin(AttributeValuePeer.ATTRIBUTE_ID,
AttributePeer.ATTRIBUTE_ID)
.add(AttributePeer.ACTION, action)
.add(RModuleAttributePeer.MODULE_ID, getModuleId())
.add(RModuleAttributePeer.ISSUE_TYPE_ID, getTypeId())
.add(AttributeValuePeer.DELETED, 0)
.add(RModuleAttributePeer.ACTIVE, true)
.addJoin(RModuleAttributePeer.ATTRIBUTE_ID,
AttributeValuePeer.ATTRIBUTE_ID);
List userAttVals = AttributeValuePeer.doSelect(crit);
for (Iterator i = userAttVals.iterator(); i.hasNext(); )
{
AttributeValue attVal = (AttributeValue) i.next();
try
{
ScarabUser su = ScarabUserManager
.getInstance(attVal.getUserId());
if (!users.contains(su)
&& su.hasPermission(attVal.getAttribute().getPermission(),
module))
{
users.add(su);
}
}
catch (Exception e)
{
throw new TorqueException("Error retrieving users to email"); //EXCEPTION
}
}
return users;
}
// in java/org/tigris/scarab/om/Issue.java
public Set<ScarabUser> getAllUsersToEmail(String action) throws TorqueException
{
Set<ScarabUser> result = null;
Object obj = ScarabCache.get(this, GET_ALL_USERS_TO_EMAIL, action);
if (obj == null)
{
Set<ScarabUser> users = new HashSet<ScarabUser>();
try
{
users = getUsersToEmail(action, this, users);
List children = getChildren();
for (int i=0;i<children.size();i++)
{
Issue depIssue = IssueManager.getInstance
(((Depend) children.get(i)).getObserverId());
users = getUsersToEmail(action, depIssue, users);
}
result = users;
}
catch (Exception e)
{
getLog().error("Issue.getUsersToEmail(): ", e);
throw new TorqueException("Error in retrieving users."); //EXCEPTION
}
ScarabCache.put(result, this, GET_ALL_USERS_TO_EMAIL, action);
}
else
{
result = (Set)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public AttributeValue getUserAttributeValue(final ScarabUser user,
final Attribute attribute)
throws TorqueException
{
AttributeValue result = null;
Object obj = getCachedObject(GET_USER_ATTRIBUTEVALUE,
attribute.getAttributeId(), user.getUserId());
if (obj == null)
{
final Criteria crit = new Criteria()
.add(AttributeValuePeer.ATTRIBUTE_ID, attribute.getAttributeId())
.add(AttributeValuePeer.ISSUE_ID, getIssueId())
.add(AttributeValuePeer.USER_ID, user.getUserId())
.add(AttributeValuePeer.DELETED, 0);
final List resultList = AttributeValuePeer.doSelect(crit);
if (resultList != null && resultList.size() == 1)
{
result = (AttributeValue)resultList.get(0);
}
putCachedObject(result, GET_USER_ATTRIBUTEVALUE,
attribute.getAttributeId(), user.getUserId());
}
else
{
result = (AttributeValue)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public List getUserAttributeValues() throws TorqueException
{
return getUserAttributeValues(null);
}
// in java/org/tigris/scarab/om/Issue.java
public ScarabUser getFirstAssignedTo() throws TorqueException
{
String assignedToAttributeName = Environment.getConfigurationProperty("scarab.common.assignedTo", "assignedTo");
List<AttributeValue> allAssignedUsers = getUserAttributeValues();
Iterator<AttributeValue> iter = allAssignedUsers.iterator();
ScarabUser result = null;
while(iter.hasNext())
{
AttributeValue attval = iter.next();
String attributeName = attval.getAttribute().getName();
if(attributeName.equals(assignedToAttributeName))
{
result = attval.getScarabUser();
break;
}
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public List getUserAttributeValues(final ScarabUser user) throws TorqueException
{
List result = null;
Object obj = null;
obj = getCachedUserAttributeValues(user);
if (obj == null)
{
List attributeList = getModule().getUserAttributes(getIssueType(), true);
List attributeIdList = new ArrayList();
for (int i=0; i<attributeList.size(); i++)
{
Attribute att = (Attribute) attributeList.get(i);
attributeIdList.add(att.getAttributeId());
}
if(!attributeIdList.isEmpty())
{
Criteria crit = new Criteria()
.addIn(AttributeValuePeer.ATTRIBUTE_ID, attributeIdList)
.add(AttributeValuePeer.ISSUE_ID, getIssueId())
.add(AttributeValuePeer.DELETED, 0);
if(user != null)
{
crit.add(AttributeValuePeer.USER_ID, user.getUserId());
}
result = AttributeValuePeer.doSelect(crit);
}
else
{
result = new ArrayList(0);
}
putCachedUserAttributeValues(user, result);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet getInitialActivitySet()
throws TorqueException
{
ActivitySet activitySet = getActivitySetRelatedByCreatedTransId();
if (activitySet == null)
{
Log.get().warn("Creation ActivitySet is null for " + this);
}
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public Date getCreatedDate()
throws TorqueException
{
ActivitySet creationSet = getActivitySetRelatedByCreatedTransId();
Date result = null;
if (creationSet == null)
{
getLog().warn("Issue " + getUniqueId() + " (pk=" + getIssueId() +
") does not have a creation ActivitySet");
}
else
{
result = creationSet.getCreatedDate();
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public ScarabUser getCreatedBy()
throws TorqueException
{
ActivitySet creationSet = getActivitySetRelatedByCreatedTransId();
ScarabUser result = null;
if (creationSet == null)
{
getLog().warn("Issue " + getUniqueId() + " (pk=" + getIssueId() +
") does not have a creation ActivitySet");
}
else
{
result = creationSet.getScarabUser();
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public boolean isCreatingUser(ScarabUser user)
throws TorqueException
{
ActivitySet creationSet = getActivitySetRelatedByCreatedTransId();
boolean result = false;
if (creationSet == null)
{
getLog().warn("Issue " + getUniqueId() + " (pk=" + getIssueId() +
") does not have a creation ActivitySet");
}
else
{
result = creationSet.getCreatedBy().equals(user.getUserId());
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet getLastActivitySet()
throws TorqueException
{
ActivitySet t = null;
if (!isNew())
{
Object obj = ScarabCache.get(this, GET_LAST_TRANSACTION, this.getLastTransId());
if (obj == null)
{
Criteria crit = new Criteria();
crit.addJoin(ActivitySetPeer.TRANSACTION_ID,
ActivityPeer.TRANSACTION_ID);
crit.add(ActivityPeer.ISSUE_ID, getIssueId());
Integer[] typeIds = {ActivitySetTypePeer.EDIT_ISSUE__PK,
ActivitySetTypePeer.MOVE_ISSUE__PK};
crit.addIn(ActivitySetPeer.TYPE_ID, typeIds);
// there could be multiple attributes modified during the
// creation which will lead to duplicates
crit.setDistinct();
crit.addDescendingOrderByColumn(ActivitySetPeer.CREATED_DATE);
List activitySets = ActivitySetPeer.doSelect(crit);
if (activitySets.size() > 0)
{
t = (ActivitySet)activitySets.get(0);
}
ScarabCache.put(t, this, GET_LAST_TRANSACTION, this.getLastTransId());
}
else
{
t = (ActivitySet)obj;
}
}
return t;
}
// in java/org/tigris/scarab/om/Issue.java
public Date getModifiedDate()
throws TorqueException
{
Date result = null;
if (!isNew())
{
ActivitySet t = getLastActivitySet();
if (t == null)
{
result = getCreatedDate();
}
else
{
result = t.getCreatedDate();
}
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public long getHoursIdle() throws TorqueException, ParseException
{
Date now = new Date();
Date date = null;
Date onHoldUntil = null;
long diffHours = 0;
if (!isNew())
{
boolean onHold = isOnHold();
if(onHold)
{
onHoldUntil = getOnHoldUntil(); // on Hold until this date
if(onHoldUntil == null)
{
return 0; // we are on hold but there is no end date, so we wait forever.
}
diffHours = (now.getTime() - onHoldUntil.getTime()) / (1000*60*60);
if(diffHours < 0)
{
return 0; // onHoldDate not yet reached, so we are not idle by definition
}
}
ActivitySet t = getLastActivitySet();
if (t == null)
{
date = getCreatedDate();
}
else
{
date = t.getCreatedDate();
}
if(onHold)
{
if (date.before(onHoldUntil))
{
// The date of last activity was before the onHoldUntil date
// In that case we count the end of the onHold period as the
// event.
date = onHoldUntil;
}
}
}
// Return the difference in hours between now and the last date of activities:
diffHours = (now.getTime() - date.getTime()) / (1000*60*60);
return diffHours;
}
// in java/org/tigris/scarab/om/Issue.java
public ScarabUser getModifiedBy()
throws TorqueException
{
ScarabUser result = null;
if (!isNew())
{
ActivitySet t = getLastActivitySet();
if (t == null)
{
result = getCreatedBy();
}
else
{
result = ScarabUserManager
.getInstance(t.getCreatedBy());
}
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public int getCommentsCount() throws TorqueException
{
return getComments(true).size();
}
// in java/org/tigris/scarab/om/Issue.java
public boolean isCommentsLong() throws TorqueException
{
return (getCommentsCount() > getCommentsLimit());
}
// in java/org/tigris/scarab/om/Issue.java
public List getComments(boolean full) throws TorqueException
{
List result = null;
Boolean fullBool = (full ? Boolean.TRUE : Boolean.FALSE);
Object obj = getCachedObject(GET_COMMENTS, fullBool);
if (obj == null)
{
Criteria crit = new Criteria()
.add(AttachmentPeer.ISSUE_ID, getIssueId())
.addJoin(AttachmentTypePeer.ATTACHMENT_TYPE_ID,
AttachmentPeer.ATTACHMENT_TYPE_ID)
.add(AttachmentTypePeer.ATTACHMENT_TYPE_ID,
Attachment.COMMENT__PK)
.addDescendingOrderByColumn(AttachmentPeer.CREATED_DATE);
if (!full)
{
crit.setLimit(getCommentsLimit());
}
result = AttachmentPeer.doSelect(crit);
putCachedObject(result, GET_COMMENTS, fullBool);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public List getUrls() throws TorqueException
{
List result = null;
Object obj = getCachedObject(GET_URLS);
if (obj == null)
{
Criteria crit = new Criteria()
.add(AttachmentPeer.ISSUE_ID, getIssueId())
.addJoin(AttachmentTypePeer.ATTACHMENT_TYPE_ID,
AttachmentPeer.ATTACHMENT_TYPE_ID)
.add(AttachmentTypePeer.ATTACHMENT_TYPE_ID,
Attachment.URL__PK)
.add(AttachmentPeer.DELETED, 0);
result = AttachmentPeer.doSelect(crit);
putCachedObject(result, GET_URLS);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public List getExistingAttachments() throws TorqueException
{
List result = null;
Object obj = getCachedObject(GET_EXISTING_ATTACHMENTS);
if (obj == null)
{
Criteria crit = new Criteria()
.add(AttachmentPeer.ISSUE_ID, getIssueId())
.addJoin(AttachmentTypePeer.ATTACHMENT_TYPE_ID,
AttachmentPeer.ATTACHMENT_TYPE_ID)
.add(AttachmentTypePeer.ATTACHMENT_TYPE_ID,
Attachment.FILE__PK)
.add(AttachmentPeer.DELETED, 0);
result = AttachmentPeer.doSelect(crit);
putCachedObject(result, GET_EXISTING_ATTACHMENTS);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public List getActivitiesWithNullEndDate(Attribute attribute)
throws TorqueException
{
List result = null;
Object obj = ScarabCache.get(this, GET_NULL_END_DATE, attribute);
if (obj == null)
{
Criteria crit = new Criteria();
crit.add(ActivityPeer.ISSUE_ID, this.getIssueId());
crit.add(ActivityPeer.ATTRIBUTE_ID, attribute.getAttributeId());
crit.add(ActivityPeer.END_DATE, null);
result = ActivityPeer.doSelect(crit);
ScarabCache.put(result, this, GET_NULL_END_DATE, attribute);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public int getHistoryLimit() throws TorqueException
{
RModuleIssueType rmit = getModule().getRModuleIssueType(getIssueType());
if (rmit != null)
{
return rmit.getHistory();
}
else
{
return 5;
}
}
// in java/org/tigris/scarab/om/Issue.java
public boolean isHistoryLong() throws TorqueException
{
return isHistoryLong(getHistoryLimit());
}
// in java/org/tigris/scarab/om/Issue.java
public boolean isHistoryLong(int limit) throws TorqueException
{
return (getActivity(true).size() > limit);
}
// in java/org/tigris/scarab/om/Issue.java
public List getActivity(ScarabUser user) throws TorqueException
{
return getActivity(false, getHistoryLimit(), user);
}
// in java/org/tigris/scarab/om/Issue.java
public List getActivity(int limit, ScarabUser user) throws TorqueException
{
return getActivity(false, limit, user);
}
// in java/org/tigris/scarab/om/Issue.java
public List getActivity(boolean fullHistory, ScarabUser user) throws TorqueException
{
return getActivity(fullHistory, getHistoryLimit(), user);
}
// in java/org/tigris/scarab/om/Issue.java
public List getActivity(boolean fullHistory) throws TorqueException
{
return this.getActivity(fullHistory, null);
}
// in java/org/tigris/scarab/om/Issue.java
private List getActivity(boolean fullHistory, int limit) throws TorqueException
{
return this.getActivity(fullHistory, limit, null);
}
// in java/org/tigris/scarab/om/Issue.java
private List getActivity(boolean fullHistory, int limit, ScarabUser user) throws TorqueException
{
List result = null;
Boolean fullHistoryObj = fullHistory ? Boolean.TRUE : Boolean.FALSE;
Object obj = getCachedObject(GET_ACTIVITY, fullHistoryObj,
new Integer(limit));
if (obj == null)
{
Criteria crit = new Criteria()
.add(ActivityPeer.ISSUE_ID, getIssueId())
.addAscendingOrderByColumn(ActivityPeer.TRANSACTION_ID);
if (!fullHistory)
{
crit.setLimit(limit);
}
result = ActivityPeer.doSelect(crit);
putCachedObject(result, GET_ACTIVITY,
fullHistoryObj, new Integer(limit));
}
else
{
result = (List)obj;
}
/**
* Filter all activities related to attributegroups restricted to any role
* to which current user does not belong to.
*
*/
final List visibleActivities = new ArrayList();
for (Iterator it = result.iterator(); it.hasNext(); )
{
final Activity act = (Activity)it.next();
final Attribute attr = act.getAttribute();
if (isAttributeVisible(attr, user))
{
visibleActivities.add(act);
}
}
return visibleActivities;
}
// in java/org/tigris/scarab/om/Issue.java
public void addActivity(Activity activity) throws TorqueException
{
List activityList = null;
try
{
activityList = getActivity(true);
}
catch (Exception e)
{
throw new TorqueException(e); //EXCEPTION
}
super.addActivity(activity);
if (!activityList.contains(activity))
{
activityList.add(activity);
}
}
// in java/org/tigris/scarab/om/Issue.java
public List getActivitySets()
throws TorqueException
{
List result = null;
Object obj = ScarabCache.get(this, GET_TRANSACTIONS);
if (obj == null)
{
Criteria crit = new Criteria();
crit.add(ActivityPeer.ISSUE_ID, getIssueId());
crit.addJoin(ActivitySetPeer.TRANSACTION_ID, ActivityPeer.TRANSACTION_ID);
crit.setDistinct();
result = ActivitySetPeer.doSelect(crit);
ScarabCache.put(result, this, GET_TRANSACTIONS);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public boolean isAttributeVisible(final Attribute attr, final ScarabUser user)
throws TorqueException
{
final List/*<AttributeGroup>*/ attrGroups = this.getIssueType().getAttributeGroups();
boolean foundInAnyGroup = false;
boolean visibleInFoundGroup = false;
for(Iterator itAny = attrGroups.iterator(); !foundInAnyGroup && itAny.hasNext();)
{
final AttributeGroup ag = (AttributeGroup)itAny.next();
if(getModuleId().equals(ag.getModuleId()) && ag.getAttributes().contains(attr))
{
foundInAnyGroup = true;
if(null == ag.getViewRoleId() || ag.isVisible4User(user))
{
visibleInFoundGroup = true;
}
}
}
return !foundInAnyGroup || visibleInFoundGroup;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet getActivitySet(final ScarabUser user,
final Attachment attachment,
final Integer type)
throws TorqueException,ScarabException
{
ActivitySet activitySet = null;
if (attachment == null)
{
activitySet = ActivitySetManager
.getInstance(type, user);
}
else
{
activitySet = ActivitySetManager
.getInstance(type, user, attachment);
}
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet getActivitySet(ScarabUser user, Integer type)
throws TorqueException, ScarabException
{
return getActivitySet(user, null, type);
}
// in java/org/tigris/scarab/om/Issue.java
public List getAllDependencies()
throws TorqueException
{
List dependencies = new ArrayList();
dependencies.addAll(getChildren());
dependencies.addAll(getParents());
return dependencies;
}
// in java/org/tigris/scarab/om/Issue.java
public List getChildren() throws TorqueException
{
return getChildren(true);
}
// in java/org/tigris/scarab/om/Issue.java
public List getChildren(boolean hideDeleted) throws TorqueException
{
List result = null;
Boolean hide = hideDeleted ? Boolean.TRUE : Boolean.FALSE;
Object obj = getCachedObject(GET_CHILDREN, hide);
if (obj == null)
{
Criteria crit = new Criteria()
.add(DependPeer.OBSERVED_ID, getIssueId());
if (hideDeleted)
{
crit.add(DependPeer.DELETED, false);
}
result = DependPeer.doSelect(crit);
putCachedObject(result, GET_CHILDREN, hide);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public List getParents() throws TorqueException
{
return getParents(true);
}
// in java/org/tigris/scarab/om/Issue.java
public List getParents(boolean hideDeleted) throws TorqueException
{
List result = null;
Boolean hide = hideDeleted ? Boolean.TRUE : Boolean.FALSE;
Object obj = getCachedObject(GET_PARENTS, hide);
if (obj == null)
{
Criteria crit = new Criteria()
.add(DependPeer.OBSERVER_ID, getIssueId());
if (hideDeleted)
{
crit.add(DependPeer.DELETED, false);
}
result = DependPeer.doSelect(crit);
putCachedObject(result, GET_PARENTS, hide);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public List getAllDependencyTypes() throws TorqueException
{
return DependTypeManager.getAll();
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet doAddDependency(ActivitySet activitySet, Depend depend,
Issue childIssue, ScarabUser user)
throws TorqueException, ScarabException
{
// Check whether the entered issue is already dependent on this
// Issue. If so, then throw an exception because we don't want
// to add it again.
Depend prevDepend = this.getDependency(childIssue, true);
if (prevDepend != null)
{
throw new ScarabException(L10NKeySet.DependencyExists);
}
// we definitely want to do an insert here so force it.
depend.setNew(true);
depend.setDeleted(false);
depend.save();
Attachment comment = depend.getDescriptionAsAttachment(user, this);
activitySet = attachActivitySet(activitySet, user, comment);
// Save activity record for the parent issue
ActivityManager
.createAddDependencyActivity(this, activitySet, depend);
// Save activity record for the child issue
ActivityManager
.createAddDependencyActivity(childIssue, activitySet, depend);
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public Depend getDependency(Issue potentialDependency) throws TorqueException
{
return getDependency(potentialDependency, true);
}
// in java/org/tigris/scarab/om/Issue.java
public Depend getDependency(Issue potentialDependency, boolean hideDeleted) throws TorqueException
{
Depend result = null;
Object obj = ScarabCache.get(this, GET_DEPENDENCY, potentialDependency);
if (obj == null)
{
// Determine if this issue is a parent to the potentialDependency
Criteria crit = new Criteria(2)
.add(DependPeer.OBSERVED_ID, getIssueId())
.add(DependPeer.OBSERVER_ID, potentialDependency.getIssueId());
if (hideDeleted)
{
crit.add(DependPeer.DELETED, false);
}
List childIssues = DependPeer.doSelect(crit);
// A system invariant is that we will get one and only one
// record back.
if (!childIssues.isEmpty())
{
result = (Depend)childIssues.get(0);
}
else
{
// Determine if this issue is a child to the potentialDependency
Criteria crit2 = new Criteria(2)
.add(DependPeer.OBSERVER_ID, getIssueId())
.add(DependPeer.OBSERVED_ID, potentialDependency.getIssueId());
if (hideDeleted)
{
crit2.add(DependPeer.DELETED, false);
}
List parentIssues = DependPeer.doSelect(crit2);
if (!parentIssues.isEmpty())
{
result = (Depend)parentIssues.get(0);
}
}
if (result != null)
{
ScarabCache.put(result, this, GET_DEPENDENCY, potentialDependency);
}
}
else
{
result = (Depend)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public void save(Connection dbCon)
throws TorqueException
{
Module module = getModule();
if (!module.allowsIssues() || (isNew() && !module.allowsNewIssues()))
{
throw new UnsupportedOperationException(module.getName() +
" does not allow issues."); //EXCEPTION
}
// remove unset AttributeValues before saving
List attValues = getAttributeValues();
// reverse order since removing from list
for (int i=attValues.size()-1; i>=0; i--)
{
AttributeValue attVal = (AttributeValue) attValues.get(i);
if (!attVal.isSet())
{
attValues.remove(i);
}
}
if (isNew())
{
// set the issue id
setIdDomain(module.getScarabInstanceId());
setIdPrefix(module.getCode());
// for an enter issue template, do not give issue id
// set id count to -1 so does not show up as an issue
if (isTemplate())
{
setIdCount(-1);
}
else
{
try
{
final int suggestedID = getIdCount();
if (suggestedID != 0) {
// Force the next available issue ID to be the
// nominated value, if not out of sequence.
// TODO: assert that this issue doesn't already exist
// In this case, just skip the next action.
setNextIssueId(dbCon, suggestedID);
}
// Set the ID to the next available value.
setIdCount(getNextIssueId(dbCon));
}
catch (Exception e)
{
throw new TorqueException(e); //EXCEPTION
}
}
}
if( getActivitySetRelatedByLastTransId()==null
||getActivitySetRelatedByCreatedTransId()==null)
{
throw new RuntimeException("Created or Last ActivitySet must not be null.");
}
super.save(dbCon);
}
// in java/org/tigris/scarab/om/Issue.java
private int getNextIssueId(Connection con)
throws TorqueException, ScarabException
{
int id = -1;
String key = getIdTableKey();
DatabaseMap dbMap = IssuePeer.getTableMap().getDatabaseMap();
IDBroker idbroker = dbMap.getIDBroker();
try
{
id = idbroker.getIdAsInt(con, key);
}
catch (Exception e)
{
synchronized (idbroker)
{
try
{
id = idbroker.getIdAsInt(con, key);
}
catch (Exception idRetrievalErr)
{
// a module code entry in the id_table was likely not
// entered, insert a row into the id_table and try again.
try
{
saveIdTableKey(con, 2);
id = 1;
}
catch (Exception badException)
{
getLog().error("Could not get an id, even after "
+"trying to add a module entry into the ID_TABLE",
e);
getLog()
.error("Error trying to create ID_TABLE entry for "
+ getIdTableKey(), badException);
// throw the original
throw new ScarabException(
L10NKeySet.ExceptionRetrievingIssueId,
badException);
}
}
}
}
return id;
}
// in java/org/tigris/scarab/om/Issue.java
private void setNextIssueId(Connection con, int newID)
throws TorqueException, ScarabException
{
String key = getIdTableKey();
DatabaseMap dbMap = IssuePeer.getTableMap().getDatabaseMap();
IDBroker idbroker = dbMap.getIDBroker();
int nextID = 1;
synchronized (idbroker)
{
try
{
// Check if the ID table is available and get the next ID
nextID = idbroker.getIdAsInt(con, key);
}
catch (Exception idRetrievalErr) {
// No, create the ID table now
saveIdTableKey(con, nextID);
}
if (nextID > newID) {
getLog()
.error("New issue ID "+ newID
+ "is out of sequence. Must be at least " + nextID);
}
else
{
try
{
// Now set the next available ID in the table
setIdTableKey(con, newID);
}
catch (Exception badException)
{
getLog()
.error("Error creating ID_TABLE entry for "
+ getIdTableKey(), badException);
// throw the original
throw new ScarabException(
L10NKeySet.ExceptionRetrievingIssueId,
badException);
}
}
}
}
// in java/org/tigris/scarab/om/Issue.java
private String getIdTableKey()
throws TorqueException
{
Module module = getModule();
String prefix = module.getCode();
String domain = module.getScarabInstanceId();
if (domain != null && domain.length() > 0)
{
prefix = domain + "-" + prefix;
}
return prefix;
}
// in java/org/tigris/scarab/om/Issue.java
private void saveIdTableKey(final Connection dbCon, final int nextID)
throws TorqueException
{
int id = 0;
final DatabaseMap dbMap = IssuePeer.getTableMap().getDatabaseMap();
final IDBroker idbroker = dbMap.getIDBroker();
final String idTable = IDBroker.TABLE_NAME.substring(0,
IDBroker.TABLE_NAME.indexOf('.'));
try
{
id = idbroker.getIdAsInt(dbCon, idTable);
}
catch(Exception e)
{
Log.get( getClass().getName() ).error(e);
throw new TorqueException(e);
}
final String key = getIdTableKey();
// FIXME: UGLY! IDBroker doesn't have a Peer yet.
final String sql = "insert into " + idTable
+ " (ID_TABLE_ID,TABLE_NAME,NEXT_ID,QUANTITY) "
+ " VALUES (" + id + ",'" + key + "'," + nextID + ",1)" ;
BasePeer.executeStatement(sql, dbCon);
}
// in java/org/tigris/scarab/om/Issue.java
private void setIdTableKey(final Connection dbCon, int id)
throws TorqueException
{
final String key = getIdTableKey();
// FIXME: UGLY! IDBroker doesn't have a Peer yet.
final String sql = "update ID_TABLE set NEXT_ID=" + id
+ " where TABLE_NAME='" + key + "'";
BasePeer.executeStatement(sql, dbCon);
}
// in java/org/tigris/scarab/om/Issue.java
public IssueTemplateInfo getTemplateInfo()
throws TorqueException
{
IssueTemplateInfo result = null;
Object obj = ScarabCache.get(this, GET_TEMPLATEINFO);
if (obj == null)
{
Criteria crit = new Criteria(1);
crit.add(IssueTemplateInfoPeer.ISSUE_ID, getIssueId());
result = (IssueTemplateInfo)IssueTemplateInfoPeer
.doSelect(crit).get(0);
ScarabCache.put(result, this, GET_TEMPLATEINFO);
}
else
{
result = (IssueTemplateInfo)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public List getUnsetRequiredAttrs(Module newModule, IssueType newIssueType)
throws TorqueException
{
List attrs = new ArrayList();
if (!getIssueType().getIssueTypeId()
.equals(newIssueType.getIssueTypeId())
|| !getModule().getModuleId().equals(newModule.getModuleId()))
{
List requiredAttributes =
newIssueType.getRequiredAttributes(newModule);
Map attrValues = getAttributeValuesMap();
for (Iterator i = requiredAttributes.iterator(); i.hasNext(); )
{
Attribute attr = (Attribute)i.next();
if (!attrValues.containsKey(attr.getName().toUpperCase()))
{
attrs.add(attr);
}
}
}
return attrs;
}
// in java/org/tigris/scarab/om/Issue.java
public Issue move(final Module newModule,
final IssueType newIssueType,
final ScarabUser user,
final String reason,
final List commentAttrs,
final List commentUserValues)
throws TorqueException, ScarabException
{
Issue newIssue;
final Attachment attachment = new Attachment();
// If moving to a new issue type, just change the issue type id
// otherwise, create fresh issue
if (getModule().getModuleId().equals(newModule.getModuleId())
&& !getIssueType().getIssueTypeId().equals(newIssueType.getIssueTypeId()))
{
newIssue = this;
newIssue.setIssueType(newIssueType);
newIssue.save();
}
else
{
newIssue = newModule.getNewIssue(newIssueType);
}
if (newIssue != this)//new issue is not same issue instance as old issue
{
// mark issue as moved
setMoved(true);
save();
//add new transaction to new issue
ActivitySet createActivitySet = ActivitySetManager.getInstance(
ActivitySetTypePeer.CREATE_ISSUE__PK, getCreatedBy());
createActivitySet.setCreatedDate(getCreatedDate());
createActivitySet.save();
newIssue.setCreatedTransId(createActivitySet.getActivitySetId());
newIssue.save();
// copy attachments: comments/files etc.
final Iterator attachments = getAttachments().iterator();
while (attachments.hasNext())
{
final Attachment oldA = (Attachment)attachments.next();
String oldFilePath = oldA.getFullPath();
oldA.setIssueId(newIssue.getIssueId());
oldA.save();
// move file attachment, too
if (Attachment.FILE__PK.equals(oldA.getTypeId())
&& !newIssue.getUniqueId().equals(this.getUniqueId()))
{
try
{
oldA.copyFileFromTo(oldFilePath, oldA.getFullPath());//copy
File f = new File(oldFilePath);//delete old one from disk
f.delete();
}
catch (Exception ex)
{
throw new ScarabException(L10NKeySet.ExceptionGeneral,ex);
}
}
}
// Copy over activity sets for the source issue's previous,
// and adapt them to new issue
final List activitySets = getActivitySets();
final List nonMatchingAttributes = getNonMatchingAttributeValuesList
(newModule, newIssueType);
final List alreadyAssociatedUsers = new ArrayList();
for (Iterator i = activitySets.iterator(); i.hasNext();)
{
final ActivitySet as = (ActivitySet)i.next();
// If activity set has an attachment, make a copy for new issue
// Copy over activities with sets
final List activities = as.getActivityList(this);
for (Iterator j = activities.iterator(); j.hasNext();)
{
// iterate over and move transaction's activities
final Activity a = (Activity)j.next();
// Only copy transactions that are records of previous move/copies
// or transactions relating to attributes.
// Other transactions (attachments, dependencies)
// will be saved when attachments and dependencies are copied.
if (as.getTypeId().equals((ActivitySetTypePeer.MOVE_ISSUE__PK))
|| !a.getAttributeId().equals(new Integer("0")))
{
// If this is an activity relating to setting an attribute value
// And the final value is in the issue right now, we'll copy
// over the attribute value
final AttributeValue attVal = getAttributeValueWithValue(a.getAttribute(),
a.getNewValue(), a.getNewNumericValue());
if (a.getEndDate() == null && attVal != null)
{
final List values = getAttributeValues(a.getAttribute());
for (Iterator it = values.iterator(); it.hasNext(); )
{
final AttributeValue att = (AttributeValue)it.next();
// Only copy if the target artifact type contains this
// Attribute
if (attVal != null && !isNonMatchingAttribute(nonMatchingAttributes, att))
{
final boolean isUser = (att instanceof UserAttribute);
if (!isUser || !alreadyAssociatedUsers.contains(((UserAttribute)att).getUserName()+att.getAttribute().getName()))
{
att.setIssueId(newIssue.getIssueId());
att.setActivity(a);
att.startActivitySet(as);
att.save();
if (isUser)
{
alreadyAssociatedUsers.add(((UserAttribute)att).getUserName()+att.getAttribute().getName());
}
}
}
}
}
}
}
}
//adapt all misc activities from old issue
Iterator iterActivities = getActivitys().iterator();
while(iterActivities.hasNext()){
Activity act = (Activity)iterActivities.next();
act.setIssue(newIssue);
act.save();
newIssue.getActivity(true).add(act); // ?
}
// Adjust dependencies if its a new issue id
// (i.e.. moved to new module)
final List children = getChildren();
for (Iterator i = children.iterator(); i.hasNext();)
{
Depend depend = (Depend)i.next();
doDeleteDependency(null, depend, user);
final Issue child = IssueManager.getInstance(depend.getObserverId());
final Depend newDepend = new Depend();
newDepend.setObserverId(child.getIssueId());
newDepend.setObservedId(newIssue.getIssueId());
newDepend.setTypeId(depend.getTypeId());
newIssue.doAddDependency(null, newDepend, child, user);
}
final List parents = getParents();
for (Iterator j = parents.iterator(); j.hasNext();)
{
final Depend depend = (Depend)j.next();
doDeleteDependency(null, depend, user);
final Issue parent = IssueManager.getInstance(depend.getObservedId());
final Depend newDepend = new Depend();
newDepend.setObserverId(newIssue.getIssueId());
newDepend.setObservedId(parent.getIssueId());
newDepend.setTypeId(depend.getTypeId());
parent.doAddDependency(null, newDepend, newIssue, user);
}
}
// Generate comment to deal with attributes that do not
// Exist in destination module, as well as the user attributes.
final StringBuffer attachmentBuf = new StringBuffer();
final StringBuffer delAttrsBuf = new StringBuffer();
if (reason != null && reason.length() > 0)
{
attachmentBuf.append(reason).append(". ");
}
if (commentAttrs.size() > 0 || commentUserValues.size() > 0 )
{
attachmentBuf.append(Localization.format(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(), "DidNotCopyAttributes", newIssueType.getName() + "/" + newModule.getName()));
attachmentBuf.append("\n");
for (int i = 0; i < commentAttrs.size(); i++)
{
final List attVals = getAttributeValues((Attribute) commentAttrs
.get(i));
for (int j = 0; j < attVals.size(); j++)
{
final AttributeValue attVal = (AttributeValue) attVals.get(j);
String field = null;
delAttrsBuf.append(attVal.getAttribute().getName());
field = attVal.getValue();
delAttrsBuf.append("=").append(field).append(". ").append(
"\n");
}
}
for (int i=0; i < commentUserValues.size(); i++)
{
final UserAttribute useratt = (UserAttribute)commentUserValues.get(i);
delAttrsBuf.append(useratt.getAttribute().getName() + ": " +
useratt.getUserName() + "\n");
}
final String delAttrs = delAttrsBuf.toString();
attachmentBuf.append(delAttrs);
// Also create a regular comment with non-matching attribute info
final Attachment comment = new Attachment();
comment.setTextFields(user, newIssue, Attachment.COMMENT__PK);
final Object[] args = {this.getUniqueId(), newIssueType.getName() + " / " + newModule.getName()};
final StringBuffer commentBuf = new StringBuffer(Localization.format(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"DidNotCopyAttributesFromArtifact", args));
commentBuf.append("\n").append(delAttrs);
comment.setData(commentBuf.toString());
comment.setName(Localization.getString(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"Comment"));
comment.save();
}
else
{
attachmentBuf.append(Localization.getString(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"AllCopied"));
}
attachmentBuf.append(Localization.getString(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"MovedIssueNote"));
attachment.setData(attachmentBuf.toString());
attachment.setName(Localization.getString(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"MovedIssueNote"));
attachment.setTextFields(user, newIssue, Attachment.MODIFICATION__PK);
attachment.save();
// Create activitySet for the MoveIssue activity
final ActivitySet activitySet2 =
newIssue.attachActivitySet(null, user, attachment, ActivitySetTypePeer.MOVE_ISSUE__PK);
// Save activity record
final Attribute zeroAttribute = AttributeManager
.getInstance(NUMBERKEY_0);
ActivityManager
.createTextActivity(newIssue, zeroAttribute, activitySet2,
ActivityType.ISSUE_MOVED,
getUniqueId(), newIssue.getUniqueId());
newIssue.index();
//send notification
NotificationManagerFactory.getInstance().addActivityNotification(
ActivityType.ISSUE_MOVED,
activitySet2, newIssue, user);
return newIssue;
}
// in java/org/tigris/scarab/om/Issue.java
public Issue copy(final Module newModule,
final IssueType newIssueType,
final ScarabUser user,
final String reason,
final List commentAttrs,
final List commentUserValues)
throws TorqueException, ScarabException
{
Issue newIssue;
final Attachment attachment = new Attachment();
// create fresh issue
newIssue = newModule.getNewIssue(newIssueType);
if (newIssue != this)
{
ActivitySet createActivitySet = ActivitySetManager.getInstance(
ActivitySetTypePeer.CREATE_ISSUE__PK, getCreatedBy());
createActivitySet.setCreatedDate(getCreatedDate());
createActivitySet.save();
newIssue.setCreatedTransId(createActivitySet.getActivitySetId());
newIssue.save();
// Copy over activity sets for the source issue's attribute activities
final List activitySets = getActivitySets();
final List nonMatchingAttributes = getNonMatchingAttributeValuesList
(newModule, newIssueType);
final List alreadyAssociatedUsers = new ArrayList();
for (Iterator i = activitySets.iterator(); i.hasNext();)
{
final ActivitySet as = (ActivitySet)i.next();
ActivitySet newAS = null;
Attachment newAtt = null;
// Copy over activities with sets
final List activities = as.getActivityList(this);
for (Iterator j = activities.iterator(); j.hasNext();)
{
final Activity a = (Activity)j.next();
// Only copy transactions that are records of previous move/copies
// Or transactions relating to attributes.
// Other transactions (attachments, dependencies)
// Will be saved when attachments and dependencies are copied
if (as.getTypeId().equals((ActivitySetTypePeer.MOVE_ISSUE__PK))
|| !a.getAttributeId().equals(new Integer("0")))
{
// iterate over and copy transaction's activities
if(newAS == null){
// If old activity set has an attachment, make a copy for new issue
if (as.getAttachmentId() != null)
{
newAtt = as.getAttachment().copy();
newAtt.save();
}
//init and store new activity set/transaction
newAS = new ActivitySet();
newAS.setTypeId(as.getTypeId());
if (newAtt != null)
{
newAS.setAttachmentId(newAtt.getAttachmentId());
}
newAS.setCreatedBy(as.getCreatedBy());
newAS.setCreatedDate(as.getCreatedDate());
newAS.save();
}
final Activity newA = a.copy(newIssue, newAS);
newIssue.getActivity(true).add(newA);
// If this is an activity relating to setting an attribute value
// And the final value is in the issue right now, we'll copy
// over the attribute value
final AttributeValue attVal = getAttributeValueWithValue(a.getAttribute(),
a.getNewValue(), a.getNewNumericValue());
if (a.getEndDate() == null && attVal != null)
{
final List values = getAttributeValues(a.getAttribute());
for (Iterator it = values.iterator(); it.hasNext(); )
{
final AttributeValue att = (AttributeValue)it.next();
// Only copy if the target artifact type contains this
// Attribute
if (attVal != null && !isNonMatchingAttribute(nonMatchingAttributes, att))
{
final boolean isUser = (att instanceof UserAttribute);
if (!isUser || !alreadyAssociatedUsers.contains(((UserAttribute)att).getUserName()+att.getAttribute().getName()))
{
final AttributeValue newAttVal = att.copy();
newAttVal.setIssueId(newIssue.getIssueId());
newAttVal.setActivity(newA);
newAttVal.startActivitySet(newAS);
newAttVal.save();
if (isUser)
{
alreadyAssociatedUsers.add(((UserAttribute)att).getUserName()+att.getAttribute().getName());
}
}
}
}
}
}
}
}
// add dependencies newly
final List children = getChildren();
for (Iterator i = children.iterator(); i.hasNext();)
{
Depend depend = (Depend)i.next();
final Issue child = IssueManager.getInstance(depend.getObserverId());
final Depend newDepend = new Depend();
newDepend.setObserverId(child.getIssueId());
newDepend.setObservedId(newIssue.getIssueId());
newDepend.setTypeId(depend.getTypeId());
newIssue.doAddDependency(null, newDepend, child, user);
}
final List parents = getParents();
for (Iterator j = parents.iterator(); j.hasNext();)
{
final Depend depend = (Depend)j.next();
final Issue parent = IssueManager.getInstance(depend.getObservedId());
final Depend newDepend = new Depend();
newDepend.setObserverId(newIssue.getIssueId());
newDepend.setObservedId(parent.getIssueId());
newDepend.setTypeId(depend.getTypeId());
parent.doAddDependency(null, newDepend, newIssue, user);
}
// copy attachments: comments/files etc. and add them, too
final Iterator attachments = getAttachments().iterator();
while (attachments.hasNext())
{
final Attachment oldA = (Attachment)attachments.next();
final Attachment newA = oldA.copy();
newA.setIssueId(newIssue.getIssueId());
newA.save();
final Activity oldAct = oldA.getActivity();
if (oldAct != null)
{
final ActivitySet activitySet = newIssue.attachActivitySet(null, user);
ActivityManager.createTextActivity(newIssue, activitySet,
ActivityType.getActivityType(oldA.getActivity().getActivityType()), newA);
}
if (Attachment.FILE__PK.equals(newA.getTypeId()))
{
try
{
oldA.copyFileTo(newA.getFullPath());
}
catch (Exception ex)
{
throw new ScarabException(L10NKeySet.ExceptionGeneral,ex);
}
}
}
}
// Generate comment to deal with attributes that do not
// Exist in destination module, as well as the user attributes.
final StringBuffer attachmentBuf = new StringBuffer();
final StringBuffer delAttrsBuf = new StringBuffer();
if (reason != null && reason.length() > 0)
{
attachmentBuf.append(reason).append(". ");
}
if (commentAttrs.size() > 0 || commentUserValues.size() > 0 )
{
attachmentBuf.append(Localization.format(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(), "DidNotCopyAttributes", newIssueType.getName() + "/" + newModule.getName()));
attachmentBuf.append("\n");
for (int i = 0; i < commentAttrs.size(); i++)
{
final List attVals = getAttributeValues((Attribute) commentAttrs
.get(i));
for (int j = 0; j < attVals.size(); j++)
{
final AttributeValue attVal = (AttributeValue) attVals.get(j);
String field = null;
delAttrsBuf.append(attVal.getAttribute().getName());
field = attVal.getValue();
delAttrsBuf.append("=").append(field).append(". ").append(
"\n");
}
}
for (int i=0; i < commentUserValues.size(); i++)
{
final UserAttribute useratt = (UserAttribute)commentUserValues.get(i);
delAttrsBuf.append(useratt.getAttribute().getName() + ": " +
useratt.getUserName() + "\n");
}
final String delAttrs = delAttrsBuf.toString();
attachmentBuf.append(delAttrs);
// Also create a regular comment with non-matching attribute info
final Attachment comment = new Attachment();
comment.setTextFields(user, newIssue, Attachment.COMMENT__PK);
final Object[] args = {this.getUniqueId(), newIssueType.getName() + " / " + newModule.getName()};
final StringBuffer commentBuf = new StringBuffer(Localization.format(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"DidNotCopyAttributesFromArtifact", args));
commentBuf.append("\n").append(delAttrs);
comment.setData(commentBuf.toString());
comment.setName(Localization.getString(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"Comment"));
comment.save();
}
else
{
attachmentBuf.append(Localization.getString(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"AllCopied"));
}
attachmentBuf.append(Localization.getString(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"CopiedIssueNote"));
attachment.setData(attachmentBuf.toString());
attachment.setName(Localization.getString(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"CopiedIssueNote"));
attachment.setTextFields(user, newIssue, Attachment.MODIFICATION__PK);
attachment.save();
// Create activitySet for the MoveIssue activity
// NOTE: There is no distinction bewteen copy and move actions in ActivitySetTypePeer.
final ActivitySet activitySet2 =
newIssue.attachActivitySet(null, user, attachment, ActivitySetTypePeer.MOVE_ISSUE__PK);
// Save activity record
final Attribute zeroAttribute = AttributeManager
.getInstance(NUMBERKEY_0);
ActivityManager
.createTextActivity(newIssue, zeroAttribute, activitySet2,
ActivityType.ISSUE_COPIED,
getUniqueId(), newIssue.getUniqueId());
//send notification
NotificationManagerFactory.getInstance().addActivityNotification(
ActivityType.ISSUE_COPIED,
activitySet2, newIssue, user);
newIssue.index();
return newIssue;
}
// in java/org/tigris/scarab/om/Issue.java
public List getMatchingAttributeValuesList(Module newModule,
IssueType newIssueType)
throws TorqueException
{
List matchingAttributes = new ArrayList();
Map setMap = this.getAttributeValuesMap();
for (Iterator iter = setMap.keySet().iterator(); iter.hasNext();)
{
AttributeValue aval = (AttributeValue)setMap.get(iter.next());
List values = getAttributeValues(aval.getAttribute());
// loop thru the values for this attribute
for (int i = 0; i<values.size(); i++)
{
AttributeValue attVal = (AttributeValue)values.get(i);
RModuleAttribute modAttr = newModule.
getRModuleAttribute(aval.getAttribute(), newIssueType);
// If this attribute is active for the destination module,
// Add to matching attributes list
if (modAttr != null && modAttr.getActive())
{
// If attribute is an option attribute,
// Check if attribute option is active for destination module.
if (aval instanceof OptionAttribute)
{
// FIXME: Use select count
Criteria crit2 = new Criteria(4)
.add(RModuleOptionPeer.ACTIVE, true)
.add(RModuleOptionPeer.OPTION_ID, attVal.getOptionId())
.add(RModuleOptionPeer.MODULE_ID, newModule.getModuleId())
.add(RModuleOptionPeer.ISSUE_TYPE_ID, newIssueType.getIssueTypeId());
List modOpt = RModuleOptionPeer.doSelect(crit2);
if (!modOpt.isEmpty())
{
matchingAttributes.add(attVal);
}
}
else if (attVal instanceof UserAttribute)
{
ScarabUser user = null;
try
{
user = ScarabUserManager.getInstance(attVal.getUserId());
}
catch (Exception e)
{
getLog().error(e);
e.printStackTrace();
}
Attribute attr = attVal.getAttribute();
ScarabUser[] userArray = newModule.getUsers(attr.getPermission());
// If user exists in destination module with this permission,
// Add as matching value
if (Arrays.asList(userArray).contains(user))
{
matchingAttributes.add(attVal);
}
}
else
{
matchingAttributes.add(attVal);
}
}
}
}
return matchingAttributes;
}
// in java/org/tigris/scarab/om/Issue.java
public List getMatchingAttributeValuesList(String moduleId, String issueTypeId)
throws TorqueException
{
Module module = ModuleManager.getInstance(new Integer(moduleId));
IssueType issueType = IssueTypeManager.getInstance(new Integer(issueTypeId));
return getMatchingAttributeValuesList(module, issueType);
}
// in java/org/tigris/scarab/om/Issue.java
public List getNonMatchingAttributeValuesList(Module newModule,
IssueType newIssueType)
throws TorqueException
{
List nonMatchingAttributes = new ArrayList();
AttributeValue aval = null;
Map setMap = this.getAttributeValuesMap();
for (Iterator iter = setMap.values().iterator(); iter.hasNext();)
{
aval = (AttributeValue) iter.next();
List values = getAttributeValues(aval.getAttribute());
// loop thru the values for this attribute
for (Iterator i = values.iterator(); i.hasNext(); )
{
AttributeValue attVal = (AttributeValue) i.next();
RModuleAttribute modAttr = newModule.
getRModuleAttribute(aval.getAttribute(), newIssueType);
// If this attribute is not active for the destination module,
// Add to nonMatchingAttributes list
if (modAttr == null || !modAttr.getActive())
{
nonMatchingAttributes.add(attVal);
}
else
{
// If attribute is an option attribute, Check if
// attribute option is active for destination module.
if (attVal instanceof OptionAttribute)
{
Criteria crit2 = new Criteria(1)
.add(RModuleOptionPeer.ACTIVE, true)
.add(RModuleOptionPeer.OPTION_ID, attVal.getOptionId())
.add(RModuleOptionPeer.MODULE_ID, newModule.getModuleId())
.add(RModuleOptionPeer.ISSUE_TYPE_ID, newIssueType.getIssueTypeId());
List modOpt = RModuleOptionPeer.doSelect(crit2);
if ( modOpt.isEmpty())
{
nonMatchingAttributes.add(attVal);
}
}
else if (attVal instanceof UserAttribute)
{
ScarabUser user = null;
try
{
user = ScarabUserManager.getInstance(attVal.getUserId());
}
catch (Exception e)
{
Log.get().error("Unable to retrieve user for "
+ "attribute", e);
}
Attribute attr = attVal.getAttribute();
ScarabUser[] userArray =
newModule.getUsers(attr.getPermission());
// If user exists in destination module with
// this permission, add as matching value.
if (!Arrays.asList(userArray).contains(user))
{
nonMatchingAttributes.add(attVal);
}
}
}
}
}
return nonMatchingAttributes;
}
// in java/org/tigris/scarab/om/Issue.java
public List getNonMatchingAttributeValuesList(String moduleId, String issueTypeId)
throws TorqueException
{
Module module = ModuleManager.getInstance(new Integer(moduleId));
IssueType issueType = IssueTypeManager.getInstance(new Integer(issueTypeId));
return getNonMatchingAttributeValuesList(module, issueType);
}
// in java/org/tigris/scarab/om/Issue.java
public void deleteItem(ScarabUser user)
throws TorqueException, ScarabException
{
Module module = getModule();
if (user.hasPermission(ScarabSecurity.ITEM__DELETE, module)
|| (user.getUserId().equals(getCreatedBy().getUserId()) && isTemplate()))
{
setDeleted(true);
save();
}
else
{
throw new ScarabException(L10NKeySet.YouDoNotHavePermissionToAction);
}
}
// in java/org/tigris/scarab/om/Issue.java
public AttributeValue getDefaultTextAttributeValue()
throws TorqueException
{
AttributeValue result = null;
Object obj = ScarabCache.get(this, GET_DEFAULT_TEXT_ATTRIBUTEVALUE);
if (obj == null)
{
Attribute defaultTextAttribute =
getIssueType().getDefaultTextAttribute(getModule());
if (defaultTextAttribute != null)
{
result = getAttributeValue(defaultTextAttribute);
}
ScarabCache.put(result, this, GET_DEFAULT_TEXT_ATTRIBUTEVALUE);
}
else
{
result = (AttributeValue)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public String getDefaultText()
throws TorqueException
{
String result = null;
Object obj = ScarabCache.get(this, GET_DEFAULT_TEXT);
if (obj == null)
{
AttributeValue emailAV = getDefaultTextAttributeValue();
if (emailAV != null)
{
result = emailAV.getValue();
}
if (result == null)
{
ActivitySet activitySet = getInitialActivitySet();
if (activitySet != null)
{
Attachment reason = activitySet.getAttachment();
if (reason != null && reason.getData() != null
&& reason.getData().trim().length() > 0)
{
result = reason.getData();
}
}
}
result = (result == null) ?
Localization.getString(ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(), "NoIssueSummaryAvailable")
: result;
ScarabCache.put(result, this, GET_DEFAULT_TEXT);
}
else
{
result = (String)obj;
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet assignUser(ActivitySet activitySet,
final ScarabUser assignee,
final ScarabUser assigner,
final Attribute attribute,
final Attachment attachment)
throws TorqueException,ScarabException
{
final UserAttribute attVal = new UserAttribute();
activitySet = attachActivitySet(activitySet, assigner, attachment);
attVal.startActivitySet(activitySet);
ActivityManager
.createUserActivity(this, attribute, activitySet,
null,
null, assignee.getUserId());
// Save user attribute values
attVal.setIssue(this);
attVal.setAttributeId(attribute.getAttributeId());
attVal.setUserId(assignee.getUserId());
attVal.setValue(assignee.getUserName());
attVal.save();
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet changeUserAttributeValue(ActivitySet activitySet,
final ScarabUser assignee,
final ScarabUser assigner,
final AttributeValue oldAttVal,
final Attribute newAttr,
final Attachment attachment)
throws TorqueException,ScarabException
{
activitySet = attachActivitySet(activitySet, assigner, attachment);
oldAttVal.startActivitySet(activitySet);
// Save activity record for deletion of old assignment
ActivityManager
.createUserActivity(this, oldAttVal.getAttribute(),
activitySet,
null,
assignee.getUserId(), null);
// Save activity record for new assignment
ActivityManager
.createUserActivity(this, newAttr, activitySet,
null,
null, assignee.getUserId());
// Save assignee value
oldAttVal.setAttributeId(newAttr.getAttributeId());
oldAttVal.save();
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet deleteUser(ActivitySet activitySet,
final ScarabUser assignee,
final ScarabUser assigner,
final AttributeValue attVal,
final Attachment attachment)
throws TorqueException, ScarabException
{
activitySet = attachActivitySet(activitySet, assigner, attachment);
attVal.startActivitySet(activitySet);
// Save activity record
ActivityManager
.createUserActivity(this, attVal.getAttribute(),
activitySet,
null,
assignee.getUserId(), null);
// Save assignee value
attVal.setDeleted(true);
attVal.save();
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet doDeleteDependency(ActivitySet activitySet,
Depend oldDepend,
final ScarabUser user)
throws TorqueException, ScarabException
{
final Issue otherIssue = IssueManager
.getInstance(oldDepend.getObserverId(), false);
final Issue thisIssue = IssueManager
.getInstance(oldDepend.getObservedId(), false);
// get the original object so that we do an update
oldDepend = thisIssue.getDependency(otherIssue);
oldDepend.setNew(false);
oldDepend.setDeleted(true);
oldDepend.save();
// need to null out the cache entry so that Issue.getDependency()
// does not try to return the item from the cache
ScarabCache.put(null, thisIssue, GET_DEPENDENCY, otherIssue);
Attachment comment = oldDepend.getDescriptionAsAttachment(user, thisIssue);
activitySet = thisIssue.attachActivitySet(activitySet, user, comment);
activitySet = otherIssue.attachActivitySet(activitySet, user, comment);
ActivityManager
.createDeleteDependencyActivity(thisIssue, activitySet, oldDepend);
ActivityManager
.createDeleteDependencyActivity(otherIssue, activitySet, oldDepend);
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet doChangeUrlDescription(ActivitySet activitySet,
final ScarabUser user,
final Attachment attachment,
final String oldDescription)
throws TorqueException, ScarabException
{
final String newDescription = attachment.getName();
if (!oldDescription.equals(newDescription))
{
final Object[] args = {
oldDescription,
newDescription,
};
String desc = Localization.format(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"UrlDescChangedDesc", args);
if (desc.length() > 248)
{
desc = desc.substring(0,248) + "...";
}
activitySet = attachActivitySet(activitySet, user);
ActivityManager
.createTextActivity(this, activitySet,
ActivityType.URL_DESC_CHANGED, attachment,
oldDescription, newDescription);
NotificationManagerFactory.getInstance().addActivityNotification(
ActivityType.URL_DESC_CHANGED, activitySet, this, user);
}
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet doChangeUrlUrl(ActivitySet activitySet,
final ScarabUser user,
final Attachment attachment,
final String oldUrl)
throws TorqueException, ScarabException
{
final String newUrl = attachment.getData();
if (!oldUrl.equals(newUrl))
{
final Object[] args = {
oldUrl, newUrl
};
String desc = Localization.format(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"UrlChangedDesc", args);
if (desc.length() > 248)
{
desc = desc.substring(0,248) + "...";
}
activitySet = attachActivitySet(activitySet, user);
// Save activity record
ActivityManager.createTextActivity(
this,
activitySet,
ActivityType.URL_CHANGED,
attachment,
oldUrl,
newUrl);
NotificationManagerFactory.getInstance().addActivityNotification(
ActivityType.URL_CHANGED, activitySet, this, user);
}
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet doChangeDependencyType(ActivitySet activitySet,
final Depend oldDepend,
final Depend newDepend,
final ScarabUser user)
throws TorqueException, ScarabException
{
final String oldName = oldDepend.getDependType().getName();
final String newName = newDepend.getDependType().getName();
final boolean rolesHaveSwitched =
( oldDepend.getObserverId().equals(newDepend.getObservedId()) &&
oldDepend.getObservedId().equals(newDepend.getObserverId())
);
final boolean typeHasChanged =
( !newName.equals(oldName));
final boolean isActive = !newDepend.getDeleted();
// check to see if something changed
// only change dependency type for non-deleted deps
if ( isActive && ( rolesHaveSwitched || typeHasChanged ) )
{
final Issue otherIssue = (newDepend.getObservedId().longValue() != this.getIssueId().longValue()
? IssueManager.getInstance(newDepend.getObservedId(), false)
: IssueManager.getInstance(newDepend.getObserverId(), false));
// always delete an old dependency
oldDepend.setDeleted(true);
oldDepend.save();
// always create a new dependency
newDepend.setNew(true);
newDepend.save();
// need to null out the cache entry so that Issue.getDependency()
// does not try to return the item from the cache
ScarabCache.put(null, this, GET_DEPENDENCY, otherIssue);
final Attachment comment = newDepend.getDescriptionAsAttachment(user, this);
activitySet = attachActivitySet(activitySet, user, comment);
activitySet = otherIssue.attachActivitySet(activitySet, user, comment);
ActivityManager
.createChangeDependencyActivity(this, activitySet, newDepend,
oldName, newName);
ActivityManager
.createChangeDependencyActivity(otherIssue, activitySet, newDepend,
oldName, newName);
}
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet setInitialAttributeValues(ActivitySet activitySet,
Attachment attachment,
final HashMap newValues,
final ScarabUser user)
throws TorqueException, ScarabException
{
// Check new values for workflow
final String msg = doCheckInitialAttributeValueWorkflow(newValues, user);
if (msg != null)
{
throw new TorqueException(msg); //EXCEPTION
}
if (activitySet == null)
{
// Save activitySet record
activitySet = ActivitySetManager
.getInstance(ActivitySetTypePeer.CREATE_ISSUE__PK, user);
activitySet.save();
}
setActivitySetRelatedByCreatedTransId(activitySet);
// enter the values into the activitySet
final LinkedMap avMap = getModuleAttributeValuesMap();
final MapIterator iter = avMap.mapIterator();
while (iter.hasNext())
{
final AttributeValue aval = (AttributeValue)avMap.get(iter.next());
try
{
aval.startActivitySet(activitySet);
}
catch (ScarabException se)
{
L10NMessage l10nmsg = new L10NMessage(L10NKeySet.ExceptionTorqueGeneric,se);
throw new ScarabException(l10nmsg);
}
}
this.save();
// create initial issue creation activity
ActivityManager.createReportIssueActivity(this, activitySet,
Localization.getString(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"IssueCreated"));
// this needs to be done after the issue is created.
// check to make sure the attachment has data before submitting it.
final String attachmentData = attachment.getData();
if (attachmentData != null &&
attachmentData.length() > 0)
{
attachment = AttachmentManager.getReason(attachment, this, user);
activitySet.setAttachment(attachment);
}
activitySet.save();
// need to clear the cache since this is after the
// issue is saved. for some reason, things don't
// show up properly right away.
ScarabCache.clear();
index();
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet setAttributeValues(ActivitySet activitySet,
final HashMap newAttVals,
final Attachment attachment,
final ScarabUser user)
throws TorqueException,ScarabException
{
if (!isTemplate())
{
final String msg = doCheckAttributeValueWorkflow(newAttVals, user);
if (msg != null)
{
throw new ScarabException(L10NKeySet.ErrorExceptionMessage,msg);
}
}
if (attachment != null)
{
attachment.setTextFields(user, this,
Attachment.MODIFICATION__PK);
attachment.save();
}
activitySet = attachActivitySet(activitySet, user, attachment );
final LinkedMap avMap = getModuleAttributeValuesMap(true);
AttributeValue oldAttVal = null;
AttributeValue newAttVal = null;
final Iterator iter = newAttVals.keySet().iterator();
while (iter.hasNext())
{
final Integer attrId = (Integer)iter.next();
final Attribute attr = AttributeManager.getInstance(attrId);
oldAttVal = (AttributeValue)avMap.get(attr.getName().toUpperCase());
newAttVal = (AttributeValue)newAttVals.get(attrId);
final String newAttValValue = newAttVal.getValue();
if (oldAttVal != null &&
(newAttValValue != null && !newAttValValue.equals(oldAttVal.getValue())
|| newAttValValue == null)
)
{
if (newAttValValue != null && newAttValValue.length() > 0)
{
oldAttVal.setProperties(newAttVal);
}
else
{
oldAttVal.setDeleted(true);
}
oldAttVal.startActivitySet(activitySet);
oldAttVal.save();
}
}
index();
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
protected ActivitySet attachActivitySet(
ActivitySet activitySet,
final ScarabUser user,
final Attachment attachment,
final Integer activitySetType
)
throws TorqueException,ScarabException
{
if (activitySet == null)
{
activitySet = getActivitySet(
user, attachment,
activitySetType);
activitySet.save();
ScarabCache.clear();
}
setLastTransId(activitySet.getActivitySetId());
save();
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
protected ActivitySet attachActivitySet(
ActivitySet activitySet,
final ScarabUser user,
final Attachment attachment
)
throws TorqueException,ScarabException
{
return attachActivitySet(activitySet, user, attachment, ActivitySetTypePeer.EDIT_ISSUE__PK);
}
// in java/org/tigris/scarab/om/Issue.java
protected ActivitySet attachActivitySet(
ActivitySet activitySet,
final ScarabUser user
)
throws TorqueException,ScarabException
{
return attachActivitySet(activitySet, user, null, ActivitySetTypePeer.EDIT_ISSUE__PK);
}
// in java/org/tigris/scarab/om/Issue.java
public String doCheckInitialAttributeValueWorkflow(final HashMap newValues,
final ScarabUser user)
throws TorqueException, ScarabException
{
String msg = null;
final Iterator iter = newValues.keySet().iterator();
while (iter.hasNext())
{
final Integer attrId = (Integer)iter.next();
final Attribute attr = AttributeManager.getInstance(attrId);
if (attr.isOptionAttribute())
{
final AttributeOption toOption = AttributeOptionManager
.getInstance(new Integer((String)newValues.get(attrId)));
msg = WorkflowFactory.getInstance().checkInitialTransition(
toOption, this,
newValues, user);
}
if (msg != null)
{
break;
}
}
return msg;
}
// in java/org/tigris/scarab/om/Issue.java
public String doCheckAttributeValueWorkflow(final HashMap newAttVals,
final ScarabUser user)
throws TorqueException,ScarabException
{
final LinkedMap avMap = getModuleAttributeValuesMap();
AttributeValue oldAttVal = null;
AttributeValue newAttVal = null;
String msg = null;
final Iterator iter = newAttVals.keySet().iterator();
while (iter.hasNext())
{
final Integer attrId = (Integer)iter.next();
final Attribute attr = AttributeManager.getInstance(attrId);
oldAttVal = (AttributeValue)avMap.get(attr.getName().toUpperCase());
newAttVal = (AttributeValue)newAttVals.get(attrId);
AttributeOption fromOption = null;
AttributeOption toOption = null;
if (newAttVal.getValue() != null)
{
if (newAttVal.getAttribute().isOptionAttribute())
{
if (oldAttVal.getOptionId() == null)
{
fromOption = AttributeOptionManager.getInstance(ScarabConstants.INTEGER_0);
}
else
{
fromOption = oldAttVal.getAttributeOption();
}
toOption = newAttVal.getAttributeOption();
msg = WorkflowFactory.getInstance().checkTransition(
fromOption,
toOption, this,
newAttVals, user);
}
if (msg != null)
{
break;
}
}
}
return msg;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet doEditComment(ActivitySet activitySet,
final String newComment,
final Attachment attachment,
final ScarabUser user)
throws TorqueException, ScarabException
{
final String oldComment = attachment.getData();
if (!newComment.equals(oldComment))
{
attachment.setData(newComment);
attachment.save();
activitySet = attachActivitySet( activitySet, user);
// Save activity record
ActivityManager
.createTextActivity(this, null, activitySet,
ActivityType.COMMENT_CHANGED, null, attachment,
oldComment, newComment);
NotificationManagerFactory.getInstance().addActivityNotification(
ActivityType.COMMENT_CHANGED, activitySet,
this, user);
}
index();
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet doDeleteUrl(ActivitySet activitySet,
final Attachment attachment,
final ScarabUser user)
throws TorqueException, ScarabException
{
final String oldUrl = attachment.getData();
attachment.setDeleted(true);
attachment.save();
activitySet = attachActivitySet( activitySet, user);
// Save activity record
ActivityManager
.createTextActivity(this, null, activitySet,
ActivityType.URL_DELETED, null, attachment, oldUrl, null);
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public ActivitySet doRemoveAttachment(ActivitySet activitySet,
final MutableBoolean physicallyDeleted,
final Attachment attachment,
final ScarabUser user)
throws TorqueException, ScarabException
{
boolean attachmentPhysicallyDeleted = false;
final boolean physicalDeletionAllowed = Turbine.getConfiguration()
.getBoolean("scarab.attachment.remove.permanent",false);
if(physicalDeletionAllowed)
{
attachmentPhysicallyDeleted = attachment.deletePhysicalAttachment();
physicallyDeleted.set(attachmentPhysicallyDeleted);
}
attachment.setDeleted(true);
attachment.save();
activitySet = attachActivitySet(activitySet, user);
// Save activity record
ActivityManager
.createTextActivity(this, null, activitySet,
ActivityType.ATTACHMENT_REMOVED, null, attachment, attachment.getFileName(), null);
return activitySet;
}
// in java/org/tigris/scarab/om/Issue.java
public HashSet getAssociatedUsers() throws TorqueException
{
HashSet users = null;
final Object obj = ScarabCache.get(this, GET_ASSOCIATED_USERS);
if (obj == null)
{
final List attributeList = getModule()
.getUserAttributes(getIssueType(), true);
final List attributeIdList = new ArrayList();
for (int i=0; i<attributeList.size(); i++)
{
final Attribute att = (Attribute) attributeList.get(i);
final RModuleAttribute modAttr = getModule().
getRModuleAttribute(att, getIssueType());
if (modAttr.getActive())
{
attributeIdList.add(att.getAttributeId());
}
}
if (!attributeIdList.isEmpty())
{
users = new HashSet();
final Criteria crit = new Criteria()
.addIn(AttributeValuePeer.ATTRIBUTE_ID, attributeIdList)
.add(AttributeValuePeer.DELETED, false);
crit.setDistinct();
final List attValues = getAttributeValues(crit);
for (int i=0; i<attValues.size(); i++)
{
final List item = new ArrayList(2);
final AttributeValue attVal = (AttributeValue) attValues.get(i);
final ScarabUser su = ScarabUserManager.getInstance(attVal.getUserId());
final Attribute attr = AttributeManager.getInstance(attVal.getAttributeId());
item.add(attr);
item.add(su);
users.add(item);
}
}
ScarabCache.put(users, this, GET_ASSOCIATED_USERS);
}
else
{
users = (HashSet)obj;
}
return users;
}
// in java/org/tigris/scarab/om/Issue.java
public boolean isBlockingConditionTrue() throws TorqueException
{
boolean isBlockingConditionTrue = false;
final List blockingConditions = this.getRModuleIssueType().getConditions();
for (Iterator it = blockingConditions.iterator(); !isBlockingConditionTrue && it.hasNext(); )
{
final Condition cond = (Condition)it.next();
isBlockingConditionTrue = cond.evaluate(null, this);
// Will exit as soon as any evaluates true!
}
return isBlockingConditionTrue;
}
// in java/org/tigris/scarab/om/Issue.java
public boolean isBlockingAnyIssue() throws TorqueException
{
return this.getBlockedIssues().size() > 0;
}
// in java/org/tigris/scarab/om/Issue.java
public boolean isBlocked() throws TorqueException
{
return (getBlockingIssues().size()>0);
}
// in java/org/tigris/scarab/om/Issue.java
public boolean isBlockedBy(final String blockingId) throws TorqueException
{
final List blockingIssues = getBlockingIssues();
int issueCount = getBlockingIssues().size();
if (issueCount==0)
{
return false;
}
for(int index = 0; index < issueCount; index++)
{
final Issue issue = (Issue)blockingIssues.get(index);
final String id = issue.getUniqueId();
if(id.equals(blockingId))
{
return true;
}
}
return false;
}
// in java/org/tigris/scarab/om/Issue.java
public boolean isBlocking(final String blockedId) throws TorqueException
{
final List blockedIssues = getBlockedIssues();
final int issueCount = blockedIssues.size();
if (issueCount==0)
{
return false;
}
for(int index = 0; index < issueCount; index++)
{
final Issue issue = (Issue)blockedIssues.get(index);
final String id = issue.getUniqueId();
if(id.equals(blockedId))
{
return true;
}
}
return false;
}
// in java/org/tigris/scarab/om/Issue.java
public List getBlockingIssues() throws TorqueException
{
final List blockingIssues = new ArrayList();
final List prerequisiteIssues = this.getPrerequisiteIssues();
for (Iterator it = prerequisiteIssues.iterator(); it.hasNext(); )
{
final Issue is = (Issue)it.next();
if (is.isBlockingConditionTrue())
blockingIssues.add(is);
}
return blockingIssues;
}
// in java/org/tigris/scarab/om/Issue.java
public List getPrerequisiteIssues() throws TorqueException
{
final List blockingIssues = new ArrayList();
final List parentIssues = this.getParents();
for (Iterator it = parentIssues.iterator(); it.hasNext(); )
{
final Depend depend = (Depend)it.next();
if (depend.getDependType().getDependTypeId().equals(DependTypePeer.BLOCKING__PK))
{
blockingIssues.add(IssuePeer.retrieveByPK(depend.getObservedId()));
}
}
return blockingIssues;
}
// in java/org/tigris/scarab/om/Issue.java
public List getRelatedIssues() throws TorqueException
{
return getAssociatedIssues(DependTypePeer.NON_BLOCKING__PK);
}
// in java/org/tigris/scarab/om/Issue.java
public List getDuplicateIssues() throws TorqueException
{
return getAssociatedIssues(DependTypePeer.DUPLICATE__PK);
}
// in java/org/tigris/scarab/om/Issue.java
private List getAssociatedIssues(final Integer dependTypeId) throws TorqueException
{
final List relatedIssues = new ArrayList();
final List allIssues = this.getAllDependencies();
for (Iterator it = allIssues.iterator(); it.hasNext(); )
{
final Depend depend = (Depend)it.next();
final DependType type = depend.getDependType();
final Integer typeId = type.getDependTypeId();
if (typeId.equals(dependTypeId))
{
//Assume, the dependant issue is the ObservedId in the Depend
Issue relatedIssue = IssuePeer.retrieveByPK(depend.getObservedId());
if(relatedIssue.getIssueId().equals(this.getIssueId()))
{
//No, the dependant issue is the ObserverId in the depend.
relatedIssue = IssuePeer.retrieveByPK(depend.getObserverId());
}
relatedIssues.add(relatedIssue);
}
}
return relatedIssues;
}
// in java/org/tigris/scarab/om/Issue.java
public List getBlockedIssues() throws TorqueException
{
if (this.isBlockingConditionTrue())
{
return this.getDependantIssues();
}
else
{
return new ArrayList();
}
}
// in java/org/tigris/scarab/om/Issue.java
public List getDependantIssues() throws TorqueException
{
final List dependantIssues = new ArrayList();
final List childIssues = this.getChildren();
for (Iterator it = childIssues.iterator(); it.hasNext(); )
{
final Depend depend = (Depend)it.next();
if (depend.getDependType().getDependTypeId().equals(DependTypePeer.BLOCKING__PK))
{
dependantIssues.add(IssuePeer.retrieveByPK(depend.getObserverId()));
}
}
return dependantIssues;
}
// in java/org/tigris/scarab/om/Issue.java
public String getIssueNewId() throws TorqueException
{
return ActivityPeer.getNewIssueUniqueId(this);
}
// in java/org/tigris/scarab/om/Issue.java
public void setCreatedTransId(Long createdTransId)
throws TorqueException
{
super.setCreatedTransId(createdTransId);
if(super.getLastTransId()==null)
super.setLastTransId(createdTransId);
}
// in java/org/tigris/scarab/om/Issue.java
public boolean isRequiredAttributeFor(Attribute attribute, ScarabUser user) throws TorqueException, ScarabException
{
Module module = this.getModule();
IssueType issueType = this.getIssueType();
RModuleAttribute rma = module.getRModuleAttribute(attribute, issueType);
boolean result = rma.getRequired();
if(result == false)
{
List<Condition> conditions = rma.getConditions();
Iterator<Condition> iter = conditions.iterator();
while(iter.hasNext())
{
Condition condition = iter.next();
boolean eval = condition.evaluate(user, this);
result |= eval;
}
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public Attribute getAttribute(String attributeName) throws TorqueException
{
Attribute result = null;
List<Attribute> attributes = this.getIssueType().getActiveAttributes(getModule());
Iterator<Attribute> iter = attributes.iterator();
while(iter.hasNext())
{
Attribute attrib = iter.next();
String attribName = attrib.getName();
if(attribName.equals(attributeName))
{
result = attrib;
break;
}
}
return result;
}
// in java/org/tigris/scarab/om/Issue.java
public SkipFiltering createIssueChecker(String setMarkerFunction, int indent) throws TorqueException, ScarabException
{
return mystate.createIssueChecker(setMarkerFunction, indent);
}
// in java/org/tigris/scarab/om/Issue.java
public boolean isSealed() throws TorqueException
{
return mystate.isSealed();
}
// in java/org/tigris/scarab/om/Issue.java
public boolean isOnHold() throws TorqueException
{
return mystate.isOnHold();
}
// in java/org/tigris/scarab/om/Issue.java
public Attribute getMyStatusAttribute() throws TorqueException
{
return mystate.getStatusAttribute();
}
// in java/org/tigris/scarab/om/Issue.java
public Attribute getMyOnHoldExpirationDate() throws TorqueException
{
return mystate.getOnHoldExpirationDate();
}
// in java/org/tigris/scarab/om/Issue.java
public Date getOnHoldUntil() throws TorqueException, ParseException
{
return mystate.getOnHoldUntil();
}
// in java/org/tigris/scarab/om/ActivitySet.java
public void setActivityList(List activityList)
throws TorqueException
{
for (Iterator itr = activityList.iterator();itr.hasNext();)
{
Activity activity = (Activity) itr.next();
activity.setActivitySet(this);
activity.save();
}
ScarabCache.put(activityList, this, GET_ACTIVITY_LIST);
}
// in java/org/tigris/scarab/om/ActivitySet.java
public List getActivityList(Issue issue) throws TorqueException
{
List activityList = (List)ActivitySetManager.getMethodResult()
.get(this, GET_ACTIVITY_LIST, issue );
if(activityList==null)
{
Criteria crit = new Criteria()
.add(ActivityPeer.TRANSACTION_ID, getActivitySetId())
.add(ActivityPeer.ISSUE_ID, issue.getIssueId());
activityList = ActivityPeer.doSelect(crit);
ActivitySetManager.getMethodResult()
.put(activityList, this, GET_ACTIVITY_LIST, issue );
}
return activityList;
}
// in java/org/tigris/scarab/om/ActivitySet.java
public ScarabUser getCreator()
throws TorqueException
{
return getScarabUser();
}
// in java/org/tigris/scarab/om/ActivitySet.java
public String getActivityReason() throws TorqueException
{
Attachment attachment = this.getAttachment();
return attachment!=null ? attachment.getData() : "";
}
// in java/org/tigris/scarab/om/ActivitySet.java
public Set getRemovedUsers(Issue changedIssue) throws TorqueException
{
Set removedUsers = new HashSet();
for (Iterator it = getActivityList(changedIssue).iterator(); it.hasNext(); )
{
Activity act = (Activity)it.next();
if(act.getOldUserId() != null && act.getNewUserId() == null)
{
ScarabUser removedUser = ScarabUserManager.getInstance(act.getOldUserId());
removedUsers.add(removedUser);
}
}
return removedUsers;
}
// in java/org/tigris/scarab/om/ActivitySet.java
public boolean hasTransitionSealed() throws ScarabException, TorqueException
{
boolean result = false;
String status = Environment.getConfigurationProperty("scarab.common.status.id", null);
if (status != null)
{
String value = Environment.getConfigurationProperty("scarab.common.status.sealed", null);
if(value != null)
{
List<Activity> activities = getActivityList();
if (activities != null)
{
Iterator<Activity> iter = activities.iterator();
if (iter != null)
{
Activity act = null;
try
{
while((act = iter.next()) != null)
{
ActivityType at = ActivityType.getActivityType(act.getActivityType());
if(at == ActivityType.ATTRIBUTE_CHANGED)
{
Attribute att = act.getAttribute();
String name = att.getName();
if(name.equals(status))
{
String oldv = act.getOldValue();
String newv = act.getNewValue();
if(value.equals(oldv) || value.equals(newv))
{
result = true;
break;
}
}
}
}
}
catch (NoSuchElementException nsee)
{
Throwable th = new Throwable("No such element exception occured.(ignore and assume transitionToSealed=false)");
th.printStackTrace();
result = false;
}
}
}
}
}
return result;
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
protected List getRModuleUserAttributes(Criteria crit)
throws TorqueException
{
return getPrivateRModuleUserAttributes(crit);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public boolean hasPermission(String perm, Module module)
throws TorqueException
{
return hasPrivatePermission(perm, module);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
protected void deleteRModuleUserAttribute(final RModuleUserAttribute rmua)
throws TorqueException, TurbineSecurityException
{
privateDeleteRModuleUserAttribute(rmua);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
private List getPrivateRModuleUserAttributes(Criteria crit)
throws TorqueException
{
return getRModuleUserAttributes(crit);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
private boolean hasPrivatePermission(String perm, Module module)
throws TorqueException
{
return hasPermission(perm, module);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
private void privateDeleteRModuleUserAttribute(final RModuleUserAttribute rmua)
throws TorqueException, TurbineSecurityException
{
rmua.delete(this);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public boolean hasPermission(String perm, Module module)
throws TorqueException
{
if (perm.equals(ScarabSecurity.USER__CHANGE_PASSWORD) && isUserAnonymous())
{
return false;
}
if (module == null || ScarabSecurity.DOMAIN__ADMIN.equals(perm) || ScarabSecurity.DOMAIN__EDIT.equals(perm))
{
module = ModuleManager.getInstance(Module.ROOT_ID);
}
AccessControlList aclAnonymous = null;
if (ScarabUserManager.anonymousAccessAllowed())
{
aclAnonymous = ScarabUserManager.getAnonymousUser().getACL();
}
boolean hasPermission = false;
AccessControlList acl = this.getACL();
if (acl != null)
{
hasPermission = aclHasPermission(acl, perm, module);
}
if (!hasPermission && aclAnonymous != null)
{
hasPermission = aclHasPermission(aclAnonymous, perm, module);
}
return hasPermission;
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public boolean hasPermission(String perm, List modules) throws TorqueException
{
return internalUser.hasPermission(perm, modules);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public List getModules() throws TorqueException
{
return internalUser.getModules();
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public List getModules(boolean showDeletedModules)
throws TorqueException
{
return internalUser.getModules(showDeletedModules);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public Module[] getModules(String permission) throws TorqueException
{
return internalUser.getModules(permission);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public List getCopyToModules(Module currentModule) throws TorqueException
{
return internalUser.getCopyToModules(currentModule);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public List getCopyToModules(Module currentModule, String action) throws TorqueException
{
return internalUser.getCopyToModules(currentModule, action, null);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public List getCopyToModules(Module currentModule, String action,
String searchString)
throws TorqueException
{
return internalUser.getCopyToModules(currentModule, action, searchString);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public boolean hasAnyRoleIn(Module module)
throws TorqueException
{
return getRoles(module).size() != 0;
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
private List getRoles(Module module)
throws TorqueException
{
List result = null;
Object obj = ScarabCache.get(this, GET_ROLES, module);
if (obj == null)
{
Criteria crit = new Criteria();
crit.setDistinct();
crit.add(TurbineUserGroupRolePeer.USER_ID, getUserId());
crit.add(TurbineUserGroupRolePeer.GROUP_ID, module.getModuleId());
crit.addJoin(TurbineRolePeer.ROLE_ID,
TurbineUserGroupRolePeer.ROLE_ID);
result = TurbineRolePeer.doSelect(crit);
ScarabCache.put(result, this, GET_ROLES, module);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public void createNewUser()
throws TorqueException, DataBackendException, EntityExistsException
{
// get a unique id for validating the user
final String uniqueId = RandomStringUtils
.randomAlphanumeric(UNIQUE_ID_MAX_LEN);
// add it to the perm table
setConfirmed(uniqueId);
TurbineSecurity.addUser (this, getPassword());
setPasswordExpire();
// add any roles the anonymous user has, if she is enabled.
if(ScarabUserManager.anonymousAccessAllowed())
{
final ScarabUserImpl anonymous = (ScarabUserImpl) ScarabUserManager.getAnonymousUser();
final List/*<ScarabModule>*/ modules = anonymous.getNonGlobalModules();
for(Iterator it0 = modules.iterator(); it0.hasNext(); )
{
final ScarabModule module = (ScarabModule)it0.next();
final List/*<Roles>*/ roles = anonymous.getRoles(module);
for(Iterator it1 = roles.iterator(); it1.hasNext(); )
{
try
{
final Role role = (Role) it1.next();
TurbineSecurity.grant(this, (Group) module, role);
// TODO: Needs to be refactored into the Users system?
ScarabUserManager.getMethodResult()
.remove(this, ScarabUserManager.GET_ACL);
ScarabUserManager.getMethodResult()
.remove(this, ScarabUserManager.HAS_ROLE_IN_MODULE, (Serializable) role, module);
}catch (UnknownEntityException ex) {
Log.get().error("tried to copy unknown role from anonymous user: " + ex);
}
}
}
}
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public List getEditableModules() throws TorqueException
{
return internalUser.getEditableModules();
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public List getEditableModules(Module currEditModule)
throws TorqueException
{
return internalUser.getEditableModules(currEditModule);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public List getNonGlobalModules() throws TorqueException
{
List modules = new ArrayList();
for (Iterator it = internalUser.getModules().iterator(); it.hasNext(); )
{
Module m = (Module)it.next();
if (!m.isGlobalModule())
{
modules.add(m);
}
}
return modules;
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public List getRModuleUserAttributes(Module module,
IssueType issueType)
throws TorqueException
{
return internalUser.getRModuleUserAttributes(module, issueType);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public RModuleUserAttribute getRModuleUserAttribute(final Module module,
final Attribute attribute,
final IssueType issueType)
throws TorqueException, ScarabException
{
return internalUser
.getRModuleUserAttribute(module, attribute, issueType);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public void setPasswordExpire()
throws TorqueException
{
String expireDays = Turbine.getConfiguration()
.getString("scarab.login.password.expire", null);
if (expireDays == null || expireDays.trim().length() == 0)
{
setPasswordExpire(null);
}
else
{
Calendar expireDate = Calendar.getInstance();
expireDate.add(Calendar.DATE, Integer.parseInt(expireDays));
setPasswordExpire(expireDate);
}
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public void setPasswordExpire(Calendar expire)
throws TorqueException
{
Integer userid = getUserId();
if (userid == null)
{
throw new TorqueException("Userid cannot be null"); //EXCEPTION
}
UserPreference up = UserPreferenceManager.getInstance(getUserId());
if (expire == null)
{
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 10);
up.setPasswordExpire(cal.getTime());
}
else
{
up.setPasswordExpire(expire.getTime());
}
up.save();
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public boolean isPasswordExpired()
throws TorqueException
{
// Password for anonymous never expires.
if (isUserAnonymous())
{
return false;
}
final Integer userid = getUserId();
if (userid == null)
{
return false; // throw new ScarabException (L10NKeySet.ExceptionGeneral,"Userid cannot be null"); //EXCEPTION
}
final Criteria crit = new Criteria();
crit.add(UserPreferencePeer.USER_ID, userid);
final Calendar cal = Calendar.getInstance();
crit.add(UserPreferencePeer.PASSWORD_EXPIRE,
cal.getTime() , Criteria.LESS_THAN);
final List result = UserPreferencePeer.doSelect(crit);
return result.size() == 1 ? true : false;
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public boolean isUserAnonymous()
throws TorqueException
{
boolean brdo = false;
String anonymous = ScarabUserManager.getAnonymousUserName();
if (ScarabUserManager.anonymousAccessAllowed() &&
anonymous != null && getUserName().equals(anonymous))
{
brdo = true;
}
return brdo;
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public int getEnterIssueRedirect()
throws TorqueException
{
return internalUser.getEnterIssueRedirect();
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public void setEnterIssueRedirect(int templateCode)
throws TorqueException
{
internalUser.setEnterIssueRedirect(templateCode);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public String getDefaultQueryId(Module module) throws TorqueException
{
return internalUser.getDefaultQueryId(module);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public void setHomePage(String homePage)
throws TorqueException, ScarabException
{
internalUser.setHomePage(homePage);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public List getMITLists()
throws TorqueException
{
return internalUser.getMITLists();
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public boolean hasAnySearchableRMITs()
throws TorqueException, DataSetException
{
return internalUser.hasAnySearchableRMITs();
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public List getSearchableRMITs(String searchField, String searchString,
String sortColumn, String sortPolarity,
Module skipModule)
throws TorqueException
{
return internalUser.getSearchableRMITs(searchField, searchString,
sortColumn, sortPolarity, skipModule);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public List getUnusedRModuleIssueTypes(Module module)
throws TorqueException
{
return internalUser.getUnusedRModuleIssueTypes(module);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public List getAllRModuleIssueTypes(Module module)
throws TorqueException
{
return internalUser.getAllRModuleIssueTypes(module);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public void addRMITsToCurrentMITList(List rmits)
throws TorqueException
{
internalUser.addRMITsToCurrentMITList(rmits);
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public RModuleIssueType getCurrentRModuleIssueType()
throws TorqueException
{
return internalUser.getCurrentRModuleIssueType();
}
// in java/org/tigris/scarab/om/ScarabUserImpl.java
public void updateIssueListAttributes(List attributes)
throws TorqueException
{
internalUser.updateIssueListAttributes(attributes);
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public boolean hasPermission(String perm, List modules) throws TorqueException
{
boolean hasPerm = false;
if (modules != null && !modules.isEmpty())
{
hasPerm = true;
Iterator i = modules.iterator();
while (i.hasNext() && hasPerm)
{
hasPerm = hasPermission(perm, (Module)i.next());
}
}
return hasPerm;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public List getEditableModules()
throws TorqueException
{
return getEditableModules(null);
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public List getCopyToModules(Module currentModule, String action,
String searchString)
throws TorqueException
{
List copyToModules = new ArrayList();
if (hasPermission(ScarabSecurity.ISSUE__MOVE, currentModule)
|| "copy".equals(action))
{
Module[] userModules = getModules(ScarabSecurity.ISSUE__ENTER);
for (int i=0; i<userModules.length; i++)
{
Module module = userModules[i];
if (!module.isGlobalModule() &&
(searchString == null || searchString.equals("") ||
module.getName().indexOf(searchString) != -1))
{
copyToModules.add(module);
}
}
}
else if (hasPermission(ScarabSecurity.ISSUE__EDIT, currentModule)
&& currentModule.getIssueTypes().size() > 1)
{
copyToModules.add(currentModule);
}
return copyToModules;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public List getCopyToModules(Module currentModule)
throws TorqueException
{
return getCopyToModules(currentModule, "copy", null);
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public List getCopyToModules(Module currentModule, String action)
throws TorqueException
{
return getCopyToModules(currentModule, action, null);
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public List getEditableModules(Module currEditModule)
throws TorqueException
{
List userModules = getModules(true);
List editModules = new ArrayList();
if (currEditModule != null && currEditModule.getParent().getModuleId().intValue() != 0)
{
editModules.add(currEditModule.getParent());
}
for (int i=0; i<userModules.size(); i++)
{
Module module = (Module)userModules.get(i);
Module parent = module.getParent();
if (!editModules.contains(module) && parent != currEditModule)
{
if (hasPermission(ScarabSecurity.MODULE__EDIT, module) && module.getModuleId().intValue() != 0)
{
editModules.add(module);
}
}
}
// we want to remove the module we are editing
if (currEditModule != null && editModules.contains(currEditModule))
{
editModules.remove(currEditModule);
}
return editModules;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public List getRModuleUserAttributes(Module module,
IssueType issueType)
throws TorqueException
{
List result = null;
Object obj = ScarabCache.get(this, GET_R_MODULE_USERATTRIBUTES,
module, issueType);
if (obj == null)
{
Integer moduleId = module.getModuleId();
Integer userId = getUserId();
Integer issueTypeId = issueType.getIssueTypeId();
Criteria crit = new Criteria()
.add(RModuleUserAttributePeer.USER_ID, userId)
.add(RModuleUserAttributePeer.MODULE_ID, moduleId)
.add(RModuleUserAttributePeer.ISSUE_TYPE_ID, issueTypeId)
.addAscendingOrderByColumn(RModuleUserAttributePeer.PREFERRED_ORDER);
result = getRModuleUserAttributes(crit);
ScarabCache.put(result, this, GET_R_MODULE_USERATTRIBUTES,
module, issueType);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public RModuleUserAttribute getRModuleUserAttribute(final Module module,
final Attribute attribute,
final IssueType issueType)
throws TorqueException, ScarabException
{
RModuleUserAttribute result = null;
final Object obj = ScarabCache.get(this, GET_R_MODULE_USERATTRIBUTE,
module, attribute, issueType);
if (obj == null)
{
final Criteria crit = new Criteria(4)
.add(RModuleUserAttributePeer.USER_ID, getUserId())
.add(RModuleUserAttributePeer.ATTRIBUTE_ID,
attribute.getAttributeId())
.add(RModuleUserAttributePeer.LIST_ID, null);
if (module == null)
{
crit.add(RModuleUserAttributePeer.MODULE_ID, null);
}
else
{
crit.add(RModuleUserAttributePeer.MODULE_ID,
module.getModuleId());
}
if (issueType == null)
{
crit.add(RModuleUserAttributePeer.ISSUE_TYPE_ID, null);
}
else
{
crit.add(RModuleUserAttributePeer.ISSUE_TYPE_ID,
issueType.getIssueTypeId());
}
final List muas = RModuleUserAttributePeer.doSelect(crit);
if (muas.size() == 1)
{
result = (RModuleUserAttribute)muas.get(0);
}
else if (muas.isEmpty())
{
result =
getNewRModuleUserAttribute(attribute, module, issueType);
}
else
{
throw new ScarabException(L10NKeySet.ExceptionMultipleJDMs);
}
ScarabCache.put(result, this, GET_R_MODULE_USERATTRIBUTE,
module, attribute, issueType);
}
else
{
result = (RModuleUserAttribute)obj;
}
return result;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
protected RModuleUserAttribute getNewRModuleUserAttribute(
Attribute attribute, Module module, IssueType issueType)
throws TorqueException
{
RModuleUserAttribute result = RModuleUserAttributeManager.getInstance();
result.setUserId(getUserId());
result.setAttributeId(attribute.getAttributeId());
if (module != null)
{
result.setModuleId(module.getModuleId());
}
if (issueType != null)
{
result.setIssueTypeId(issueType.getIssueTypeId());
}
return result;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public int getEnterIssueRedirect()
throws TorqueException
{
if (enterIssueRedirect == 0)
{
UserPreference up = UserPreferenceManager.getInstance(getUserId());
if (up != null && up.getEnterIssueRedirect() != 0)
{
enterIssueRedirect = up.getEnterIssueRedirect();
}
}
return enterIssueRedirect;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public void setEnterIssueRedirect(int templateCode)
throws TorqueException
{
UserPreference up = UserPreferenceManager.getInstance(getUserId());
up.setEnterIssueRedirect(templateCode);
up.save();
enterIssueRedirect = templateCode;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public String getDefaultQueryId(Module module) throws TorqueException
{
String homePage = getHomePage(module);
String result;
if(homePage.equals("IssueList.vm"))
{
Query q = QueryPeer.getDefaultQuery(module, this.getUserId());
if(q != null)
{
homePage="IssueList.vm";
long cnt = (q.getQueryId());
return Long.toString(cnt);
}
}
return "";
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
private boolean isHomePageValid(String homePage, Module module) throws TorqueException
{
boolean result = true;
String perm = ScarabSecurity
.getScreenPermission(homePage.replace(',','.'));
if (perm != null && !hasPermission(perm, module))
{
result = false;
}
return result;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public void setHomePage(final String homePage)
throws TorqueException, ScarabException
{
if ("ModuleNotReady.vm".equals(homePage))
{
throw new ScarabException(L10NKeySet.ExceptionForbiddenHomeModuleNotReady);
}
final UserPreference up = UserPreferenceManager.getInstance(getUserId());
up.setHomePage(homePage);
up.save();
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public List getMITLists()
throws TorqueException
{
List result = null;
Criteria crit = new Criteria();
crit.add(MITListPeer.ACTIVE, true);
Criteria.Criterion userCrit = crit.getNewCriterion(
MITListPeer.USER_ID, getUserId(), Criteria.EQUAL);
//userCrit.or(crit.getNewCriterion(
// MITListPeer.USER_ID, null, Criteria.EQUAL));
crit.add(userCrit);
crit.add(MITListPeer.MODIFIABLE, true);
crit.add(MITListPeer.ACTIVE, true);
crit.add(MITListPeer.NAME, (Object)null, Criteria.NOT_EQUAL);
crit.addAscendingOrderByColumn(MITListPeer.NAME);
result = MITListPeer.doSelect(crit);
return result;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public boolean hasAnySearchableRMITs()
throws TorqueException, DataSetException
{
boolean result = false;
final List moduleIds = getSearchableModuleIds();
if (!moduleIds.isEmpty())
{
final Criteria crit = new Criteria();
crit.addIn(RModuleIssueTypePeer.MODULE_ID, moduleIds);
result = (RModuleIssueTypePeer.count(crit) > 0);
}
return result;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
private List getSearchableModuleIds()
throws TorqueException
{
Module[] userModules = getModules(ScarabSecurity.ISSUE__SEARCH);
List moduleIds;
if (userModules != null && (userModules.length > 1 ||
userModules.length == 1 && !userModules[0].isGlobalModule())
)
{
moduleIds = new ArrayList(userModules.length);
for (int i=0; i<userModules.length; i++)
{
Module module = userModules[i];
if (!module.isGlobalModule())
{
moduleIds.add(module.getModuleId());
}
}
}
else
{
moduleIds = Collections.EMPTY_LIST;
}
return moduleIds;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public List getUnusedRModuleIssueTypes(Module module)
throws TorqueException
{
List result;
if(module == null)
{
result = Collections.EMPTY_LIST;
}
else
{
Criteria crit = new Criteria();
crit.add(RModuleIssueTypePeer.MODULE_ID, module.getModuleId())
.addJoin(RModuleIssueTypePeer.ISSUE_TYPE_ID,
IssueTypePeer.ISSUE_TYPE_ID)
.add(IssueTypePeer.PARENT_ID, 0)
.add(IssueTypePeer.DELETED, false);
addCurrentMITListExclusion(crit);
result = RModuleIssueTypePeer.doSelect(crit);
}
return result;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public List getAllRModuleIssueTypes(Module module)
throws TorqueException
{
List result;
if(module == null)
{
result = Collections.EMPTY_LIST;
}
else
{
Criteria crit = new Criteria();
crit.add(RModuleIssueTypePeer.MODULE_ID, module.getModuleId())
.addJoin(RModuleIssueTypePeer.ISSUE_TYPE_ID,
IssueTypePeer.ISSUE_TYPE_ID)
.add(IssueTypePeer.PARENT_ID, 0)
.add(IssueTypePeer.DELETED, false);
result = RModuleIssueTypePeer.doSelect(crit);
}
return result;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
private void addCurrentMITListExclusion(Criteria crit)
throws TorqueException
{
// do not include RMIT's related to current MITListItems.
MITList mitList = getCurrentMITList(getGenThreadKey());
if (mitList != null && mitList.getMITListItems() != null
&& !mitList.getMITListItems().isEmpty())
{
boolean addAnd = false;
StringBuffer sb = new StringBuffer();
Iterator mitItems =
mitList.getExpandedMITListItems().iterator();
while (mitItems.hasNext())
{
MITListItem item = (MITListItem)mitItems.next();
if (mitList.getModule(item) != null
&& item.getIssueType() != null)
{
if (addAnd)
{
sb.append(" AND ");
}
sb.append(" NOT (")
.append(RModuleIssueTypePeer.MODULE_ID)
.append('=')
.append(mitList.getModule(item).getModuleId())
.append(" AND ")
.append(RModuleIssueTypePeer.ISSUE_TYPE_ID)
.append('=')
.append(item.getIssueType().getIssueTypeId())
.append(')');
addAnd = true;
}
}
// the column name used here is arbitrary (within limits)
crit.add(IssueTypePeer.ISSUE_TYPE_ID,
(Object)sb.toString(), Criteria.CUSTOM);
}
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public List getSearchableRMITs(String searchField, String searchString,
String sortColumn, String sortPolarity,
Module skipModule)
throws TorqueException
{
List moduleIds = getSearchableModuleIds();
if (skipModule != null)
{
moduleIds.remove(skipModule.getModuleId());
}
List result;
if (moduleIds.isEmpty())
{
result = Collections.EMPTY_LIST;
}
else
{
Criteria crit = new Criteria();
crit.addIn(RModuleIssueTypePeer.MODULE_ID, moduleIds);
crit.addJoin(RModuleIssueTypePeer.ISSUE_TYPE_ID,
IssueTypePeer.ISSUE_TYPE_ID);
crit.add(IssueTypePeer.PARENT_ID, 0);
crit.add(IssueTypePeer.DELETED, false);
addCurrentMITListExclusion(crit);
// we could add the filter criteria here, but this might
// result in full table scans. Even if the table scan turns out
// to be more efficient, I think it is better to move this
// into the middle/front tier.
//addFilterCriteria(crit, searchField, searchString);
//addSortCriteria(crit, sortColumn, sortPolarity);
result = RModuleIssueTypePeer.doSelect(crit);
filterRMITList(result, searchField, searchString);
sortRMITList(result, sortColumn, sortPolarity);
}
return result;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
protected void filterRMITList(List rmits,
String searchField, String searchString)
throws TorqueException
{
String moduleName = null;
String issueTypeName = null;
if ("issuetype".equals(searchField))
{
issueTypeName = searchString;
}
else
{
moduleName = searchString;
}
if (moduleName != null && moduleName.length() > 0)
{
for (int i=rmits.size()-1; i>=0; i--)
{
String name = ((RModuleIssueType)rmits.get(i))
.getModule().getRealName();
if (name == null || name.indexOf(moduleName) == -1)
{
rmits.remove(i);
}
}
}
if (issueTypeName != null && issueTypeName.length() > 0)
{
for (int i=rmits.size()-1; i>=0; i--)
{
String name = ((RModuleIssueType)rmits.get(i))
.getDisplayName();
if (name == null || name.indexOf(issueTypeName) == -1)
{
rmits.remove(i);
}
}
}
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public void addRMITsToCurrentMITList(List rmits)
throws TorqueException
{
if (rmits != null && !rmits.isEmpty())
{
MITList mitList = getCurrentMITList(getGenThreadKey());
if (mitList == null)
{
mitList = MITListManager.getInstance();
setCurrentMITList(mitList);
}
Iterator i = rmits.iterator();
while (i.hasNext())
{
RModuleIssueType rmit = (RModuleIssueType)i.next();
MITListItem item = MITListItemManager.getInstance();
item.setModuleId(rmit.getModuleId());
item.setIssueTypeId(rmit.getIssueTypeId());
if (!mitList.contains(item))
{
mitList.addMITListItem(item);
}
}
}
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public RModuleIssueType getCurrentRModuleIssueType()
throws TorqueException
{
RModuleIssueType rmit = null;
Module module = getCurrentModule();
if (module != null)
{
IssueType it = getCurrentIssueType();
if (it != null)
{
rmit = module.getRModuleIssueType(it);
}
}
return rmit;
}
// in java/org/tigris/scarab/om/AbstractScarabUser.java
public void updateIssueListAttributes(List attributes)
throws TorqueException
{
MITList mitList = getCurrentMITList();
// Delete current attribute selections for user
for (Iterator currentAttributes = mitList.getSavedRMUAs().iterator();
currentAttributes.hasNext();)
{
RModuleUserAttribute rmua = (RModuleUserAttribute)currentAttributes.next();
Criteria crit = new Criteria();
crit.add(RModuleUserAttributePeer.MODULE_ID, rmua.getModuleId());
crit.add(RModuleUserAttributePeer.ISSUE_TYPE_ID, rmua.getIssueTypeId());
crit.add(RModuleUserAttributePeer.USER_ID, rmua.getUserId());
crit.add(RModuleUserAttributePeer.LIST_ID, rmua.getListId());
crit.add(RModuleUserAttributePeer.INTERNAL_ATTRIBUTE, rmua.getInternalAttribute());
RModuleUserAttributePeer.doDelete(crit);
}
int i = 1;
for (Iterator iter = attributes.iterator(); iter.hasNext();)
{
RModuleUserAttribute rmua = (RModuleUserAttribute)iter.next();
rmua.setOrder(i++);
rmua.setListId(mitList.getListId());
if (mitList.isSingleIssueType())
{
rmua.setIssueType(mitList.getIssueType());
}
if (mitList.isSingleModule())
{
rmua.setModule(mitList.getModule());
}
rmua.save();
}
}
// in java/org/tigris/scarab/om/Attachment.java
public void setTextFields(final ScarabUser user,
final Issue issue,
final Integer typeId)
throws TorqueException
{
setIssue(issue);
setTypeId(typeId);
setMimeType("text/plain");
//setCreatedDate(new Date());
setCreatedBy(user.getUserId());
}
// in java/org/tigris/scarab/om/Attachment.java
public void save(Connection dbCon)
throws TorqueException
{
if (getIssue().isNew())
{
throw new TorqueException("Cannot save an attachment before saving"
+ " the issue to which it is attached."); //EXCEPTION
}
// It would be better (from an oo perspective) to do this whenever
// setData is called, but we can't be sure the typeId will be
// set prior to setting the url, so we will do the check here.
setData(doMakeURLFromData());
// need to handle the case where we don't want to be smart
// and just set the dates to be whatever we want them
// to be (xml import!).
if (isNew() && (getCreatedDate() == null && getModifiedDate() == null))
{
Date now = new Date();
setCreatedDate(now);
setModifiedDate(now);
}
else if (isModified())
{
setModifiedDate(new Date());
}
super.save(dbCon);
try
{
FileItem file = getFile();
if (file != null)
{
File uploadFile =
new File(getRepositoryDirectory(),getRelativePath());
File parent = uploadFile.getParentFile();
if (!parent.exists())
{
mkdirs(parent);
}
file.write(uploadFile);
}
}
catch (Exception e)
{
throw new TorqueException(e); //EXCEPTION
}
}
// in java/org/tigris/scarab/om/Attachment.java
public boolean deletePhysicalAttachment()
throws TorqueException, ScarabException
{
File f = new File(getFullPath());
return f.delete();
}
// in java/org/tigris/scarab/om/Attachment.java
public String getRelativePath()
throws TorqueException,ScarabException
{
if (isNew())
{
throw new ScarabException(L10NKeySet.ExceptionPathNotSet);
}
String path = null;
String filename = getFileName();
if (filename != null)
{
// moduleId/(issue_IdCount/1000)/issueID_attID_filename
StringBuffer sb = new StringBuffer(30 + filename.length());
final Issue issue = getIssue();
sb.append("mod").append(issue.getModule().getQueryKey())
.append(File.separator)
.append(issue.getIdCount() / 1000)
.append(File.separator)
.append(issue.getUniqueId()).append('_')
.append(getQueryKey()).append('_')
.append(filename);
path = sb.toString();
}
return path;
}
// in java/org/tigris/scarab/om/Attachment.java
public String getFullPath()
throws TorqueException,ScarabException
{
String path = null;
final String relativePath = getRelativePath();
if (relativePath != null)
{
path = getRepositoryDirectory() + File.separator + relativePath;
}
return path;
}
// in java/org/tigris/scarab/om/Attachment.java
public void copyFileTo(final String path)
throws TorqueException, ScarabException, FileNotFoundException, IOException
{
copyFileFromTo(getFullPath(), path);
}
// in java/org/tigris/scarab/om/Attachment.java
public long getSize()
throws TorqueException, ScarabException
{
if (size== -1) {
Log.get(this.getClass().getName()).debug("getSize() reading attachment size from FileSystem");
final String path = getFullPath();
if (path != null) {
final File f = new File(getFullPath());
if (f!= null && f.exists()) {
size = f.length();
}
}
} else {
Log.get(this.getClass().getName()).debug("getSize() reading attachment size from cache");
}
return size;
}
// in java/org/tigris/scarab/om/Attachment.java
public Attachment copy() throws TorqueException
{
Attachment copyObj = AttachmentManager.getInstance();
copyObj.setIssueId(getIssueId());
copyObj.setTypeId(getTypeId());
copyObj.setName(getName());
copyObj.setData(getData());
copyObj.setFileName(getFileName());
copyObj.setMimeType(getMimeType());
copyObj.setModifiedBy(getModifiedBy());
copyObj.setCreatedBy(getCreatedBy());
copyObj.setModifiedDate(getModifiedDate());
copyObj.setCreatedDate(getCreatedDate());
copyObj.setDeleted(getDeleted());
return copyObj;
}
// in java/org/tigris/scarab/om/Attachment.java
public Activity getActivity() throws TorqueException
{
Activity activity = null;
Criteria crit = new Criteria()
.add(ActivityPeer.ATTACHMENT_ID, getAttachmentId());
List activities = ActivityPeer.doSelect(crit);
if (activities.size() > 0)
{
activity = (Activity)activities.get(0);
}
return activity;
}
// in java/org/tigris/scarab/om/ReportPeer.java
public static boolean exists(final String name)
throws TorqueException, ScarabException
{
return retrieveByName(name) != null;
}
// in java/org/tigris/scarab/om/ReportPeer.java
public static Report retrieveByName(final String name)
throws TorqueException, ScarabException
{
Report report = null;
final Criteria crit = new Criteria()
.add(NAME, name)
.add(DELETED, false);
final List reports = doSelect(crit);
if (reports.size() == 1)
{
report = (Report)reports.get(0);
}
else if (reports.size() > 1)
{
throw new ScarabException(L10NKeySet.ExceptionMultipleReports,
name);
}
return report;
}
// in java/org/tigris/scarab/om/ReportPeer.java
public static Report retrieveByPK(ObjectKey pk)
throws TorqueException
{
Report result = null;
Object obj = ScarabCache.get(REPORT_PEER, RETRIEVE_BY_PK, pk);
if (obj == null)
{
result = BaseReportPeer.retrieveByPK(pk);
ScarabCache.put(result, REPORT_PEER, RETRIEVE_BY_PK, pk);
}
else
{
result = (Report)obj;
}
return result;
}
// in java/org/tigris/scarab/om/DependManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap.get(DependPeer.DEPEND_ID);
notifyListeners(listeners, oldOm, om);
listeners = (List)listenersMap.get(DependPeer.OBSERVER_ID);
notifyListeners(listeners, oldOm, om);
listeners = (List)listenersMap.get(DependPeer.OBSERVED_ID);
notifyListeners(listeners, oldOm, om);
listeners = (List)listenersMap.get(DependPeer.DEPEND_TYPE_ID);
notifyListeners(listeners, oldOm, om);
listeners = (List)listenersMap.get(DependPeer.DELETED);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/RModuleOptionPeer.java
public static int count(Criteria crit)
throws TorqueException, DataSetException
{
crit.addSelectColumn(COUNT);
return ((Record)IssuePeer.doSelectVillageRecords(crit).get(0))
.getValue(1).asInt();
}
// in java/org/tigris/scarab/om/AttributeType.java
public AttributeClass getAttributeClass()
throws TorqueException
{
AttributeClass result = null;
Object obj = ScarabCache.get(this, GET_ATTRIBUTE_CLASS);
if (obj == null)
{
result = super.getAttributeClass();
ScarabCache.put(result, this, GET_ATTRIBUTE_CLASS);
}
else
{
result = (AttributeClass)obj;
}
return result;
}
// in java/org/tigris/scarab/om/AttributeType.java
public static AttributeType getInstance(final String attributeTypeName)
throws TorqueException, ScarabException
{
AttributeType result = null;
final Object obj = ScarabCache.get(ATTRIBUTETYPE, GET_INSTANCE,
attributeTypeName);
if (obj == null)
{
final Criteria crit = new Criteria();
crit.add(AttributeTypePeer.ATTRIBUTE_TYPE_NAME, attributeTypeName);
final List attributeTypes = AttributeTypePeer.doSelect(crit);
if(attributeTypes.size() > 1)
{
throw new ScarabException(L10NKeySet.ExceptionDuplicateAttributeTypeName,
attributeTypeName);
}
result = (AttributeType)attributeTypes.get(0);
ScarabCache.put(result, ATTRIBUTETYPE, GET_INSTANCE,
attributeTypeName);
}
else
{
result = (AttributeType)obj;
}
return result;
}
// in java/org/tigris/scarab/om/ScarabModulePeer.java
public static List getAllModules()
throws TorqueException
{
return doSelect(new Criteria());
}
// in java/org/tigris/scarab/om/Depend.java
public static Depend getInstance()
throws TorqueException
{
return DependManager.getInstance();
}
// in java/org/tigris/scarab/om/Depend.java
public Attachment getDescriptionAsAttachment(ScarabUser user, Issue issue)
throws TorqueException
{
if (description == null || description.length() == 0)
{
return null;
}
Attachment comment = AttachmentManager.getInstance();
comment.setTextFields(user, issue, Attachment.MODIFICATION__PK);
comment.setData(getDescription());
comment.setName("modification");
comment.save();
return comment;
}
// in java/org/tigris/scarab/om/Depend.java
public void setDependType(String type)
throws TorqueException
{
super.setDependType(DependTypeManager.getInstance(type));
}
// in java/org/tigris/scarab/om/Depend.java
public void setObserverUniqueId(String uniqueId)
throws TorqueException, ScarabException
{
if (getDefaultModule() == null)
{
throw new ScarabException( L10NKeySet.ExceptionDependInternalWorkflow,
"setDefaultModule()",
"setObserverUniqueId()");
}
Issue childIssue = IssueManager.getIssueById(uniqueId.trim());
if (childIssue == null)
{
String code = getDefaultModule().getCode();
uniqueId = code + uniqueId;
childIssue = IssueManager.getIssueById(uniqueId);
}
super.setObserverId(childIssue.getIssueId());
}
// in java/org/tigris/scarab/om/Depend.java
public void setProperties(Depend depend)
throws TorqueException
{
this.setObservedId(depend.getObservedId());
this.setObserverId(depend.getObserverId());
this.setTypeId(depend.getTypeId());
}
// in java/org/tigris/scarab/om/Depend.java
public void exchangeRoles() throws TorqueException
{
Long observerId = getObserverId();
Long observedId = getObservedId();
setObserverId(observedId);
setObservedId(observerId);
}
// in java/org/tigris/scarab/om/RAttributeAttributeGroup.java
public void delete() throws TorqueException
{
Criteria c = new Criteria()
.add(RAttributeAttributeGroupPeer.GROUP_ID, getGroupId())
.add(RAttributeAttributeGroupPeer.ATTRIBUTE_ID, getAttributeId());
RAttributeAttributeGroupPeer.doDelete(c);
}
// in java/org/tigris/scarab/om/IssueTemplateInfo.java
public boolean canDelete(ScarabUser user)
throws TorqueException
{
// can delete a template if they have delete permission
// Or if is their personal template
boolean hasPermission = user.hasPermission(ScarabSecurity.ITEM__DELETE, getIssue().getModule());
boolean isCreatedBySelf = user.getUserId().equals(getIssue().getCreatedBy().getUserId());
boolean hasScopePersonal = getScopeId().equals(Scope.PERSONAL__PK);
return (hasPermission || (isCreatedBySelf && hasScopePersonal));
}
// in java/org/tigris/scarab/om/IssueTemplateInfo.java
public boolean canEdit(ScarabUser user)
throws TorqueException
{
return canDelete(user);
}
// in java/org/tigris/scarab/om/IssueTemplateInfo.java
public void saveAndSendEmail(final ScarabUser user,
final Module module,
final TemplateContext context)
throws TorqueException, ScarabException
{
// If it's a module scoped template, user must have Item | Approve
// permission, Or its Approved field gets set to false
boolean success = true;
final Issue issue = IssueManager.getInstance(getIssueId());
// If it's a module template, user must have Item | Approve
// permission, or its Approved field gets set to false
if (getScopeId().equals(Scope.PERSONAL__PK)
|| user.hasPermission(ScarabSecurity.ITEM__APPROVE, module))
{
setApproved(true);
}
else
{
setApproved(false);
issue.save();
// Send Email to the people with module edit ability so
// that they can approve the new template
if (context != null)
{
final String template = Turbine.getConfiguration().
getString("scarab.email.requireapproval.template",
"RequireApproval.vm");
ScarabUser[] toUsers = module.getUsers(ScarabSecurity.MODULE__EDIT);
// if the module doesn't have any users, then we need to add at
// least ourselves...
if (toUsers.length == 0)
{
toUsers = new ScarabUser[1];
toUsers[0] = user;
}
final EmailContext ectx = new EmailContext();
ectx.setUser(user);
ectx.setModule(module);
ectx.setDefaultTextKey("NewTemplateRequiresApproval");
final String fromUser = "scarab.email.default";
try
{
Email.sendEmail(ectx,
module,
fromUser,
module.getSystemEmail(),
Arrays.asList(toUsers),
null, template);
}
catch(Exception e)
{
save(); // Not shure about this, but i think it's ok,
// because we already did an issue.save(), see above
throw new ScarabException(L10NKeySet.ExceptionGeneral,e);
}
}
}
save();
}
// in java/org/tigris/scarab/om/IssueTemplateInfo.java
public void approve(final ScarabUser user, final boolean approved)
throws TorqueException, ScarabException
{
final Module module = getIssue().getModule();
if (user.hasPermission(ScarabSecurity.ITEM__APPROVE, module))
{
setApproved(true);
if (!approved)
{
setScopeId(Scope.PERSONAL__PK);
}
save();
}
else
{
throw new ScarabException(L10NKeySet.YouDoNotHavePermissionToAction);
}
}
// in java/org/tigris/scarab/om/RAttributeAttributeGroupManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap
.get(RAttributeAttributeGroupPeer.GROUP_ID);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/RModuleIssueTypePeer.java
public static int count(Criteria crit)
throws TorqueException, DataSetException
{
crit.addSelectColumn(COUNT);
return ((Record)doSelectVillageRecords(crit).get(0))
.getValue(1).asInt();
}
// in java/org/tigris/scarab/om/DependTypeManager.java
public static DependType getInstance(String dependTypeName)
throws TorqueException
{
DependType result = null;
Object obj = ScarabCache.get(DEPENDTYPE, FIND_DEPENDTYPE_BY_NAME,
dependTypeName);
if (obj == null)
{
Criteria crit = new Criteria();
crit.add(DependTypePeer.DEPEND_TYPE_NAME, dependTypeName);
List dependTypes = DependTypePeer.doSelect(crit);
if (dependTypes == null || dependTypes.size() == 0)
{
throw new TorqueException("Invalid issue depend type: " +
dependTypeName); //EXCEPTION
}
result = (DependType)dependTypes.get(0);
ScarabCache.put(result, DEPENDTYPE, FIND_DEPENDTYPE_BY_NAME,
dependTypeName);
}
else
{
result = (DependType)obj;
}
return result;
}
// in java/org/tigris/scarab/om/DependTypeManager.java
public static DependType getInstanceById(String dependTypeId)
throws TorqueException
{
DependType result = null;
List dependTypes = getAll();
for(int index=0; index < dependTypes.size(); index++)
{
DependType entry = (DependType)dependTypes.get(index);
if(entry.getQueryKey().equals(dependTypeId))
{
result = entry;
break;
}
}
return result;
}
// in java/org/tigris/scarab/om/DependTypeManager.java
public static List getAll()
throws TorqueException
{
return getManager().getAllImpl();
}
// in java/org/tigris/scarab/om/DependTypeManager.java
public List getAllImpl()
throws TorqueException
{
List result = null;
Object obj = getMethodResult().get(this.toString(), GET_ALL);
if (obj == null)
{
result = DependTypePeer.doSelect(new Criteria());
getMethodResult().put(result, this.toString(), GET_ALL);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/DependTypeManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
getMethodResult().remove(this, GET_ALL);
return oldOm;
}
// in java/org/tigris/scarab/om/DependTypeManager.java
public L10NKey getL10nKey( String dependTypeName )
throws TorqueException
{
return (L10NKey)l10nKeys.get( getInstance(dependTypeName).getDependTypeId());
}
// in java/org/tigris/scarab/om/RModuleIssueType.java
public void setModule(Module me)
throws TorqueException
{
Integer id = me.getModuleId();
if (id == null)
{
throw new TorqueException("Modules must be saved prior to " +
"being associated with other objects."); //EXCEPTION
}
setModuleId(id);
}
// in java/org/tigris/scarab/om/RModuleIssueType.java
public Module getModule()
throws TorqueException
{
Module module = null;
Integer id = getModuleId();
if ( id != null )
{
module = ModuleManager.getInstance(id);
}
return module;
}
// in java/org/tigris/scarab/om/RModuleIssueType.java
public void delete(final ScarabUser user)
throws TorqueException, ScarabException
{
final Module module = getModule();
final IssueType issueType = getIssueType();
if (user.hasPermission(ScarabSecurity.MODULE__CONFIGURE, module))
{
// Delete both active and inactive attribute groups first
final List attGroups = issueType.getAttributeGroups(module, false);
for (int j=0; j<attGroups.size(); j++)
{
// delete attribute-attribute group map
final AttributeGroup attGroup =
(AttributeGroup)attGroups.get(j);
attGroup.delete();
}
// Delete mappings with user attributes
List rmas = module.getRModuleAttributes(issueType);
for (int i=0; i<rmas.size(); i++)
{
((RModuleAttribute)rmas.get(i)).delete();
}
// Delete mappings with user attributes for template type
final IssueType templateType = issueType.getTemplateIssueType();
rmas = module.getRModuleAttributes(templateType);
for (int i=0; i<rmas.size(); i++)
{
((RModuleAttribute)rmas.get(i)).delete();
}
// delete workflows
WorkflowFactory.getInstance().resetAllWorkflowsForIssueType(module,
issueType);
// delete templates
Criteria c = new Criteria()
.add(IssuePeer.TYPE_ID, templateType.getIssueTypeId());
final List result = IssuePeer.doSelect(c);
final List issueIdList = new ArrayList(result.size());
for (int i=0; i < result.size(); i++)
{
final Issue issue = (Issue)result.get(i);
issueIdList.add(issue.getIssueId());
}
IssuePeer.doDelete(c);
if (!issueIdList.isEmpty())
{
c = new Criteria()
.addIn(IssueTemplateInfoPeer.ISSUE_ID, issueIdList);
IssueTemplateInfoPeer.doDelete(c);
}
// mit list items
c = new Criteria()
.add(MITListItemPeer.MODULE_ID, module.getModuleId())
.add(MITListItemPeer.ISSUE_TYPE_ID, issueType.getIssueTypeId());
final List listItems = MITListItemPeer.doSelect(c);
final List listIds = new ArrayList(listItems.size());
for (int i=0; i < listItems.size(); i++)
{
final MITList list = ((MITListItem)listItems.get(i)).getMITList();
final Long listId = list.getListId();
if (list.isSingleModuleIssueType() && !listIds.contains(listId))
{
listIds.add(listId);
}
}
MITListItemPeer.doDelete(c);
if (!listIds.isEmpty())
{
// delete single module-issuetype mit lists
c = new Criteria()
.addIn(MITListPeer.LIST_ID, listIds);
MITListPeer.doDelete(c);
// delete queries
c = new Criteria()
.addIn(QueryPeer.LIST_ID, listIds);
QueryPeer.doDelete(c);
}
c = new Criteria()
.add(RModuleIssueTypePeer.MODULE_ID, getModuleId())
.add(RModuleIssueTypePeer.ISSUE_TYPE_ID, getIssueTypeId());
RModuleIssueTypePeer.doDelete(c);
RModuleIssueTypeManager.removeFromCache(this);
final List rmits = module.getRModuleIssueTypes();
rmits.remove(this);
}
else
{
throw new ScarabException(L10NKeySet.YouDoNotHavePermissionToAction);
}
}
// in java/org/tigris/scarab/om/RModuleIssueType.java
public RModuleIssueType copy()
throws TorqueException
{
RModuleIssueType rmit2 = new RModuleIssueType();
rmit2.setModuleId(getModuleId());
rmit2.setIssueTypeId(getIssueTypeId());
rmit2.setActive(getActive());
rmit2.setDisplay(getDisplay());
rmit2.setDisplayDescription(getDisplayDescription());
rmit2.setOrder(getOrder());
rmit2.setDedupe(getDedupe());
rmit2.setHistory(getHistory());
rmit2.setComments(getComments());
return rmit2;
}
// in java/org/tigris/scarab/om/RModuleIssueType.java
public List<Condition> getConditions(Criteria criteria) throws TorqueException
{
criteria.add(ConditionPeer.ATTRIBUTE_ID, (Object)(ConditionPeer.ATTRIBUTE_ID + " IS NULL"), Criteria.CUSTOM);
return super.getConditions(criteria);
}
// in java/org/tigris/scarab/om/RModuleIssueType.java
public void setConditionsArray(Integer[] aOptionId, Integer operator) throws TorqueException
{
Criteria crit = new Criteria();
crit.add(ConditionPeer.ATTRIBUTE_ID, null);
crit.add(ConditionPeer.MODULE_ID, this.getModuleId());
crit.add(ConditionPeer.ISSUE_TYPE_ID, this.getIssueTypeId());
crit.add(ConditionPeer.TRANSITION_ID, null);
ConditionPeer.doDelete(crit);
this.save();
this.getConditions().clear();
ConditionManager.clear();
if (aOptionId != null)
for (int i = 0; i < aOptionId.length; i++)
{
if (aOptionId[i].intValue() != 0)
{
Condition cond = new Condition();
cond.setAttributeId(null);
cond.setOptionId(aOptionId[i]);
cond.setModuleId(this.getModuleId());
cond.setIssueTypeId(this.getIssueTypeId());
cond.setTransitionId(null);
cond.setOperator(operator);
this.addCondition(cond);
cond.save();
}
}
}
// in java/org/tigris/scarab/om/RModuleIssueType.java
public boolean isRequiredIf(Integer optionID) throws TorqueException
{
Condition cond = new Condition();
cond.setAttributeId(null);
cond.setOptionId(optionID);
cond.setModuleId(this.getModuleId());
cond.setIssueTypeId(this.getIssueTypeId());
cond.setTransitionId(null);
return this.getConditions().contains(cond);
}
// in java/org/tigris/scarab/om/RModuleIssueType.java
public void addCondition(Condition cond) throws TorqueException
{
getConditions().add(cond);
cond.setRModuleIssueType(this);
}
// in java/org/tigris/scarab/om/RModuleIssueTypeManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap
.get(RModuleIssueTypePeer.MODULE_ID);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/RModuleIssueTypeManager.java
public static void removeFromCache(RModuleIssueType module)
throws TorqueException
{
ObjectKey key = module.getPrimaryKey();
getManager().removeInstanceImpl(key);
}
// in java/org/tigris/scarab/om/RModuleIssueTypeManager.java
public static RModuleIssueType getInstance(String key)
throws TorqueException
{
if (key == null)
{
throw new NullPointerException(
"Cannot request a RModuleIssueType using a null key."); //EXCEPTION
}
int colonPos = key.indexOf(':');
if (colonPos == -1)
{
throw new IllegalArgumentException(
"RModuleIssueType keys must be of the form N1:N2, not " + key); //EXCEPTION
}
// { module_id, issue_type_id }
SimpleKey[] keyArray = { new NumberKey(key.substring(1, colonPos)),
new NumberKey(key.substring(colonPos+2, key.length()-1))
};
return getInstance(new ComboKey(keyArray));
}
// in java/org/tigris/scarab/om/AttributePeer.java
public static List getAttributes(String attributeType, boolean includeDeleted,
String sortColumn, String sortPolarity)
throws TorqueException
{
Serializable[] cacheKey = {ATTRIBUTE_PEER, GET_ATTRIBUTES, attributeType, Boolean.valueOf(includeDeleted),
sortColumn, sortPolarity};
List attributes = (List)AttributeManager.getMethodResult().get(cacheKey);
if(attributes==null)
{
Criteria crit = new Criteria();
crit.add(AttributePeer.ATTRIBUTE_ID, 0, Criteria.NOT_EQUAL);
if (!includeDeleted)
{
crit.add(AttributePeer.DELETED, 0);
}
if (attributeType.equals("user"))
{
crit.add(AttributePeer.ATTRIBUTE_TYPE_ID,
AttributeTypePeer.USER_TYPE_KEY);
}
else
{
crit.add(AttributePeer.ATTRIBUTE_TYPE_ID,
AttributeTypePeer.USER_TYPE_KEY, Criteria.NOT_EQUAL);
}
if (sortColumn.equals("desc"))
{
addSortOrder(crit, AttributePeer.DESCRIPTION,
sortPolarity);
}
else if (sortColumn.equals("date"))
{
addSortOrder(crit, AttributePeer.CREATED_DATE,
sortPolarity);
}
else if (sortColumn.equals("type"))
{
crit.addJoin(AttributePeer.ATTRIBUTE_TYPE_ID,
AttributeTypePeer.ATTRIBUTE_TYPE_ID);
addSortOrder(crit, AttributeTypePeer .ATTRIBUTE_TYPE_NAME,
sortPolarity);
}
else if (!sortColumn.equals("user"))
{
addSortOrder(crit, AttributePeer.ATTRIBUTE_NAME,
sortPolarity);
}
attributes = doSelect(crit);
if (sortColumn.equals("user"))
{
attributes = sortAttributesByCreatingUser(attributes, sortPolarity);
}
AttributeManager.getMethodResult().put(attributes, cacheKey);
}
return attributes;
}
// in java/org/tigris/scarab/om/AttributePeer.java
public static List getFilteredAttributes(String name, String description,
String searchField)
throws TorqueException
{
List result = null;
List allAttributes = getAttributes();
if (allAttributes == null || allAttributes.size() == 0)
{
result = Collections.EMPTY_LIST;
}
else
{
List attrIds = new ArrayList();
for (int i = 0; i < allAttributes.size(); i++)
{
attrIds.add(((Attribute)allAttributes.get(i)).getAttributeId());
}
Criteria crit = new Criteria();
crit.addIn(AttributePeer.ATTRIBUTE_ID, attrIds);
Criteria.Criterion c = null;
Criteria.Criterion c1 = null;
Criteria.Criterion c2 = null;
if (name != null)
{
c1 = crit.getNewCriterion(AttributePeer.ATTRIBUTE_NAME,
addWildcards(name), Criteria.LIKE);
}
if (description != null)
{
c2 = crit.getNewCriterion(AttributePeer.DESCRIPTION,
addWildcards(description), Criteria.LIKE);
}
if (searchField.equals("Name"))
{
c = c1;
}
else if (searchField.equals("Description"))
{
c = c2;
}
else if (searchField.equals("Any"))
{
c = c1.or(c2);
}
crit.and(c);
result = AttributePeer.doSelect(crit);
}
return result;
}
// in java/org/tigris/scarab/om/AttributePeer.java
public static List getAttributes()
throws TorqueException
{
return getAttributes(NON_USER, false, AttributePeer.ATTRIBUTE_NAME, "asc");
}
// in java/org/tigris/scarab/om/AttributePeer.java
public static List getAttributes(String attributeType)
throws TorqueException
{
return getAttributes(attributeType, false, AttributePeer.ATTRIBUTE_NAME,
"asc");
}
// in java/org/tigris/scarab/om/AttributePeer.java
public static List getAttributes(String attributeType, boolean includeDeleted)
throws TorqueException
{
return getAttributes(attributeType, includeDeleted, AttributePeer.ATTRIBUTE_NAME,
"asc");
}
// in java/org/tigris/scarab/om/AttributePeer.java
public static List getAttributes(String sortColumn,
String sortPolarity)
throws TorqueException
{
return getAttributes(NON_USER, false, sortColumn, sortPolarity);
}
// in java/org/tigris/scarab/om/AttributePeer.java
private static List sortAttributesByCreatingUser(List result,
String sortPolarity)
throws TorqueException
{
final int polarity = ("asc".equals(sortPolarity)) ? 1 : -1;
Comparator c = new Comparator()
{
public int compare(Object o1, Object o2)
{
int i = 0;
try
{
i = polarity *
((Attribute)o1).getCreatedUserName()
.compareTo(((Attribute)o2).getCreatedUserName());
}
catch (Exception e)
{
//
}
return i;
}
};
Collections.sort(result, c);
return result;
}
// in java/org/tigris/scarab/om/AttributeManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap.get(AttributePeer.ATTRIBUTE_ID);
notifyListeners(listeners, oldOm, om);
getMethodResult().removeAll(AttributePeer.ATTRIBUTE_PEER, AttributePeer.GET_ATTRIBUTES);
return oldOm;
}
// in java/org/tigris/scarab/om/AttributeValuePeer.java
public static int count(Criteria crit)
throws TorqueException, DataSetException
{
crit.addSelectColumn(COUNT);
return ((Record)AttributeValuePeer.doSelectVillageRecords(crit).get(0))
.getValue(1).asInt();
}
// in java/org/tigris/scarab/om/AttributeValuePeer.java
public static int countDistinct(Criteria crit)
throws TorqueException, DataSetException
{
crit.addSelectColumn(COUNT_DISTINCT);
return ((Record)AttributeValuePeer.doSelectVillageRecords(crit).get(0))
.getValue(1).asInt();
}
// in java/org/tigris/scarab/om/AttributeValuePeer.java
public static Class getOMClass(Record record, int offset)
throws TorqueException
{
Class c = null;
try
{
Integer attId = new Integer(record.getValue(offset-1 + 3)
.asString());
Attribute attribute = AttributeManager.getInstance(attId);
String className = attribute.getAttributeType().getJavaClassName();
c = (Class)classMap.get(className);
if (c == null)
{
c = Class.forName(className);
classMap.put(className, c);
}
}
catch (Exception e)
{
throw new TorqueException(e); //EXCEPTION
}
return c;
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public boolean isGlobal()
throws TorqueException
{
return (getModule() == null);
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public void setModule(Module me)
throws TorqueException
{
Integer id = me.getModuleId();
if ( id == null)
{
throw new TorqueException("Modules must be saved prior to " +
"being associated with other objects."); //EXCEPTION
}
setModuleId(id);
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public Module getModule()
throws TorqueException
{
Module module = null;
Integer id = getModuleId();
if ( id != null )
{
module = ModuleManager.getInstance(id);
}
return module;
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public boolean hasAnyOptionAttributes()
throws TorqueException
{
boolean result = false;
for (Iterator i = getAttributes().iterator(); i.hasNext() && !result;)
{
result = ((Attribute)i.next()).isOptionAttribute();
}
return result;
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public List getAttributes()
throws TorqueException
{
List result = null;
Object obj = getMethodResult().get(this, GET_ATTRIBUTES);
if (obj == null)
{
Log.get().debug("getAttributes() not cached, getting from db");
Criteria crit = new Criteria()
.add(RAttributeAttributeGroupPeer.GROUP_ID,
getAttributeGroupId())
.addJoin(RAttributeAttributeGroupPeer.ATTRIBUTE_ID,
AttributePeer.ATTRIBUTE_ID)
.add(AttributePeer.ATTRIBUTE_TYPE_ID,
AttributeTypePeer.USER_TYPE_KEY, Criteria.NOT_EQUAL)
.add(AttributePeer.DELETED, false)
.addAscendingOrderByColumn(RAttributeAttributeGroupPeer
.PREFERRED_ORDER);
List raags = RAttributeAttributeGroupPeer.doSelect(crit);
result = new LinkedList();
Iterator i = raags.iterator();
while (i.hasNext())
{
Integer id = ((RAttributeAttributeGroup)i.next())
.getAttributeId();
result.add(AttributeManager.getInstance(SimpleKey.keyFor(id)));
if (Log.get().isDebugEnabled())
{
Log.get().debug("attribute id=" + id +
"'s relationship to group was in db");
}
}
getMethodResult().put(result, this, GET_ATTRIBUTES);
}
else
{
result = (List)obj;
if (Log.get().isDebugEnabled())
{
Log.get().debug("getAttributes() returning cached value");
for (Iterator i = result.iterator(); i.hasNext();)
{
Log.get().debug("attribute id=" +
((Attribute)i.next()).getAttributeId() +
"'s relationship to group was in cache");
}
}
}
return result;
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public boolean hasAttribute(Attribute attribute)
throws TorqueException
{
List raags = getAttributes();
return (raags != null && raags.contains(attribute));
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public int getHighestOrderedAttribute ()
throws TorqueException
{
int highest = 0;
Criteria crit = new Criteria()
.add(RAttributeAttributeGroupPeer.GROUP_ID,
getAttributeGroupId())
.addAscendingOrderByColumn(RAttributeAttributeGroupPeer
.PREFERRED_ORDER);
List raags = RAttributeAttributeGroupPeer.doSelect(crit);
if (raags.size() > 0)
{
RAttributeAttributeGroup raag = (RAttributeAttributeGroup)
raags.get(raags.size()-1);
highest = raag.getOrder();
}
return highest + 1;
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public RAttributeAttributeGroup getRAttributeAttributeGroup
(Attribute attribute)
throws TorqueException
{
RAttributeAttributeGroup result = null;
Object obj = ScarabCache.get(this, GET_R_ATTRIBUTE_ATTRGROUP,
attribute);
if (obj == null)
{
Criteria crit = new Criteria()
.add(RAttributeAttributeGroupPeer.GROUP_ID,
getAttributeGroupId())
.add(RAttributeAttributeGroupPeer.ATTRIBUTE_ID,
attribute.getAttributeId());
List resultList = RAttributeAttributeGroupPeer.doSelect(crit);
if(resultList != null && resultList.size() > 0)
{
result = (RAttributeAttributeGroup)resultList.get(0);
ScarabCache.put(result, this, GET_R_ATTRIBUTE_ATTRGROUP,
attribute);
}
else
{
result = null;
}
}
else
{
result = (RAttributeAttributeGroup)obj;
}
return result;
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public List getRModuleAttributes()
throws TorqueException
{
List attrs = getAttributes();
Iterator i = attrs.iterator();
List rmas = new ArrayList(attrs.size());
while (i.hasNext())
{
Attribute attr = (Attribute)i.next();
RModuleAttribute rma = getModule().getRModuleAttribute(attr, getIssueType());
if (rma != null)
{
rmas.add(rma);
}
}
return rmas;
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public List getRIssueTypeAttributes()
throws TorqueException
{
List attrs = getAttributes();
Iterator i = attrs.iterator();
List rias = new ArrayList(attrs.size());
while (i.hasNext())
{
Attribute attr = (Attribute)i.next();
RIssueTypeAttribute ria =
getIssueType().getRIssueTypeAttribute(attr);
if (ria != null)
{
rias.add(ria);
}
}
return rias;
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public void delete()
throws TorqueException, ScarabException
{
int dupeSequence = 0;
final Integer issueTypeId = getIssueTypeId();
final IssueType issueType = IssueTypeManager
.getInstance(SimpleKey.keyFor(issueTypeId), false);
List attrGroups = null;
if (isGlobal())
{
attrGroups = issueType.getAttributeGroups(null, false);
dupeSequence = issueType.getDedupeSequence();
// Delete issuetype-attribute mapping
final Criteria crit = new Criteria()
.addJoin(RIssueTypeAttributePeer.ATTRIBUTE_ID,
RAttributeAttributeGroupPeer.ATTRIBUTE_ID)
.add(RAttributeAttributeGroupPeer.GROUP_ID,
getAttributeGroupId())
.add(RIssueTypeAttributePeer.ISSUE_TYPE_ID, issueTypeId);
final List results = RIssueTypeAttributePeer.doSelect(crit);
for (Iterator i = results.iterator(); i.hasNext();)
{
((RIssueTypeAttribute)i.next()).delete();
}
}
else
{
if (issueType.getLocked())
{
throw new ScarabException(L10NKeySet.ExceptionGroupDeleteForbidden,
this.getName(),
issueType.getName());
}
else
{
final Module module = getModule();
attrGroups = getIssueType().getAttributeGroups(module, false);
dupeSequence = module.getDedupeSequence(issueType);
// Delete module-attribute mapping
final Criteria crit = new Criteria()
.addJoin(RModuleAttributePeer.ATTRIBUTE_ID,
RAttributeAttributeGroupPeer.ATTRIBUTE_ID)
.add(RAttributeAttributeGroupPeer.GROUP_ID,
getAttributeGroupId())
.add(RModuleAttributePeer.MODULE_ID,
getModuleId());
final Criteria.Criterion critIssueType = crit.getNewCriterion(
RModuleAttributePeer.ISSUE_TYPE_ID,
getIssueTypeId(), Criteria.EQUAL);
critIssueType.or(crit.getNewCriterion(
RModuleAttributePeer.ISSUE_TYPE_ID,
issueType.getTemplateId(), Criteria.EQUAL));
crit.and(critIssueType);
final List results = RModuleAttributePeer.doSelect(crit);
for (int i=0; i<results.size(); i++)
{
final RModuleAttribute rma = (RModuleAttribute)results.get(i);
rma.delete();
}
}
}
// Delete attribute - attribute group mapping
Criteria crit2 = new Criteria()
.add(RAttributeAttributeGroupPeer.GROUP_ID, getAttributeGroupId());
RAttributeAttributeGroupPeer.doDelete(crit2);
// Delete the attribute group
final int order = getOrder();
crit2 = new Criteria()
.add(AttributeGroupPeer.ATTRIBUTE_GROUP_ID, getAttributeGroupId());
AttributeGroupPeer.doDelete(crit2);
IssueTypeManager.getManager().refreshedObject(this);
// Adjust the orders for the other attribute groups
for (int i=0; i<attrGroups.size(); i++)
{
final AttributeGroup tempGroup = (AttributeGroup)attrGroups.get(i);
int tempOrder = tempGroup.getOrder();
if (tempGroup.getOrder() > order)
{
if (tempOrder == dupeSequence + 1 && tempOrder == 3)
{
tempGroup.setOrder(tempOrder - 2);
}
else
{
tempGroup.setOrder(tempOrder - 1);
}
tempGroup.save();
}
}
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public void addAttribute(final Attribute attribute)
throws TorqueException, ScarabException
{
final IssueType issueType = getIssueType();
final Module module = getModule();
// add attribute group-attribute mapping
final RAttributeAttributeGroup raag =
addRAttributeAttributeGroup(attribute);
raag.save();
if (Log.get().isDebugEnabled())
{
Log.get().debug("Calling getAttributes() from addAttribute in order to add attribute id="
+ attribute.getAttributeId() + " to the List");
}
// FIXME! Distributed cache buster, cache should be invalidated.
final List attributes = getAttributes();
if (!attributes.contains(attribute))
{
attributes.add(attribute);
}
final List allOptions = attribute.getAttributeOptions(false);
// remove duplicate options
// FIXME! why would we ever want Attribute.getAttributeOptions to
// return dupes, should this code be in that method?
final ArrayList options = new ArrayList();
for (int i=0; i<allOptions.size(); i++)
{
final AttributeOption option = (AttributeOption)allOptions.get(i);
if (!options.contains(option))
{
options.add(option);
}
}
if (isGlobal())
{
// this is a global attribute group
// add issuetype-attribute groupings
issueType.addRIssueTypeAttribute(attribute);
// add issueType-attributeoption mappings
for (int j=0;j < options.size();j++)
{
final AttributeOption option = (AttributeOption)options.get(j);
final List roos = option.getROptionOptionsRelatedByOption2Id();
final ROptionOption roo = (ROptionOption)roos.get(0);
final RIssueTypeOption rio = new RIssueTypeOption();
rio.setIssueTypeId(issueType.getIssueTypeId());
rio.setOptionId(option.getOptionId());
rio.setOrder(roo.getPreferredOrder());
rio.setWeight(roo.getWeight());
// making sure error is recorded in same log as our other
// debugging for pcn 17683.
try
{
rio.save();
}
catch (TorqueException e)
{
Log.get().error("Exception saving rio", e);
throw e; //EXCEPTION
}
}
}
else
{
// add module-attribute groupings
module.addRModuleAttribute(issueType, attribute);
// add module-attributeoption mappings
for (int j=0;j < options.size();j++)
{
final AttributeOption option = (AttributeOption)options.get(j);
final List roos = option.getROptionOptionsRelatedByOption2Id();
final ROptionOption roo = (ROptionOption)roos.get(0);
final RModuleOption rmo = new RModuleOption();
rmo.setModuleId(getModuleId());
rmo.setIssueTypeId(issueType.getIssueTypeId());
rmo.setOptionId(option.getOptionId());
rmo.setDisplayValue(option.getName());
rmo.setOrder(roo.getPreferredOrder());
rmo.setWeight(roo.getWeight());
rmo.save();
// add module-attributeoption mappings to template type
final IssueType templateType = IssueTypeManager
.getInstance(issueType.getTemplateId(), false);
final RModuleOption rmo2 = module.
addRModuleOption(templateType, option);
rmo2.save();
}
}
getMethodResult().remove(this, AttributeGroup.GET_ATTRIBUTES);
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public void deleteAttribute(final Attribute attribute,
final ScarabUser user,
final Module module)
throws TorqueException, ScarabException
{
String permission = null;
if (isGlobal())
{
permission = (ScarabSecurity.DOMAIN__EDIT);
}
else
{
permission = (ScarabSecurity.MODULE__CONFIGURE);
}
if (user.hasPermission(permission, module))
{
final IssueType issueType = getIssueType();
final IssueType template = IssueTypeManager.getInstance
(issueType.getTemplateId());
boolean success = true;
final RIssueTypeAttribute ria = issueType.getRIssueTypeAttribute(attribute);
if (isGlobal())
{
// This is a global attribute group
// Remove attribute - issue type mapping
final List rias = issueType.getRIssueTypeAttributes
(false, AttributePeer.NON_USER);
if (ria != null)
{
ria.delete();
}
if (rias != null)
{
rias.remove(ria);
}
}
else
{
// Check if attribute is locked
if (ria != null && ria.getLocked())
{
success = false;
throw new TorqueException(attribute.getName() + "is locked"); //EXCEPTION
}
else
{
// Remove attribute - module mapping
final List rmas = module.getRModuleAttributes(issueType, false,
AttributePeer.NON_USER);
final RModuleAttribute rma = module
.getRModuleAttribute(attribute, issueType);
if(rma != null)rma.delete();
WorkflowFactory.getInstance().deleteWorkflowsForAttribute
(attribute, module, issueType);
if(rma != null)rmas.remove(rma);
// Remove attribute - module mapping from template type
final RModuleAttribute rma2 = module
.getRModuleAttribute(attribute, template);
if(rma2 != null)
{
rma2.delete();
rmas.remove(rma2);
}
}
}
if (success)
{
// Remove attribute - group mapping
final RAttributeAttributeGroup raag =
getRAttributeAttributeGroup(attribute);
raag.delete();
if (attribute.isOptionAttribute())
{
if (isGlobal())
{
// global attributeGroup; remove issuetype-option maps
final List rios = issueType.getRIssueTypeOptions(attribute);
if (rios != null)
{
for (int i = 0; i<rios.size();i++)
{
((RIssueTypeOption) rios.get(i))
.delete(user, module);
}
}
}
else
{
// Remove module-option mapping
final List rmos = module.getRModuleOptions(attribute, issueType);
if (rmos != null)
{
rmos.addAll(module.getRModuleOptions(attribute, template));
for (int j = 0; j<rmos.size();j++)
{
final RModuleOption rmo = (RModuleOption)rmos.get(j);
// rmo's may be inherited by the parent module.
// don't delete unless they are directly associated
// with this module. Will know by the first one.
if (rmo.getModuleId().equals(module.getModuleId()))
{
rmo.delete();
}
else
{
break;
}
}
}
}
}
}
}
else
{
throw new ScarabException(L10NKeySet.YouDoNotHavePermissionToAction);
}
getMethodResult().remove(this, AttributeGroup.GET_ATTRIBUTES);
}
// in java/org/tigris/scarab/om/AttributeGroup.java
private RAttributeAttributeGroup addRAttributeAttributeGroup(Attribute attribute)
throws TorqueException
{
RAttributeAttributeGroup raag = new RAttributeAttributeGroup();
raag.setGroupId(getAttributeGroupId());
raag.setAttributeId(attribute.getAttributeId());
if (Log.get().isDebugEnabled())
{
Log.get().debug("Calling getAttributes() from addRAttributeAttributeGroup "
+ "in order to determine order for attribute id=" +
attribute.getAttributeId());
}
raag.setOrder(getAttributes().size() +1);
return raag;
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public AttributeGroup copyGroup()
throws TorqueException
{
AttributeGroup newGroup = new AttributeGroup();
newGroup.setName(getName());
newGroup.setDescription(getDescription());
newGroup.setDedupe(getDedupe());
newGroup.setActive(getActive());
newGroup.setOrder(getOrder());
return newGroup;
}
// in java/org/tigris/scarab/om/AttributeGroup.java
public boolean isVisible4User(ScarabUser user) throws TorqueException
{
Role role = this.getRole4View();
boolean bRdo = false;
if (role == null)
{
bRdo = true;
}
else
{
if (user != null)
{
try
{
AccessControlList acl = TurbineSecurity.getACL(user);
GroupSet allGroups = TurbineSecurity.getAllGroups();
Group group = allGroups.getGroup(user.getCurrentModule().getName());
bRdo = acl.hasRole(role, group);
}
catch(org.apache.fulcrum.security.util.DataBackendException dbe)
{
throw new TorqueException("failed to get user's groups", dbe);
}
catch(org.apache.fulcrum.security.util.UnknownEntityException uee)
{
throw new TorqueException("failed to get user's groups", uee);
}
}
}
return bRdo;
}
// in java/org/tigris/scarab/om/QueryPeer.java
public static List getQueries(Module module, IssueType issueType,
ScarabUser user, String sortColumn,
String sortPolarity, String type)
throws TorqueException
{
List queries = null;
if (module == null || module.isGlobalModule())
{
queries = new ArrayList();
}
else
{
Serializable[] key = {QUERY_PEER, GET_QUERIES, module,
issueType, user, sortColumn, sortPolarity, type};
Object obj = QueryManager.getMethodResult().get(key);
if (obj == null)
{
Criteria crit = new Criteria()
.add(QueryPeer.DELETED, 0);
Criteria.Criterion moduleCrit = crit.getNewCriterion(
QueryPeer.MODULE_ID, module.getModuleId(), Criteria.EQUAL);
Criteria.Criterion crossModule = crit.getNewCriterion(
QueryPeer.MODULE_ID, null, Criteria.EQUAL);
moduleCrit.or(crossModule);
if (issueType != null)
{
Criteria.Criterion issueTypeCrit = crit.getNewCriterion(
QueryPeer.ISSUE_TYPE_ID, issueType.getIssueTypeId(),
Criteria.EQUAL);
Criteria.Criterion nullIssueTypeCrit = crit.getNewCriterion(
QueryPeer.ISSUE_TYPE_ID, null, Criteria.EQUAL);
moduleCrit.and(issueTypeCrit.or(nullIssueTypeCrit));
}
if (TYPE_PRIVATE.equals(type))
{
crit.add(userPrivateQueriesCrits(user, crit, moduleCrit));
}
else if (TYPE_GLOBAL.equals(type))
{
crit.add(allGlobalQueriesCrit(crit, moduleCrit));
}
else if (TYPE_ALL_USER.equals(type))
{
Criteria.Criterion cuGlob = userUnapprovedQueriesCrits(user, crit, moduleCrit);
Criteria.Criterion cPriv = userPrivateQueriesCrits(user, crit, moduleCrit);
cuGlob.or(cPriv);
Integer moduleOwnerId = module.getOwnerId();
Integer userId = user.getUserId();
if (moduleOwnerId.equals(userId))
{
Criteria.Criterion owner = ownerQueriesCrit(moduleOwnerId, crit, moduleCrit);
cuGlob.or(owner);
}
crit.add(cuGlob);
}
else
{
// All queries
Criteria.Criterion cGlob = allGlobalQueriesCrit(crit, moduleCrit);
Criteria.Criterion cPriv = userPrivateQueriesCrits(user, crit, moduleCrit);
cGlob.or(cPriv);
crit.add(cGlob);
}
// Add sort criteria
if (SORT_DESCRIPTION.equals(sortColumn))
{
addSortOrder(crit, QueryPeer.DESCRIPTION,
sortPolarity);
}
else if (SORT_AVAILABILITY.equals(sortColumn))
{
crit.addJoin(QueryPeer.SCOPE_ID,
ScopePeer.SCOPE_ID);
addSortOrder(crit, ScopePeer.SCOPE_NAME, sortPolarity);
}
else if (SORT_USER.equals(sortColumn))
{
addSortOrder(crit, QueryPeer.USER_ID, sortPolarity);
}
else
{
// sort by name
addSortOrder(crit, QueryPeer.NAME, sortPolarity);
}
String tmp = crit.toString();
queries = QueryPeer.doSelect(crit);
QueryManager.getMethodResult().put(queries, key);
}
else
{
queries = (List)obj;
}
}
return queries;
}
// in java/org/tigris/scarab/om/QueryPeer.java
public static List getUserQueries(ScarabUser user)
throws TorqueException
{
List queries = null;
Object obj = QueryManager.getMethodResult()
.get(QUERY_PEER, GET_USER_QUERIES, user);
if (obj == null)
{
Criteria crit = new Criteria()
.add(QueryPeer.DELETED, 0);
crit.add(QueryPeer.USER_ID, user.getUserId());
queries = QueryPeer.doSelect(crit);
QueryManager.getMethodResult()
.put(queries, QUERY_PEER, GET_USER_QUERIES, user);
}
else
{
queries = (List)obj;
}
return queries;
}
// in java/org/tigris/scarab/om/QueryPeer.java
public static List getModuleQueries(Module module)
throws TorqueException
{
List queries = null;
Object obj = QueryManager.getMethodResult()
.get(QUERY_PEER, GET_MODULE_QUERIES, module);
if (obj == null)
{
Criteria crit = new Criteria()
.add(QueryPeer.DELETED, 0);
crit.add(QueryPeer.MODULE_ID, module.getModuleId());
crit.add(QueryPeer.SCOPE_ID, Scope.MODULE__PK);
queries = QueryPeer.doSelect(crit);
QueryManager.getMethodResult()
.put(queries, QUERY_PEER, GET_MODULE_QUERIES, module);
}
else
{
queries = (List)obj;
}
return queries;
}
// in java/org/tigris/scarab/om/QueryPeer.java
public static List getQueries(Module module, IssueType issueType,
ScarabUser user)
throws TorqueException
{
return getQueries(module, issueType, user, SORT_AVAILABILITY, "asc",
TYPE_ALL);
}
// in java/org/tigris/scarab/om/QueryPeer.java
public static List getQueries(Module module, IssueType issueType,
ScarabUser user, String sortColumn,
String sortPolarity)
throws TorqueException
{
return getQueries(module, issueType, user, sortColumn,
sortPolarity, TYPE_ALL);
}
// in java/org/tigris/scarab/om/QueryPeer.java
public static Query getDefaultQuery(Module module) throws TorqueException
{
Integer moduleOwnerId = module.getOwnerId();
return getDefaultQuery(module, moduleOwnerId);
}
// in java/org/tigris/scarab/om/QueryPeer.java
public static Query getDefaultQuery(Module module, Integer userId) throws TorqueException
{
List<Query> queries = null;
Object obj = QueryManager.getMethodResult()
.get(QUERY_PEER, GET_MODULE_QUERIES, module, "homePage");
if (obj == null)
{
Integer moduleId = module.getModuleId();
Criteria crit = new Criteria()
.add(QueryPeer.DELETED, 0);
crit.add(QueryPeer.HOME_PAGE, 1);
crit.add(QueryPeer.MODULE_ID, moduleId);
queries = QueryPeer.doSelect(crit);
QueryManager.getMethodResult()
.put(queries, QUERY_PEER, GET_MODULE_QUERIES, module, "homePage");
}
else
{
queries = (List)obj;
}
Integer moduleOwnerId = module.getOwnerId();
Query result = null;
if(queries != null)
{
Iterator<Query> iter = queries.iterator();
while(iter.hasNext())
{
Query candidate = iter.next();
Integer candidateId = candidate.getUserId();
Integer scopeId = candidate.getScopeId();
boolean isPrivateUserQuery = candidateId.equals(userId) && (scopeId == 1);
boolean isGlobalQuery = scopeId == 2;
if( isPrivateUserQuery || isGlobalQuery )
{
result = candidate; // We found a customized query.
}
if(isPrivateUserQuery)
{
break; // It is the user's custom query. Take that and be happy.
}
}
// Now result contains either the user's customized query,
// or the module owner's query, if the user hasn't configured one by himself,
// or null, if no query could be found at all for either the user or the module owner.
}
return result;
}
// in java/org/tigris/scarab/om/NotificationStatusManager.java
public static List<NotificationStatus> getNotificationsFor(ScarabUser user) throws TorqueException
{
//NotificationStatusManager.getInstance().
List result = null;
Criteria crit = new Criteria()
.add(NotificationStatusPeer.RECEIVER_ID, user.getUserId());
crit.and(NotificationStatusPeer.STATUS, NotificationStatus.MARK_DELETED, Criteria.NOT_EQUAL);
result = NotificationStatusPeer.doSelect(crit);
return result;
}
// in java/org/tigris/scarab/om/NotificationStatusManager.java
public static int getNotificationCount(Module module, ScarabUser user) throws TorqueException
{
List<NotificationStatus> notifications = getNotificationsFor(user);
int count = 0;
Iterator<NotificationStatus> iter = notifications.iterator();
int currentModuleId = module.getModuleId();
while(iter.hasNext())
{
NotificationStatus status = iter.next();
long issueId = status.getIssueId();
Issue issue = IssueManager.getInstance(issueId);
int moduleId = issue.getModuleId();
if(moduleId == currentModuleId)
{
count++;
}
}
return count;
}
// in java/org/tigris/scarab/om/ScopePeer.java
public static List getAllScopes()
throws TorqueException
{
return doSelect(new Criteria(0));
}
// in java/org/tigris/scarab/om/ModuleManager.java
public static Module getInstance(String moduleDomain,
String moduleRealName,
String moduleCode)
throws TorqueException
{
return getManager().getInstanceImpl(moduleDomain, moduleRealName,
moduleCode);
}
// in java/org/tigris/scarab/om/ModuleManager.java
protected Module getInstanceImpl(final String moduleDomain,
final String moduleRealName,
final String moduleCode)
throws TorqueException
{
final Criteria crit = new Criteria();
if( moduleDomain != null )
{
crit.add(ScarabModulePeer.DOMAIN, moduleDomain);
}
if( moduleRealName != null )
{
crit.add(ScarabModulePeer.MODULE_NAME, moduleRealName);
}
if( moduleCode != null )
{
crit.add(ScarabModulePeer.MODULE_CODE, moduleCode);
}
final List result = ScarabModulePeer.doSelect(crit);
if (result.size() != 1)
{
throw new TorqueException ("Selected: " + result.size() +
" rows. Expected 1."); //EXCEPTION
}
return (Module) result.get(0);
}
// in java/org/tigris/scarab/om/ModuleManager.java
public static List getInstancesFromIssueList(List issues)
throws TorqueException
{
if (issues == null)
{
throw new IllegalArgumentException("Null issue list is not allowed."); //EXCEPTION
}
List modules = new ArrayList();
Iterator i = issues.iterator();
if (i.hasNext())
{
Issue issue = (Issue)i.next();
if (issue != null)
{
Module module = issue.getModule();
if (module != null && !modules.contains(module))
{
modules.add(module);
}
}
else
{
throw new TorqueException("Null issue in list is not allowed."); //EXCEPTION
}
}
return modules;
}
// in java/org/tigris/scarab/om/ModuleManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
getMethodResult().removeAll((ScarabModule)om, ScarabModule.GET_DEFAULTREPORT);
List listeners = (List)listenersMap.get(ReportPeer.REPORT_ID);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/AttachmentManager.java
protected Persistent putInstanceImpl(Persistent om)
throws TorqueException
{
Persistent oldOm = super.putInstanceImpl(om);
List listeners = (List)listenersMap.get(AttachmentPeer.ISSUE_ID);
notifyListeners(listeners, oldOm, om);
return oldOm;
}
// in java/org/tigris/scarab/om/AttachmentManager.java
public static Attachment getInstance(String id)
throws TorqueException
{
return getInstance(new Long(id));
}
// in java/org/tigris/scarab/om/AttachmentManager.java
public static Attachment getComment(Attachment attachment, Issue issue,
ScarabUser user)
throws TorqueException
{
return populate(attachment, issue, Attachment.COMMENT__PK, "comment",
user, "text/plain");
}
// in java/org/tigris/scarab/om/AttachmentManager.java
public static Attachment getReason(Attachment attachment, Issue issue,
ScarabUser user)
throws TorqueException
{
return populate(attachment, issue, Attachment.MODIFICATION__PK, "reason",
user, "text/plain");
}
// in java/org/tigris/scarab/om/AttachmentManager.java
private static Attachment populate(Attachment attachment,
Issue issue, Integer typeId,
String name, ScarabUser user,
String mimetype)
throws TorqueException
{
attachment.setIssue(issue);
attachment.setTypeId(typeId);
attachment.setName(name);
attachment.setCreatedBy(user.getUserId());
attachment.setMimeType(mimetype);
attachment.save();
return attachment;
}
// in java/org/tigris/scarab/om/IssueTypePeer.java
public static IssueType retrieveByPK(ObjectKey pk)
throws TorqueException
{
IssueType result = null;
Object obj = ScarabCache.get(ISSUE_TYPE_PEER, RETRIEVE_BY_PK, pk);
if (obj == null)
{
result = BaseIssueTypePeer.retrieveByPK(pk);
ScarabCache.put(result, ISSUE_TYPE_PEER, RETRIEVE_BY_PK, pk);
}
else
{
result = (IssueType)obj;
}
return result;
}
// in java/org/tigris/scarab/om/IssueTypePeer.java
public static List getAllIssueTypes(boolean deleted,
String sortColumn, String sortPolarity)
throws TorqueException
{
List result = null;
Boolean b = deleted ? Boolean.TRUE : Boolean.FALSE;
Object obj = ScarabCache.get(ISSUE_TYPE_PEER, GET_ALL_ISSUE_TYPES, b);
if (obj == null)
{
Criteria c = new Criteria();
c.add(IssueTypePeer.PARENT_ID, 0);
c.add(IssueTypePeer.ISSUE_TYPE_ID, 0, Criteria.NOT_EQUAL);
if (deleted)
{
c.add(IssueTypePeer.DELETED, 1);
}
else
{
c.add(IssueTypePeer.DELETED, 0);
}
if (sortColumn != null && sortColumn.equals("desc"))
{
addSortOrder(c, IssueTypePeer.DESCRIPTION,
sortPolarity);
}
else
{
// sort on name
addSortOrder(c, IssueTypePeer.NAME,
sortPolarity);
}
result = doSelect(c);
ScarabCache.put(result, ISSUE_TYPE_PEER, GET_ALL_ISSUE_TYPES, b);
}
else
{
result = (List)obj;
}
return result;
}
// in java/org/tigris/scarab/om/IssueTypePeer.java
public static List getAllIssueTypes(boolean includeDeleted)
throws TorqueException
{
return getAllIssueTypes(includeDeleted, "name", "asc");
}
// in java/org/tigris/scarab/om/IssueTypePeer.java
public static List getDefaultIssueTypes()
throws TorqueException
{
Criteria c = new Criteria();
c.add(IssueTypePeer.PARENT_ID, 0);
c.add(IssueTypePeer.DELETED, 0);
c.add(IssueTypePeer.ISDEFAULT, 1);
c.add(IssueTypePeer.ISSUE_TYPE_ID, 0, Criteria.NOT_EQUAL);
return IssueTypePeer.doSelect(c);
}
// in java/org/tigris/scarab/om/IssueTypePeer.java
public static boolean isUnique(String name, Integer id)
throws TorqueException
{
boolean unique = true;
name = name.trim();
Criteria crit = new Criteria().add(IssueTypePeer.NAME, name);
crit.setIgnoreCase(true);
List types = IssueTypePeer.doSelect(crit);
if (types.size() > 0)
{
for (int i =0; i<types.size();i++)
{
IssueType it = (IssueType)types.get(i);
if ((id == null ||
(id != null && !it.getIssueTypeId().equals(id)))
&& it.getName().trim().toLowerCase().equals(name.toLowerCase()))
{
unique = false;
}
}
}
return unique;
}
// in java/org/tigris/scarab/om/AttachmentType.java
public static AttachmentType getInstance(String attachmentTypeName)
throws TorqueException,ScarabException
{
Criteria crit = new Criteria();
crit.add(BaseAttachmentTypePeer.ATTACHMENT_TYPE_NAME, attachmentTypeName);
List attachmentTypes = AttachmentTypePeer.doSelect(crit);
if(attachmentTypes.size() > 1)
{
throw new ScarabException(L10NKeySet.ExceptionAttachmentDuplicateTypename);
}
return (AttachmentType)attachmentTypes.get(0);
}
// in java/org/tigris/scarab/om/IssueTemplateInfoPeer.java
public static List getTemplates(Module module, IssueType issueType,
ScarabUser user, String sortColumn,
String sortPolarity, String type)
throws TorqueException, ScarabException
{
List templates = null;
Serializable[] key = {TEMPLATE_PEER, GET_TEMPLATES, module,
issueType, user, sortColumn, sortPolarity, type};
Object obj = ScarabCache.get(key);
if (obj == null)
{
Criteria crit = new Criteria()
.add(IssuePeer.MODULE_ID, module.getModuleId())
.add(IssuePeer.DELETED, 0)
.add(IssuePeer.MOVED, 0)
.addJoin(ActivitySetPeer.TRANSACTION_ID,
ActivityPeer.TRANSACTION_ID)
.addJoin(IssuePeer.ISSUE_ID,
ActivityPeer.ISSUE_ID)
.add(IssuePeer.TYPE_ID, issueType.getTemplateId())
.addJoin(IssueTemplateInfoPeer.ISSUE_ID,
IssuePeer.ISSUE_ID);
crit.setDistinct();
Criteria.Criterion cGlob = crit.getNewCriterion(
IssueTemplateInfoPeer.SCOPE_ID, Scope.MODULE__PK,
Criteria.EQUAL);
cGlob.and(crit.getNewCriterion(IssueTemplateInfoPeer.APPROVED,
Boolean.TRUE, Criteria.EQUAL));
Criteria.Criterion cPriv = crit.getNewCriterion(
ActivitySetPeer.CREATED_BY, user.getUserId(),
Criteria.EQUAL);
cPriv.and(crit.getNewCriterion(
IssueTemplateInfoPeer.SCOPE_ID, Scope.PERSONAL__PK,
Criteria.EQUAL));
if (TYPE_PRIVATE.equals(type))
{
crit.add(cPriv);
}
else if (TYPE_GLOBAL.equals(type))
{
crit.add(cGlob);
}
else
{
// All templates
cGlob.or(cPriv);
crit.add(cGlob);
}
// Add sort criteria
if (sortColumn.equals("desc"))
{
addSortOrder(crit, IssueTemplateInfoPeer.DESCRIPTION,
sortPolarity);
}
else if (sortColumn.equals("avail"))
{
crit.addJoin(IssueTemplateInfoPeer.SCOPE_ID,
ScopePeer.SCOPE_ID);
addSortOrder(crit, ScopePeer.SCOPE_NAME, sortPolarity);
}
else if (!sortColumn.equals("user"))
{
// sort by name
addSortOrder(crit, IssueTemplateInfoPeer.NAME, sortPolarity);
}
templates = IssueTemplateInfoPeer.doSelect(crit);
ScarabCache.put(templates, key);
}
else
{
templates = (List)obj;
}
if (sortColumn.equals("user"))
{
templates = sortByCreatingUser(templates, sortPolarity);
}
return templates;
}
// in java/org/tigris/scarab/om/IssueTemplateInfoPeer.java
public static List getUserTemplates(ScarabUser user, Module module,IssueType issueType)
throws TorqueException, ScarabException
{
List templates = null;
Object obj = ScarabCache.get(TEMPLATE_PEER, GET_USER_TEMPLATES, user);
if (obj == null)
{
Criteria crit = new Criteria()
.addJoin(IssueTemplateInfoPeer.ISSUE_ID,
IssuePeer.ISSUE_ID)
.add(IssuePeer.DELETED, 0)
.add(IssuePeer.MODULE_ID, module.getModuleId())
.addJoin(ActivitySetPeer.TRANSACTION_ID,
ActivityPeer.TRANSACTION_ID)
.addJoin(IssuePeer.ISSUE_ID,
ActivityPeer.ISSUE_ID)
.add(IssuePeer.TYPE_ID, issueType.getTemplateId())
.add(ActivitySetPeer.CREATED_BY, user.getUserId());
templates = IssueTemplateInfoPeer.doSelect(crit);
ScarabCache.put(templates, TEMPLATE_PEER, GET_USER_TEMPLATES, user);
}
else
{
templates = (List)obj;
}
return templates;
}
// in java/org/tigris/scarab/om/IssueTemplateInfoPeer.java
public static List getModuleTemplates(Module module)
throws TorqueException
{
List templates = null;
Object obj = ScarabCache.get(TEMPLATE_PEER, GET_MODULE_TEMPLATES, module);
if (obj == null)
{
Criteria crit = new Criteria()
.addJoin(IssueTemplateInfoPeer.ISSUE_ID,
IssuePeer.ISSUE_ID)
.add(IssuePeer.DELETED, 0)
.add(IssuePeer.MODULE_ID, module.getModuleId())
.add(IssueTemplateInfoPeer.SCOPE_ID, Scope.MODULE__PK);
templates = IssueTemplateInfoPeer.doSelect(crit);
ScarabCache.put(templates, TEMPLATE_PEER, GET_USER_TEMPLATES, module);
}
else
{
templates = (List)obj;
}
return templates;
}
// in java/org/tigris/scarab/om/IssueTemplateInfoPeer.java
private static List sortByCreatingUser(List result,
String sortPolarity)
throws TorqueException
{
final int polarity = ("asc".equals(sortPolarity)) ? 1 : -1;
Comparator c = new Comparator()
{
public int compare(Object o1, Object o2)
{
int i = 0;
try
{
i = polarity *
((Issue)o1).getCreatedBy().getFirstName()
.compareTo(((Issue)o2).getCreatedBy().getFirstName());
}
catch (Exception e)
{
//
}
return i;
}
};
Collections.sort(result, c);
return result;
}
// in java/org/tigris/scarab/om/Report.java
public Module getModule()
throws TorqueException
{
return ModuleManager.getInstance(getModuleId());
}
// in java/org/tigris/scarab/om/Report.java
public void setModule(Module v)
throws TorqueException
{
setModuleId(v.getModuleId());
}
// in java/org/tigris/scarab/om/AttributeOption.java
public List getAncestors()
throws TorqueException
{
List options = new ArrayList();
addAncestors(options);
return options;
}
// in java/org/tigris/scarab/om/AttributeOption.java
private void addAncestors(List ancestors)
throws TorqueException
{
List parents = getParents();
for (int i=parents.size()-1; i>=0; i--)
{
AttributeOption parent = (AttributeOption)
parents.get(i);
if (!ancestors.contains(parent))
{
ancestors.add(parent);
parent.addAncestors(ancestors);
}
}
}
// in java/org/tigris/scarab/om/AttributeOption.java
public List getDescendants()
throws TorqueException
{
List options = new ArrayList();
addDescendants(options);
return options;
}
// in java/org/tigris/scarab/om/AttributeOption.java
private void addDescendants(List descendants)
throws TorqueException
{
List children = getChildren();
for (int i=children.size()-1; i>=0; i--)
{
AttributeOption child = (AttributeOption)
children.get(i);
descendants.add(child);
child.addDescendants(descendants);
}
}
// in java/org/tigris/scarab/om/AttributeOption.java
public List getChildren()
throws TorqueException
{
if (sortedChildren == null)
{
buildChildren();
}
return sortedChildren;
}
// in java/org/tigris/scarab/om/AttributeOption.java
public List getParents()
throws TorqueException
{
List sortedParents = (List)AttributeOptionManager.getMethodResult().get(
this, AttributeOptionManager.GET_PARENTS
);
if ( sortedParents == null )
{
sortedParents = buildParents();
AttributeOptionManager.getMethodResult().put(
sortedParents, this, AttributeOptionManager.GET_PARENTS
);
}
return sortedParents;
}
// in java/org/tigris/scarab/om/AttributeOption.java
private synchronized void buildChildren()
throws TorqueException
{
Criteria crit = new Criteria()
.add(ROptionOptionPeer.RELATIONSHIP_ID,
OptionRelationship.PARENT_CHILD)
.add(ROptionOptionPeer.OPTION1_ID,
super.getOptionId());
List relations = ROptionOptionPeer.doSelect(crit);
sortedChildren = new ArrayList(relations.size());
for (int i=0; i < relations.size(); i++)
{
ROptionOption relation = (ROptionOption)relations.get(i);
Integer key = relation.getOption2Id();
if (key != null)
{
sortedChildren.add(relation.getOption2Option());
}
}
sortChildren();
}
// in java/org/tigris/scarab/om/AttributeOption.java
private synchronized List buildParents()
throws TorqueException
{
Criteria crit = new Criteria()
.add(ROptionOptionPeer.RELATIONSHIP_ID,
OptionRelationship.PARENT_CHILD)
.add(ROptionOptionPeer.OPTION2_ID,
super.getOptionId());
List relations = ROptionOptionPeer.doSelect(crit);
List sortedParents = new ArrayList(relations.size());
for (int i=0; i < relations.size(); i++)
{
ROptionOption relation = (ROptionOption)relations.get(i);
Integer key = relation.getOption1Id();
if (key != null)
{
sortedParents.add(relation.getOption1Option());
}
}
Collections.sort(sortedParents, getComparator());
return sortedParents;
}
// in java/org/tigris/scarab/om/AttributeOption.java
public boolean isChildOf(AttributeOption parent)
throws TorqueException
{
return getParents().contains(parent);
}
// in java/org/tigris/scarab/om/AttributeOption.java
public boolean isParentOf(AttributeOption child)
throws TorqueException
{
return getChildren().contains(child);
}
// in java/org/tigris/scarab/om/AttributeOption.java
public boolean hasChildren()
throws TorqueException
{
return getChildren().size() > 0 ? true : false;
}
// in java/org/tigris/scarab/om/AttributeOption.java
public boolean hasParents()
throws TorqueException
{
return getParents().size() > 0 ? true : false;
}
// in java/org/tigris/scarab/om/AttributeOption.java
public AttributeOption getParent()
throws TorqueException
{
AttributeOption parent = null;
List parents = getParents();
if (parents.size() == 1)
{
parent = (AttributeOption) parents.get(0);
}
return parent;
}
// in java/org/tigris/scarab/om/AttributeOption.java
public void deleteModuleMappings()
throws TorqueException
{
Criteria crit = new Criteria();
crit.add(RModuleOptionPeer.OPTION_ID, getOptionId());
RModuleOptionPeer.doDelete(crit);
ScarabCache.clear();
}
// in java/org/tigris/scarab/om/AttributeOption.java
public void deleteIssueTypeMappings()
throws TorqueException
{
Criteria crit = new Criteria();
crit.add(RIssueTypeOptionPeer.OPTION_ID, getOptionId());
RIssueTypeOptionPeer.doDelete(crit);
ScarabCache.clear();
}
// in java/org/tigris/scarab/om/AttributeOption.java
private List getIssueTypesWithMappings()
throws TorqueException
{
Criteria crit = new Criteria();
crit.add(RIssueTypeOptionPeer.OPTION_ID, getOptionId());
crit.addJoin(RIssueTypeOptionPeer.ISSUE_TYPE_ID,
IssueTypePeer.ISSUE_TYPE_ID);
return IssueTypePeer.doSelect(crit);
}
// in java/org/tigris/scarab/om/AttributeOption.java
public boolean isSystemDefined()
throws TorqueException
{
boolean systemDefined = false;
List issueTypeList = getIssueTypesWithMappings();
for (Iterator i = issueTypeList.iterator();
i.hasNext() && !systemDefined;)
{
systemDefined = ((IssueType)i.next()).isSystemDefined();
}
return systemDefined;
}
// in java/org/tigris/scarab/om/UserPreferenceManager.java
public static UserPreference getInstance(Integer userid)
throws TorqueException
{
if (userid == null)
{
throw new IllegalArgumentException("User ID cannot be null"); //EXCEPTION
}
UserPreference up = null;
try
{
up = BaseUserPreferenceManager.getInstance(userid);
}
catch (TorqueException te)
{
// Empty result...Failed to select one and only one row.
}
if (up == null)
{
up = UserPreferenceManager.getInstance();
up.setUserId(userid);
}
return up;
}
// in java/org/tigris/scarab/notification/ScarabNotificationManager.java
private void logNotificationData(NotificationStatus notification) throws TorqueException
{
try
{
log.error("queueNotifications():comment:" + notification.getComment());
log.error("queueNotifications():changeDate:" + notification.getChangeDate());
log.error("queueNotifications():creationDate:" + notification.getCreationDate());
log.error("queueNotifications():creator:" + notification.getCreator().toString());
log.error("queueNotifications():issueId:" + notification.getIssueId());
log.error("queueNotifications():primaryKey:" + notification.getPrimaryKey().toString());
log.error("queueNotifications():queryKey:" + notification.getQueryKey());
log.error("queueNotifications():receiver:" + notification.getReceiver().toString());
log.error("queueNotifications():status:" + notification.getStatusLabel());
}
catch(Exception e)
{
log.error("queueNotifications(): while dumping notificationData: " + e.getMessage(),e);
}
}
// in java/org/tigris/scarab/notification/ScarabNotificationManager.java
private void createWakeupNotification(Issue issue, ScarabUser user, String wakeupMessage) throws TorqueException
{
Date date;
try {
date = issue.getOnHoldUntil();
} catch (Exception e)
{
throw new RuntimeException("Can not retrieve the onHoldUntil date from the current issue");
}
Activity activity = ActivityManager.getInstance();
Attribute attribute = issue.getMyStatusAttribute();
activity.setAttribute(attribute);
activity.setActivityType(ActivityType.ISSUE_ONHOLD.getCode());
activity.setDescription("WakeupFromOnHoldstate");
activity.setIssue(issue);
activity.setEndDate(date);
activity.setNewValue("");
activity.setOldValue("");
activity.setOldOptionId(0);
activity.setNewOptionId(0);
Attachment attachment = AttachmentManager.getInstance();
attachment.setTextFields(user, issue,Attachment.COMMENT__PK);
attachment.setData(wakeupMessage);
attachment.setName("comment");
attachment.save();
activity.setAttachment(attachment);
Integer tt = ActivitySetTypePeer.EDIT_ISSUE__PK;
ActivitySet activitySet;
try {
activitySet = ActivitySetManager.getInstance(tt, user);
activitySet.addActivity(activity);
activitySet.save();
addActivityNotification(ActivityType.ISSUE_REMINDER, activitySet, issue, user);
} catch (ScarabException e) {
throw new RuntimeException(e);
}
}
// in java/org/tigris/scarab/notification/ScarabNotificationManager.java
private boolean getIsStatusAttribute(Attribute attribute, Issue issue)
throws TorqueException
{
Attribute statusAttribute = issue.getMyStatusAttribute();
if(statusAttribute == null)
{
return false;
}
boolean result = statusAttribute.equals(attribute);
return result;
}
// in java/org/tigris/scarab/notification/ScarabNotificationManager.java
private String[] getFromUser(Issue issue, EmailContext context) throws TorqueException
{
String[] replyToUser = null;
Set creators = (Set)context.get("creators");
if (creators.size()==1)
{
// exactly one contributor to this E-Mail
boolean exposeSender = Turbine.getConfiguration()
.getBoolean("scarab.email.replyto.sender",false);
if(exposeSender)
{
ScarabUser creator = (ScarabUser)creators.toArray()[0];
replyToUser = new String[] { creator.getName(), creator.getEmail() };
}
}
if(replyToUser == null)
{
replyToUser = issue.getModule().getSystemEmail();
}
return replyToUser;
}
// in java/org/tigris/scarab/notification/Notification.java
public void setIssue(Issue issue) throws TorqueException
{
this.module = issue.getModule();
this.issue = issue;
this.conditions = null;
this.rules = null;
this.optionIds = null;
}
// in java/org/tigris/scarab/notification/Notification.java
public boolean isRequiredIf(Integer optionID) throws TorqueException
{
boolean isRequired = getOptionIds().contains(optionID);
return isRequired;
}
// in java/org/tigris/scarab/notification/Notification.java
public void setConditionsArray(Integer[] optionId, Integer operator) throws TorqueException
{
NotificationRulePeer.saveConditions(user, module, optionId, operator);
}
// in java/org/tigris/scarab/notification/Notification.java
public List<Condition> getConditions() throws TorqueException
{
if(conditions == null)
{
conditions = NotificationRulePeer.getConditions(user, module);
}
return conditions;
}
// in java/org/tigris/scarab/notification/Notification.java
public List<NotificationRule> getRules() throws TorqueException
{
if(rules == null)
{
NotificationRulePeer.getNotificationRules(user, module);
}
return rules;
}
// in java/org/tigris/scarab/notification/Notification.java
private Set<Integer> getOptionIds() throws TorqueException
{
Iterator<Condition> iter = getConditions().iterator();
Set<Integer>optionIds = new HashSet<Integer>();
while(iter.hasNext())
{
Condition condition = iter.next();
Integer optionId = condition.getOptionId();
if(optionId != null)
{
optionIds.add(optionId);
}
}
return optionIds;
}
// in java/org/tigris/scarab/notification/Notification.java
public boolean sendConditionsMatch() throws TorqueException
{
List<Condition> conditions = getConditions();
if(conditions.size() == 0)
{
return true; // no conditions defined, hence no constraints, hence return true
}
Map<String,AttributeValue> attributeValues = issue.getModuleOptionAttributeValuesMap();
Integer operator = getConditionOperator();
Iterator<Condition> iter = conditions.iterator();
Set<Integer>attributeIds = new HashSet<Integer>();
String forIssueId = "";
if(this.issue!=null)
{
forIssueId = "for issue " + this.issue.getIdPrefix()+ this.issue.getIdCount();
}
log.info("test sendNotification conditions "+forIssueId+" -------------");
int matchCounter = 0;
while(iter.hasNext())
{
Condition condition = iter.next();
AttributeOption ao = condition.getAttributeOption();
int optionId = ao.getOptionId();
Attribute attribute = ao.getAttribute();
int attributeId = attribute.getAttributeId();
attributeIds.add(attributeId);
AttributeOption option = AttributeOptionManager.getInstance(optionId);
//log.info("test for " + attribute.getName() + "=\"" + option.getName() + "\" (att:" + + attributeId + ",opt:" + optionId+")");
Iterator<Entry<String,AttributeValue>> attvalIterator = attributeValues.entrySet().iterator();
while( attvalIterator.hasNext())
{
Entry<String,AttributeValue> e = attvalIterator.next();
AttributeValue av = e.getValue();
int attvalAttributeId = av.getAttributeId();
Attribute att = av.getAttribute();
AttributeOption attOpt = av.getAttributeOption();
if(attributeId == attvalAttributeId)
{
int aoi = av.getOptionId();
boolean match = aoi == optionId;
//log.info( ((match)? "match ":" ") + att.getName() + "=\"" + attOpt.getName() + "\" (att:" + attvalAttributeId + ",opt:" + attOpt.getOptionId());
if( match)
{
String sendConditionMet = "SendCondition met. ("+attribute.getName() + "=\"" + option.getName()+")";
matchCounter++;
if ( operator.equals(OR) )
{
log.info(sendConditionMet + " -> (send notification)");
return true; // quick exit. first match gives success.
}
log.info(sendConditionMet);
break; // we can break the inner iteration (we found the match)
}
}
}
}
boolean match; // just in case no condition is defined, we return true
if(operator.equals(AND) && attributeIds.size() == matchCounter)
{
log.info("SendCondition met. (all conditions matched)");
match = true; // operator
}
else
{
if (matchCounter > 0)
{
log.info("Only " + matchCounter + " send Conditions out of "+attributeIds.size()+" met. (Send is not triggered.)");
}
else
{
log.info("None of the " + attributeIds.size() + " available conditions was applicable to this issue. (Send is not triggered.)" );
}
match = false;
}
return match;
}
// in java/org/tigris/scarab/xmlrpc/NewTicketHandler.java
public String createNewTicket( String moduleCode,
String issueTypeName,
String userName,
Hashtable attribs) throws TorqueException, ScarabException {
//init environment for the new issue
Module module = ModuleManager.getInstance(null, null, moduleCode);
IssueType issueType = IssueType.getInstance(issueTypeName);
Issue issue = module.getNewIssue(issueType);
ScarabUser user = ScarabUserManager.getInstance(userName);
Attachment reason = new Attachment();
reason.setData("Created by xmlrpc");
reason.setName("reason");
//init issue, set and store attributes
ActivitySet activitySet = null;
activitySet = issue.setInitialAttributeValues(activitySet, reason, new HashMap(), user);
// Save any unsaved attachments as part of this ActivitySet as well.
setAttributes(issue,activitySet,reason,user,attribs);
activitySet = issue.doSaveFileAttachments(activitySet, user);
activitySet.save();
return issue.getUniqueId();
}
// in java/org/tigris/scarab/xmlrpc/NewTicketHandler.java
private void setAttributes(Issue issue, ActivitySet activitySet, Attachment attachment, ScarabUser user, Hashtable attribs) throws TorqueException, ScarabException {
LinkedMap avMap = issue.getModuleAttributeValuesMap(false);
HashMap newValues = new HashMap();
for (MapIterator i = avMap.mapIterator();i.hasNext();)
{
AttributeValue aval = (AttributeValue)avMap.get(i.next());
String key = aval.getAttribute().getName();
String newValue = (String)attribs.get(key);
if (newValue != null) {
AttributeValue newVal = aval.copy();
newVal.setValue(newValue);
newValues.put(aval.getAttributeId(),newVal);
}
}
issue.setAttributeValues(activitySet, newValues, attachment, user);
}
// in java/org/tigris/scarab/xmlrpc/ScarabUpdateHelper.java
private Attribute getAttribute(String attribute)
throws ScarabUpdateException, TorqueException {
// find the corresponding attribute
Attribute attr;
Criteria crit = new Criteria();
crit.add(AttributePeer.ATTRIBUTE_NAME, (Object) attribute,
Criteria.EQUAL);
List attrList = AttributePeer.doSelect(crit);
if (attrList.size() == 1) {
attr = (Attribute) attrList.get(0);
} else {
throw new ScarabUpdateException(
"Found " + attrList.size() + " attributes for " + attribute + ".");
}
return attr;
}
// in java/org/tigris/scarab/xmlrpc/ScarabUpdateHelper.java
private Attribute getOptionAttribute(String attribute)
throws ScarabUpdateException, TorqueException {
Attribute attr = getAttribute(attribute);
if (attr.isOptionAttribute()) {
// do nothing
} else {
throw new ScarabUpdateException(
"Found non-optiontype attribute when an option type attribte was expected.");
}
return attr;
}
// in java/org/tigris/scarab/xmlrpc/ScarabUpdateHelper.java
public List getAttributeOptions(String attribute) throws TorqueException,
ScarabUpdateException {
Criteria crit = new Criteria();
// get all non-deleted options for this attribute
crit.add(AttributePeer.ATTRIBUTE_NAME, (Object) attribute,
Criteria.EQUAL);
crit.add(AttributeOptionPeer.DELETED, false);
crit.addJoin(AttributePeer.ATTRIBUTE_ID,
AttributeOptionPeer.ATTRIBUTE_ID);
return AttributeOptionPeer.doSelect(crit);
}
// in java/org/tigris/scarab/xmlrpc/ScarabUpdateHelper.java
private List getModuleAttributes(String attribute) throws TorqueException,
ScarabUpdateException {
Criteria crit = new Criteria();
// get all non-deleted options for this attribute
crit.add(AttributePeer.ATTRIBUTE_NAME, (Object) attribute,
Criteria.EQUAL);
crit.addJoin(AttributePeer.ATTRIBUTE_ID,
RModuleAttributePeer.ATTRIBUTE_ID);
List matOptions = RModuleAttributePeer.doSelect(crit);
return matOptions;
}
// in java/org/tigris/scarab/xmlrpc/ScarabUpdateHelper.java
private List getIssueTypes(String attribute) throws TorqueException,
ScarabUpdateException {
Criteria crit = new Criteria();
// get all non-deleted options for this attribute
crit.add(AttributePeer.ATTRIBUTE_NAME, (Object) attribute,
Criteria.EQUAL);
crit.addJoin(AttributePeer.ATTRIBUTE_ID,
RIssueTypeAttributePeer.ATTRIBUTE_ID);
crit.addJoin(IssueTypePeer.ISSUE_TYPE_ID,
RIssueTypeAttributePeer.ISSUE_TYPE_ID);
List itOptions = IssueTypePeer.doSelect(crit);
return itOptions;
}
// in java/org/tigris/scarab/feeds/IssueFeed.java
public SyndFeed getFeed() throws IOException, FeedException, TorqueException, Exception {
SyndFeed feed = new SyndFeedImpl();
String title = issue.getUniqueId() + ": " + issue.getDefaultText();
feed.setTitle(title);
String link = scarabLink.getIssueIdAbsoluteLink(issue).toString();
feed.setLink(link);
feed.setDescription(title);
List entries = new ArrayList();
List allActivities = issue.getActivity(true);
for (Iterator i = allActivities.iterator(); i.hasNext();) {
SyndEntry entry;
SyndContent description;
Activity activity = (Activity)i.next();
ActivitySet activitySet = activity.getActivitySet();
Date date =activitySet.getCreatedDate();
entry = new SyndEntryImpl();
entry.setPublishedDate(date);
description = new SyndContentImpl();
description.setType("text/html");
String desc =
"<b>Description:</b>" + activity.getDisplayName(this.l10nTool) +"<br/>"
+ "<b>New:</b>" + activity.getNewValue(this.l10nTool) +"<br/>"
+ "<b>Old:</b>" + activity.getOldValue(this.l10nTool) +"<br/>"
+ "<b>Reason:</b>" + activitySet.getCommentForHistory(issue) +"<br/>";
entry.setAuthor(activitySet.getCreator().getName());
description.setValue(desc.toString());
String entryTitle = createEntryTitle(activity);
entry.setTitle(entryTitle);
entry.setDescription(description);
//The hashCode is a cheap trick to have a unique link tag in the RSS feed
//to help those reader as ThunderBird that use the link to check for new items
entry.setLink(link+"?hash="+entry.hashCode());
entries.add(entry);
}
feed.setEntries(entries);
return feed;
}
// in java/org/tigris/scarab/feeds/QueryFeed.java
public SyndFeed getFeed() throws Exception, TorqueException, DataSetException, TurbineSecurityException
{
SyndFeed feed = new SyndFeedImpl();
feed.setTitle(query.getName());
String link = scarabLink.setAction("Search").addPathInfo("go",query.getQueryId()).toString();
feed.setLink(link);
feed.setDescription(query.getDescription());
List entries = new ArrayList();
for(Iterator i = results.iterator(); i.hasNext();)
{
SyndEntry entry = new SyndEntryImpl();
SyndContent description = new SyndContentImpl();
QueryResult queryResult = (QueryResult)i.next();
String title = queryResult.getUniqueId();
entry.setTitle(title);
Issue issue = IssueManager.getInstance(Long.valueOf(queryResult.getIssueId()));
link = scarabLink.getIssueIdAbsoluteLink(issue).toString();
entry.setLink(link);
Date publishedDate = null;
if(issue.getModifiedDate()!= null){
publishedDate = issue.getModifiedDate();
}
else {
publishedDate = issue.getCreatedDate();
}
entry.setPublishedDate(publishedDate);
description = new SyndContentImpl();
description.setType("text/html");
String desc = "";
Iterator avIteratorCSV = queryResult.getAttributeValuesAsCSV().iterator();
Iterator avIterator = query.getMITList().getAllRModuleUserAttributes().iterator();
while (avIterator.hasNext())
{
String value = (String)avIteratorCSV.next();
RModuleUserAttribute av = (RModuleUserAttribute)avIterator.next();
desc = desc + "<b>" + av.getAttribute().getName()+":</b>" + value +"<br/>";
}
description.setValue(ScarabUtil.filterNonXml(desc));
entry.setDescription(description);
entries.add(entry);
}
feed.setEntries(entries);
feed.setFeedType(format);
return feed;
}
// in java/org/tigris/scarab/actions/Search.java
public void doGetissues(RunData data, TemplateContext context) throws TorqueException
{
try
{
setup(data, context);
}
catch(Exception e)
{
// no module selected
return;
}
ParameterParser pp = data.getParameters();
Module module = user.getCurrentModule();
MITList mitList;
int issueTypeId = pp.getInt("issueType");
if(issueTypeId > 0)
{
// search only within specidied issueType
IssueType issueType = IssueTypeManager.getInstance(new Integer(issueTypeId));
mitList = MITListManager.getSingleItemList(module, issueType, user);
}
else
{
// search all issueTypes in current module
mitList = MITListManager.getSingleModuleAllIssueTypesList(module, user);
}
user.setCurrentMITList(mitList);
int optionId = pp.getInt("option");
if (optionId > 0)
{
// search only issues with given attribute set to given value
Integer oid = new Integer(optionId);
AttributeOption ao = AttributeOptionManager.getInstance(oid);
Integer attId = ao.getAttributeId();
Attribute attribute = AttributeManager.getInstance(attId);
AttributeValue av = AttributeValue.getNewInstance(attribute, null);
String aoname = ao.getName();
attributeSearch(aoname, av, user);
}
else
{
// search all issues in current MITList (see MITList initializatoin above)
processSearch("", user);
}
return;
}
// in java/org/tigris/scarab/actions/DefineXModuleList.java
private void addToUsersList(ScarabUser user, MITList list)
throws TorqueException
{
MITList currentList = user.getCurrentMITList();
if (currentList == null)
{
currentList = MITListManager.getInstance();
user.setCurrentMITList(currentList);
}
currentList.addAll(list);
}
// in java/org/tigris/scarab/actions/ModifyModule.java
private void updateModuleParameters(RunData data, Module me) throws TorqueException
{
ParameterParser pp = data.getParameters();
// Update email overrides
if (GlobalParameterManager.getBoolean(
GlobalParameter.EMAIL_ALLOW_MODULE_OVERRIDE,me))
{
String name;
for (int i=0; i<EMAIL_PARAMS.length; i++)
{
name = EMAIL_PARAMS[i];
storeGlobalParameterAsBoolean(name, me, pp);
}
}
// update all global module parameters in database
storeGlobalParameter(GlobalParameter.ISSUE_REASON_REQUIRED, me, pp);
storeGlobalParameterAsBoolean(GlobalParameter.ISSUE_REASON_HIDDEN, me, pp);
storeGlobalParameter(GlobalParameter.REQUIRED_ROLE_FOR_REQUESTING_ACCESS, me, pp);
storeGlobalParameter(GlobalParameter.COMMENT_RENDER_ENGINE, me, pp);
storeGlobalParameter(GlobalParameter.DEFAULT_REPORT, me, pp);
}
// in java/org/tigris/scarab/actions/ModifyModule.java
private void storeGlobalParameterAsBoolean(String name, Module me, ParameterParser pp) throws TorqueException
{
boolean storageValue = pp.getBoolean(name);
GlobalParameterManager
.setBoolean(name, me, storageValue);
}
// in java/org/tigris/scarab/actions/ModifyModule.java
private void storeGlobalParameter(String name, Module me, ParameterParser pp) throws TorqueException
{
String requiredRole = pp.getString(name);
if (null == requiredRole)
{
requiredRole = "";
}
GlobalParameterManager.setString(name, me, requiredRole);
}
// in java/org/tigris/scarab/actions/QueryList.java
private boolean setStartpage(List<Query> queries, Query newStartQuery) throws TorqueException
{
boolean addedAsStartQuery = false;
Iterator<Query> iter = queries.iterator();
while(iter.hasNext())
{
Query query = iter.next();
if (query.getQueryId().equals(newStartQuery.getQueryId()))
{
query.setHomePage(true);
addedAsStartQuery=true;
}
else
{
query.setHomePage(false);
}
query.save();
}
return addedAsStartQuery;
}
// in java/org/tigris/scarab/actions/admin/BaseConditionEdit.java
public void doDelete(RunData data, TemplateContext context) throws TorqueException, Exception
{
IntakeTool intake = getIntakeTool(context);
Group attrGroup = intake.get("ConditionEdit", IntakeTool.DEFAULT_KEY);
data.getParameters().remove(attrGroup.get("ConditionsArray").getKey());
updateObject(data, context, null);
}
// in java/org/tigris/scarab/actions/admin/BaseConditionEdit.java
private void delete(RunData data, TemplateContext context) throws TorqueException, Exception
{
int nObjectType = data.getParameters().getInt("obj_type");
Criteria crit = new Criteria();
switch (nObjectType)
{
case ScarabConstants.TRANSITION_OBJECT:
Integer tranId = data.getParameters().getInteger("transition_id");
crit.add(ConditionPeer.TRANSITION_ID, tranId);
TransitionManager.getMethodResult().remove(TransitionManager.getInstance(tranId), TransitionManager.GET_CONDITIONS);
break;
case ScarabConstants.GLOBAL_ATTRIBUTE_OBJECT:
crit.add(ConditionPeer.ATTRIBUTE_ID, data.getParameters().getInt("attId"));
crit.add(ConditionPeer.MODULE_ID, 0);
crit.add(ConditionPeer.ISSUE_TYPE_ID, 0);
break;
case ScarabConstants.MODULE_ATTRIBUTE_OBJECT:
crit.add(ConditionPeer.ATTRIBUTE_ID, data.getParameters().getInt("attId"));
crit.add(ConditionPeer.MODULE_ID, data.getParameters().getInt("module_id"));
crit.add(ConditionPeer.ISSUE_TYPE_ID, data.getParameters().getInt("issueTypeId"));
break;
case ScarabConstants.NOTIFICATION_ATTRIBUTE_OBJECT:
ScarabRequestTool scarabR = getScarabRequestTool(context);
ScarabUser user = (ScarabUser)data.getUser();
if(user == null)
{
throw new TorqueException("No user found in RunData during Notification customization (constraints on attributes)");
}
Module module = scarabR.getCurrentModule();
if(module == null)
{
throw new TorqueException("No module found in RunData during Notification customization (constraints on attributes)");
}
NotificationRulePeer.deleteConditions(user, module);
return;
}
ConditionPeer.doDelete(crit);
ConditionManager.clear();
TransitionManager.clear();
}
// in java/org/tigris/scarab/actions/ChangeNotificationStatus.java
private void modifyInDatabase(NotificationRule rule) throws TorqueException, Exception
{
if (equalsDefaultCustomization(rule))
{
if (rule.isNew())
{
// don't need to create this rule
}
else
{
// can safely remove this rule
ObjectKey pk = rule.getPrimaryKey();
NotificationRulePeer.doDelete(pk);
}
}
else
{
// need to store this rule
rule.save();
}
}
// in java/org/tigris/scarab/actions/AssignIssue.java
private int removeUserFromIssue(ScarabUser user, Issue issue) throws TorqueException
{
return removeUserFromIssue(user, null, issue);
}
// in java/org/tigris/scarab/actions/AssignIssue.java
private int removeUserFromIssue(ScarabUser user, Attribute attribute, Issue issue) throws TorqueException
{
Set<ArrayList> userSet = issue.getAssociatedUsers();
return removeUserFromUserSet(user, attribute, userSet);
}
// in java/org/tigris/scarab/actions/AssignIssue.java
private int removeUserFromUserSet(ScarabUser user, Attribute attribute, Set<ArrayList> userSet) throws TorqueException
{
Integer userId = user.getUserId();
Iterator<ArrayList> iter = userSet.iterator();
Collection toBeRemoved = new ArrayList();
while(iter.hasNext())
{
ArrayList entry = iter.next();
ScarabUser su = (ScarabUser)entry.get(1);
if (su.equals(user))
{
if(attribute != null)
{
Attribute entryAttribute = (Attribute)entry.get(0);
if (!entryAttribute.equals(attribute))
{
continue;
}
}
toBeRemoved.add(entry);
}
}
userSet.removeAll(toBeRemoved);
int removeCounter = toBeRemoved.size();
return removeCounter;
}
// in java/org/tigris/scarab/actions/AssignIssue.java
private int addUsersToList(ScarabUser user, Module module, Map userAttributes, StringBuffer msg) throws Exception, TorqueException
{
int returnCode;
Map userMap = user.getAssociatedUsersMap();
if (userAttributes != null && userAttributes.size() > 0)
{
boolean isUserAttrRemoved = false;
List removedUserAttrs = null;
for (Iterator it = userAttributes.keySet().iterator(); it.hasNext(); )
{
String userId = (String)it.next();
List item = new ArrayList();
String attrId = (String)userAttributes.get(userId);
Attribute attribute = AttributeManager
.getInstance(new Integer(attrId));
ScarabUser su = ScarabUserManager
.getInstance(new Integer(userId));
item.add(attribute);
item.add(su);
List issues = (List)user.getAssignIssuesList();
for (int j=0; j<issues.size(); j++)
{
Issue issue = (Issue)issues.get(j);
Long issueId = issue.getIssueId();
Set userList = (Set) userMap.get(issueId);
if (userList == null)
{
userList = new HashSet();
}
List<Attribute> attributeList = module
.getUserAttributes(issue.getIssueType(), true);
if (!attributeList.contains(attribute))
{
if (removedUserAttrs == null)
{
removedUserAttrs = new ArrayList();
removedUserAttrs.add(attribute);
msg.append("'").append(attribute.getName())
.append("'");
}
else if (!removedUserAttrs.contains(attribute))
{
removedUserAttrs.add(attribute);
msg.append(", '").append(attribute.getName())
.append("'");
}
isUserAttrRemoved = true;
}
else
{
removeUserFromUserSet(su, null, userList); // remove all user entries from set.
cleanupMultiAssignEntries(attribute, userList, attributeList);
userList.add(item);
// userMap.put(issueId, userList);
// user.setAssociatedUsersMap(userMap);
}
}
}
if (!isUserAttrRemoved)
{
returnCode = USERS_ADDED;
}
else
{
returnCode = USERS_REMOVED;
}
}
else
{
returnCode = ERR_NO_USERS_SELECTED;
}
return returnCode;
}
// in java/org/tigris/scarab/reports/ReportBridge.java
public void setQueryKey(String key)
throws TorqueException
{
torqueReport.setQueryKey(key);
}
// in java/org/tigris/scarab/reports/ReportBridge.java
public void setScopeId(Integer id)
throws TorqueException
{
torqueReport.setScopeId(id);
}
// in java/org/tigris/scarab/reports/ReportBridge.java
public void setUserId(Integer id)
throws TorqueException
{
torqueReport.setUserId(id);
}
// in java/org/tigris/scarab/reports/ReportBridge.java
public Scope getScope()
throws TorqueException
{
return torqueReport.getScope();
}
// in java/org/tigris/scarab/reports/ReportBridge.java
public Module getModule()
throws TorqueException
{
Module module = null;
if (torqueReport.getModuleId() != null)
{
module = ModuleManager.getInstance(torqueReport.getModuleId());
}
return module;
}
// in java/org/tigris/scarab/reports/ReportBridge.java
public void setModule(Module v)
throws TorqueException
{
reportDefn.setModuleIssueTypes(null);
if (v == null)
{
torqueReport.setModuleId((Integer)null);
}
else
{
torqueReport.setModuleId(v.getModuleId());
if (torqueReport.getIssueTypeId() != null)
{
ModuleIssueType mit = new ModuleIssueType();
mit.setModuleId(v.getModuleId());
mit.setIssueTypeId(torqueReport.getIssueTypeId());
reportDefn.addModuleIssueType(mit);
}
}
}
// in java/org/tigris/scarab/reports/ReportBridge.java
public void setIssueType(IssueType v)
throws TorqueException
{
reportDefn.setModuleIssueTypes(null);
if (v == null)
{
// issue type id cannot be null
torqueReport.setIssueTypeId(ScarabConstants.INTEGER_0);
}
else
{
torqueReport.setIssueTypeId(v.getIssueTypeId());
if (torqueReport.getModuleId() != null)
{
ModuleIssueType mit = new ModuleIssueType();
mit.setModuleId(torqueReport.getModuleId());
mit.setIssueTypeId(v.getIssueTypeId());
reportDefn.addModuleIssueType(mit);
}
}
}
// in java/org/tigris/scarab/reports/ReportBridge.java
public MITList getMITList()
throws TorqueException
{
MITList mitList = null;
List mits = reportDefn.getModuleIssueTypes();
if (mits != null)
{
Log.get().debug("mits were not null");
mitList = new MITList();
mitList.setScarabUser(this.torqueReport.getScarabUser());
for (Iterator i = mits.iterator(); i.hasNext();)
{
ModuleIssueType mit = (ModuleIssueType)i.next();
MITListItem item = new MITListItem();
item.setModuleId(mit.getModuleId());
item.setIssueTypeId(mit.getIssueTypeId());
mitList.addMITListItem(item);
}
}
return mitList;
}
// in java/org/tigris/scarab/workflow/CheapWorkflow.java
public List filterConditionalTransitions(List transitions, Issue issue) throws TorqueException {
try {
boolean blockedIssue = issue.isBlocked();
if (transitions != null) {
for (int i=transitions.size()-1; i>=0; i--) {
Transition tran = (Transition)transitions.get(i);
if (blockedIssue && tran.getDisabledIfBlocked()) {
transitions.remove(i);
continue;
}
List conditions = tran.getConditions();
if (null != conditions && conditions.size() > 0) {
boolean bRemove = true;
for (Iterator itReq = conditions.iterator(); bRemove && itReq.hasNext(); ) {
Condition cond = (Condition)itReq.next();
bRemove = !evaluate(cond, issue);
}
if (bRemove) {
transitions.remove(i);
}
}
}
}
} catch (Exception e) {
Log.get().error("filterConditionalTransitions: " + e);
}
return transitions;
}
// in java/org/tigris/scarab/workflow/CheapWorkflow.java
private boolean evaluate(final Condition cond, final Issue issue) throws TorqueException {
boolean bEval = false;
Attribute requiredAttribute = cond.getAttributeOption().getAttribute();
Integer optionId = cond.getOptionId();
AttributeValue av = issue.getAttributeValue(requiredAttribute);
if (av != null) {
Integer issueOptionId = av.getOptionId();
if (issueOptionId != null && issueOptionId.equals(optionId)) {
bEval = true;
}
}
return bEval;
}
// in java/org/tigris/scarab/workflow/IssueState.java
public SkipFiltering createIssueChecker(String setMarkerFunction, int indent) throws TorqueException, ScarabException
{
String result = "";
List<Attribute> attributes = null;
Module module = issue.getModule();
IssueType issueType = issue.getIssueType();
attributes = issueType.getActiveAttributes(module);
Iterator<Attribute> iter = attributes.iterator();
while (iter.hasNext())
{
Attribute attribute = iter.next();
RModuleAttribute rma = module.getRModuleAttribute(attribute, issueType);
result += createIssueChecker(rma, setMarkerFunction, indent);
}
String prepend;
if(result.length() > 0)
{
prepend="\n";
}
else
{
prepend = "/* No conditional attributes found for this module/issueType */";
}
return new SimpleSkipFiltering(prepend+result);
}
// in java/org/tigris/scarab/workflow/IssueState.java
private String createIssueChecker(RModuleAttribute rma, String setMarkerFunction, int indent) throws TorqueException, ScarabException
{
String result = "";
boolean isRequired = rma.getRequired();
if(!isRequired)
{
List<Condition> conditions = rma.getConditions();
Iterator<Condition> iter = conditions.iterator();
while(iter.hasNext())
{
Condition condition = iter.next();
result += condition.createConditionCheckerScript(rma, setMarkerFunction, indent);
}
}
return result;
}
// in java/org/tigris/scarab/workflow/IssueState.java
public boolean isSealed() throws TorqueException
{
boolean result = false;
String status = Environment.getConfigurationProperty("scarab.common.status.id", null);
if (status != null)
{
String value = Environment.getConfigurationProperty("scarab.common.status.sealed", null);
if(value != null)
{
AttributeValue attval = issue.getAttributeValue(status);
if(attval != null && attval.getValue().equals(value))
{
result = true;
}
}
}
return result;
}
// in java/org/tigris/scarab/workflow/IssueState.java
public boolean isOnHold() throws TorqueException
{
boolean result = false;
String status = Environment.getConfigurationProperty("scarab.common.status.id", null);
if (status != null)
{
String value = Environment.getConfigurationProperty("scarab.common.status.onhold", null);
if(value != null)
{
AttributeValue attval = issue.getAttributeValue(status);
if(attval != null && attval.getValue().equals(value))
{
result = true;
}
}
}
return result;
}
// in java/org/tigris/scarab/workflow/IssueState.java
public boolean isActive() throws TorqueException
{
return !(isOnHold() || isSealed());
}
// in java/org/tigris/scarab/workflow/IssueState.java
public Attribute getStatusAttribute() throws TorqueException
{
Attribute attribute = null;
String attributeName = Environment.getConfigurationProperty("scarab.common.status.id", null);
if(attributeName != null)
{
attribute = issue.getAttribute(attributeName);
}
return attribute;
}
// in java/org/tigris/scarab/workflow/IssueState.java
public Attribute getOnHoldExpirationDate() throws TorqueException
{
Attribute attribute = null;
String attributeName = Environment.getConfigurationProperty("scarab.common.status.onhold.dateProperty", null);
if(attributeName != null)
{
attribute = issue.getAttribute(attributeName);
}
return attribute;
}
// in java/org/tigris/scarab/workflow/IssueState.java
public Date getOnHoldUntil() throws TorqueException, ParseException
{
Date date = null;
String attributeName = Environment.getConfigurationProperty("scarab.common.status.onhold.dateProperty", null);
if (attributeName != null)
{
AttributeValue dateValue = issue.getAttributeValue(attributeName);
if(dateValue!=null)
{
String value = dateValue.getValue();
if (value != null && value.length() > 0)
{
date = DateAttribute.toDate(value);
}
}
}
return date;
}
// in java/org/tigris/scarab/util/xmlissues/ScarabIssues.java
void doHandleDependencies()
throws ScarabException, TorqueException
{
LOG.debug("Number of dependencies found: " + allDependencies.size());
for (Iterator itr = allDependencies.iterator(); itr.hasNext();)
{
final Object[] data = (Object[])itr.next();
final ActivitySet activitySetOM = (ActivitySet) data[0];
final XmlActivity activity = (XmlActivity) data[1];
final Dependency dependency = activity.getDependency();
final String child = (String)issueXMLMap.get(dependency.getChild());
final String parent = (String)issueXMLMap.get(dependency.getParent());
if (parent == null || child == null)
{
if(null != parent || null != child)
{
// add a comment into the issue that informs of the dependency
final Issue issueOM = IssueManager.getIssueById(null == parent ? child : parent);
final Attachment attachmentOM = new Attachment();
attachmentOM.setName("comment");
attachmentOM.setTypeId(Attachment.COMMENT__PK);
attachmentOM.setMimeType("text/plain");
// TODO i18n this
final String text = "Dependency \""
+ parent + " (originally " + dependency.getParent() + ") " + dependency.getType() + ' '
+ child + " (originally " + dependency.getParent()
+ ") \" was not imported due to "
+ (null == parent ? dependency.getParent() : dependency.getChild()) + " not being resolved";
attachmentOM.setData(text);
issueOM.addComment(attachmentOM, ScarabUserManager.getInstance("Administrator"));
}
LOG.debug("Could not find issues: parent: " + parent + " child: " + child);
LOG.debug("----------------------------------------------------");
continue;
}
LOG.debug("doHandleDependencies: " + dependency);
if (getImportTypeCode() == UPDATE_SAME_DB)
{
LOG.error("[TODO] update-same-db import type not yet implemented");
// trick here is that dependencies don't have ids or unique keys to find the
// correct existing instance against.
}
else
{
try
{
final String type = dependency.getType();
final Depend newDependOM = DependManager.getInstance();
final Issue parentIssueOM = IssueManager.getIssueById(parent);
final Issue childIssueOM = IssueManager.getIssueById(child);
newDependOM.setDefaultModule(parentIssueOM.getModule());
newDependOM.setObservedId(parentIssueOM.getIssueId());
newDependOM.setObserverId(childIssueOM.getIssueId());
newDependOM.setDependType(type);
LOG.debug("Dep: " + type + " Parent: " + parent + " Child: " + child);
LOG.debug("XML Activity id: " + activity.getId());
if (activity.isAddDependency())
{
parentIssueOM
.doAddDependency(activitySetOM, newDependOM, childIssueOM, null);
LOG.debug("Added Dep Type: " + type + " Parent: " + parent + " Child: " + child);
LOG.debug("----------------------------------------------------");
}
else if (activity.isDeleteDependency())
{
parentIssueOM
.doDeleteDependency(activitySetOM, newDependOM, null);
LOG.debug("Deleted Dep Type: " + type + " Parent: " + parent + " Child: " + child);
LOG.debug("----------------------------------------------------");
}
else if (activity.isUpdateDependency())
{
final Depend oldDependOM = parentIssueOM.getDependency(childIssueOM);
if (oldDependOM == null)
{
throw new IllegalArgumentException ("Whoops! Could not find the original dependency!"); //EXCEPTION
}
// we definitely know we are doing an update here.
newDependOM.setDeleted(false);
parentIssueOM
.doChangeDependencyType(activitySetOM, oldDependOM, newDependOM, null);
LOG.debug("Updated Dep Type: " + type + " Parent: " + parent + " Child: " + child);
LOG.debug("Old Type: " + oldDependOM.getDependType().getName() + " New type: " + newDependOM.getDependType().getName());
LOG.debug("----------------------------------------------------");
}
}
catch (Exception e)
{
LOG.error("Failed to handle dependencies", e);
throw new ScarabException(new L10NKey("Failed to handle dependencies <localize me>"),e); //EXCEPTION
}
}
}
}
// in java/org/tigris/scarab/util/xmlissues/ScarabIssues.java
private void doIssueValidateEvent(final XmlModule module,
final XmlIssue issue)
throws TorqueException
{
// Check for the existance of the module.
Module moduleOM = null;
try
{
moduleOM = getModuleForIssue(module,issue);
if (moduleOM == null)
{
throw new IllegalArgumentException(); //EXCEPTION
}
// TODO: Handle user import. Until then, ignore the
// module's owner.
//importUsers.add(module.getOwner());
}
catch (Exception e)
{
final Object[] args = (issue.hasModuleCode()
? new Object[]{null, issue.getModuleCode(), module.getDomain()}
: new Object[]{module.getName(), module.getCode(), module.getDomain()});
final String error = Localization.format(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"CouldNotFindModule", args);
importErrors.add(error);
}
// Check for the existance of the issue type.
IssueType issueTypeOM = null;
try
{
issueTypeOM = IssueType.getInstance(issue.getArtifactType());
if (issueTypeOM == null)
{
throw new IllegalArgumentException(); //EXCEPTION
}
if (!moduleOM.getRModuleIssueType(issueTypeOM).getActive())
{
final String error = Localization.format(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"IssueTypeInactive", issue.getArtifactType());
importErrors.add(error);
}
List moduleAttributeList = null;
if (moduleOM != null)
{
moduleAttributeList = moduleOM.getAttributes(issueTypeOM);
}
final List activitySets = issue.getActivitySets();
for (Iterator itr = activitySets.iterator(); itr.hasNext();)
{
final XmlActivitySet activitySet = (XmlActivitySet) itr.next();
if (activitySet.getCreatedBy() != null)
{
importUsers.add(activitySet.getCreatedBy());
}
if (activitySet.getAttachment() != null)
{
final String attachCreatedBy = activitySet.getAttachment().getCreatedBy();
if (attachCreatedBy != null)
{
importUsers.add(attachCreatedBy);
}
}
// Validate the activity set's type.
try
{
final ActivitySetType ttOM =
ActivitySetTypeManager.getInstance(activitySet.getType());
if (ttOM == null)
{
throw new IllegalArgumentException(); //EXCEPTION
}
}
catch (Exception e)
{
final String error = Localization.format(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"CouldNotFindActivitySetType", activitySet.getType());
importErrors.add(error);
}
// Validate the activity set's date.
validateDate(activitySet.getCreatedDate(), true);
final List activities = activitySet.getActivities();
for (Iterator itrb = activities.iterator(); itrb.hasNext();)
{
validateActivity(moduleOM, issueTypeOM, moduleAttributeList,
activitySet, (XmlActivity) itrb.next());
}
}
}
catch (Exception e)
{
final String error = Localization.format(
ScarabConstants.DEFAULT_BUNDLE_NAME,
getLocale(),
"CouldNotFindIssueType", issue.getArtifactType());
importErrors.add(error);
}
}
// in java/org/tigris/scarab/util/xmlissues/ScarabIssues.java
private Issue createNewIssue(final XmlModule module, final XmlIssue issue, final String id)
throws TorqueException,ScarabException
{
// get the instance of the module
final Module moduleOM = getModuleForIssue(module,issue);
// get the instance of the issue type
final IssueType issueTypeOM = IssueType.getInstance(issue.getArtifactType());
issueTypeOM.setName(issue.getArtifactType());
// get me a new issue since we couldn't find one before
final Issue issueOM = Issue.getNewInstance(moduleOM, issueTypeOM);
// The import data may nominate its ID
if (id != null) {
// This will cause Issue.save() to use this ID
issueOM.setFederatedId(id);
}
// create the issue in the database
// Add the mapping between the issue id and the id that was created.
// This mapping is used dependency checking and printing out in
// results list of original id and new id. The original issue id can be
// null. In this case, have the original id show as 'null (index)'
// where index is count into the issueXMLMap. We add the index to keep
// the key unique. This substitute original id also shouldn't interfere
// w/ issueXMLMap's use dependency checking.
String issueID = "Null (" + Integer.toString(issueXMLMap.size()) + ")";
if(issue.getId() != null)
{
issueID = (issue.hasModuleCode()?"":module.getCode())
+ issue.getId();
}
issueXMLMap.put(issueID, issueOM.getUniqueId());
LOG.debug("Created new Issue: " + issueOM.getUniqueId());
return issueOM;
}
// in java/org/tigris/scarab/util/xmlissues/ScarabIssues.java
private void doIssueEvent(final XmlModule module, final XmlIssue issue)
throws TorqueException,ScarabException,ParseException
{
/////////////////////////////////////////////////////////////////////////////////
// Get me an issue
Issue issueOM = null;
final String issueID = (issue.hasModuleCode() ? "" : module.getCode()) + issue.getId();
if (getImportTypeCode() == CREATE_SAME_DB || getImportTypeCode() == CREATE_DIFFERENT_DB)
{
// Check if the new issue nominates an ID and if the database does
// not already contain an issue with that ID
if (issue.getId() != null && IssueManager.getIssueById(issueID) == null)
{
// Create the new issue with the nominated ID
issueOM = createNewIssue(module, issue, issue.getId());
}
else
{
// Crate the new issue with an automatically allocated ID
issueOM = createNewIssue(module, issue, null);
}
}
else if (getImportTypeCode() == UPDATE_SAME_DB) // nice to specify just for searching/refactoring
{
issueOM = IssueManager.getIssueById(issueID);
if (issueOM == null)
{
issueOM = createNewIssue(module, issue, null);
}
else
{
LOG.debug("Found Issue in db: " + issueOM.getUniqueId());
}
}
/////////////////////////////////////////////////////////////////////////////////
// Loop over the XML activitySets
final List activitySets = issue.getActivitySets();
LOG.debug("-----------------------------------");
LOG.debug("Number of ActivitySets in Issue: " + activitySets.size());
for (Iterator itr = activitySets.iterator(); itr.hasNext();)
{
final XmlActivitySet activitySet = (XmlActivitySet) itr.next();
LOG.debug("Processing ActivitySet: " + activitySet.getId());
/////////////////////////////////////////////////////////////////////////////////
// Deal with the attachment for the activitySet
final XmlAttachment activitySetAttachment = activitySet.getAttachment();
Attachment activitySetAttachmentOM = null;
if (activitySetAttachment != null)
{
if (getImportTypeCode() == UPDATE_SAME_DB)
{
try
{
activitySetAttachmentOM = AttachmentManager
.getInstance(activitySetAttachment.getId());
LOG.debug("Found existing ActivitySet Attachment");
}
catch (TorqueException e)
{
activitySetAttachmentOM = createAttachment(issueOM, activitySetAttachment);
}
}
else
{
activitySetAttachmentOM = createAttachment(issueOM, activitySetAttachment);
LOG.debug("Created ActivitySet Attachment object");
}
}
else
{
LOG.debug("OK- No Attachment in this ActivitySet");
}
/////////////////////////////////////////////////////////////////////////////////
// Attempt to get the activitySet OM
boolean alreadyCreated = false;
ActivitySet activitySetOM = null;
if (getImportTypeCode() == UPDATE_SAME_DB)
{
try
{
activitySetOM = ActivitySetManager.getInstance(activitySet.getId());
LOG.debug("Found ActivitySet: " + activitySet.getId() +
" in db: " + activitySetOM.getActivitySetId());
}
catch (Exception e)
{
activitySetOM = ActivitySetManager.getInstance();
}
}
else
{
// first try to get the ActivitySet from the internal map
if (activitySetIdMap.containsKey(activitySet.getId()))
{
activitySetOM = ActivitySetManager.getInstance(
(String)activitySetIdMap.get(activitySet.getId()));
alreadyCreated = true;
LOG.debug("Found ActivitySet: " + activitySet.getId() +
" in map: " + activitySetOM.getActivitySetId());
}
else // it hasn't been encountered previously
{
activitySetOM = ActivitySetManager.getInstance();
LOG.debug("Created new ActivitySet");
}
}
final ScarabUser activitySetCreatedByOM = findUser(activitySet.getCreatedBy());
if (LOG.isDebugEnabled())
{
LOG.debug("ActivitySet: " + activitySet.getId() + "; of type: " + activitySet.getType() + "; by: " + activitySet.getCreatedBy());
LOG.debug(" alreadyCreated: " + alreadyCreated);
}
if (!alreadyCreated)
{
// Populate the ActivitySet
// Get the ActivitySet type/createdby values (we know these are valid)
final ActivitySetType ttOM = ActivitySetTypeManager.getInstance(activitySet.getType());
activitySetOM.setActivitySetType(ttOM);
if( activitySetCreatedByOM != null ){
activitySetOM.setCreatedBy(activitySetCreatedByOM.getUserId());
}
else
{
// Anonymous user. better than nothing.
try {
activitySetOM.setCreatedBy(ScarabUserManager.getAnonymousUser().getUserId());
} catch (Exception e) {
LOG.error("doIssueEvent: Cannot get Anonymous user: e");
}
}
activitySetOM.setCreatedDate(activitySet.getCreatedDate().getDate());
if (activitySetAttachmentOM != null)
{
activitySetAttachmentOM.save();
activitySetOM.setAttachment(activitySetAttachmentOM);
}
activitySetOM.save();
if( activitySet.getId() != null){
// if id is valid, save for later re-use.
activitySetIdMap.put(activitySet.getId(),
activitySetOM.getPrimaryKey().toString());
}
}
// Determine if this ActivitySet should be marked as the
// creation event
final ActivitySet creationSet = issueOM.getActivitySetRelatedByCreatedTransId();
if (ActivitySetTypePeer.CREATE_ISSUE__PK
.equals(activitySetOM.getTypeId())
||
(ActivitySetTypePeer.MOVE_ISSUE__PK
.equals(activitySetOM.getTypeId()) &&
(creationSet == null || activitySetOM.getCreatedDate()
.before(creationSet.getCreatedDate()))) )
{
issueOM.setActivitySetRelatedByCreatedTransId(activitySetOM);
issueOM.save();
}
/////////////////////////////////////////////////////////////////////////////////
// Deal with changing user attributes. this code needs to be in this *strange*
// location because we look at the entire activityset in order to determine
// that this is a change user activity set. of course in the future, it would
// be really nice to create an activityset/activiy type that more accurately
// reflects what type of change this is. so that it is easier to case for. for
// now, we just look at some fingerprints to determine this information. -JSS
if (activitySet.isChangeUserAttribute())
{
final List activities = activitySet.getActivities();
final XmlActivity activityA = (XmlActivity)activities.get(0);
final XmlActivity activityB = (XmlActivity)activities.get(1);
final ScarabUser assigneeOM = findUser(activityA.getOldUser());
final ScarabUser assignerOM = findUser(activityB.getNewUser());
final Attribute oldAttributeOM = Attribute.getInstance(activityA.getAttribute());
final AttributeValue oldAttValOM = issueOM.getUserAttributeValue(assigneeOM, oldAttributeOM);
if (oldAttValOM == null)
{
LOG.error("User '" + assigneeOM.getName() + "' was not previously '" + oldAttributeOM.getName() + "' to the issue!");
}
// Get the Attribute associated with the new Activity
final Attribute newAttributeOM = Attribute.getInstance(activityB.getAttribute());
issueOM.changeUserAttributeValue(activitySetOM,
assigneeOM,
assignerOM,
oldAttValOM,
newAttributeOM, null);
LOG.debug("-------------Updated User AttributeValue------------");
continue;
}
/////////////////////////////////////////////////////////////////////////////////
// Deal with the activities in the activitySet
final List activities = activitySet.getActivities();
LOG.debug("Number of Activities in ActivitySet: " + activities.size());
final LinkedMap avMap = issueOM.getModuleAttributeValuesMap();
LOG.debug("Total Module Attribute Values: " + avMap.size());
for (Iterator itrb = activities.iterator(); itrb.hasNext();)
{
final XmlActivity activity = (XmlActivity) itrb.next();
LOG.debug("Looking at activity id: " + activity.getId());
// Get the Attribute associated with the Activity
final Attribute attributeOM = Attribute.getInstance(activity.getAttribute());
// deal with the activity attachment (if there is one)
final XmlAttachment activityAttachment = activity.getAttachment();
Attachment activityAttachmentOM = null;
if (activityAttachment != null)
{
// look for an existing attachment in the activity
// the case is when we have a URL and we create it
// and then delete it, the attachment id is still the
// same so there is no reason to re-create the attachment
// again.
final String previousXmlId = activityAttachment.getId();
final String previousId = (String)attachmentIdMap.get(previousXmlId);
if (previousId == null)
{
activityAttachmentOM = createAttachment(issueOM, activityAttachment);
activityAttachmentOM.save();
attachmentIdMap.put(previousXmlId, activityAttachmentOM.getPrimaryKey().toString());
// Special case. After the Attachment object has been
// saved, if the ReconcilePath == true, then assume
// that the fileName is an absolute path to a file and
// copy it to the right directory
// structure under Scarab's path.
if (allowFileAttachments && activityAttachment.getReconcilePath())
{
try
{
activityAttachmentOM
.copyFileFromTo(activityAttachment.getFilename(),
activityAttachmentOM.getFullPath());
}
catch (FileNotFoundException ex)
{
// FIXME correct error message "ExceptionCouldNotFindFile"
throw new ScarabException(L10NKeySet.ExceptionGeneral,ex);
}
catch (IOException ex)
{
// FIXME correct error message "ExceptionCouldNotReadFile"
throw new ScarabException(L10NKeySet.ExceptionGeneral,ex);
}
}
LOG.debug("Created Activity Attachment object");
}
else
{
activityAttachmentOM = AttachmentManager
.getInstance(previousId);
LOG.debug("Found existing Activity Attachment");
}
}
else
{
LOG.debug("OK- No Attachment in this Activity");
}
// deal with null attributes (need to do this before we create the
// activity right below because this will create its own activity).
if (attributeOM.equals(nullAttribute))
{
// add any dependency activities to a list for later processing
if (isDependencyActivity(activity))
{
if (!isDuplicateDependency(activity))
{
final Object[] obj = {activitySetOM, activity, activityAttachmentOM};
allDependencies.add(obj);
dependActivitySetId.add(activity.getDependency());
LOG.debug("-------------Stored Dependency # "
+ allDependencies.size() + '[' + activity.getDependency() + ']');
continue;
}
}
else
{
// create the activity record.
ActivityManager.createTextActivity(issueOM, nullAttribute, activitySetOM,
ActivityType.getActivityType(activity.getActivityType()), activity.getDescription(), activityAttachmentOM,
activity.getOldValue(), activity.getNewValue());
LOG.debug("-------------Saved Null Attribute-------------");
continue;
}
}
// create the activityOM
createActivity(activity, module,
issueOM, attributeOM, activitySetOM);
// check to see if this is a new activity or an update activity
AttributeValue avalOM = null;
for (Iterator moduleAttributeValueItr = avMap.mapIterator();
moduleAttributeValueItr.hasNext() && avalOM == null;)
{
final AttributeValue testAvalOM = (AttributeValue)
avMap.get(moduleAttributeValueItr.next());
final Attribute avalAttributeOM = testAvalOM.getAttribute();
LOG.debug("Checking Attribute match: " + avalAttributeOM.getName() +
" against: " + attributeOM.getName());
if (avalAttributeOM.equals(attributeOM))
{
avalOM = testAvalOM;
}
}
if (avalOM != null)
{
final Attribute avalAttributeOM = avalOM.getAttribute();
LOG.debug("Attributes match!");
AttributeValue avalOM2 = null;
if (!activity.isNewActivity())
{
LOG.debug("Activity is not new.");
avalOM2 = AttributeValue.getNewInstance(
avalAttributeOM.getAttributeId(),
avalOM.getIssue());
avalOM2.setProperties(avalOM);
}
if (avalAttributeOM.isOptionAttribute())
{
LOG.debug("We have an Option Attribute: " +
avalAttributeOM.getName());
final AttributeOption newAttributeOptionOM =
AttributeOptionManager.getInstance(
attributeOM, activity.getNewOption(),
issueOM.getModule(),
issueOM.getIssueType());
if (activity.isNewActivity())
{
if (newAttributeOptionOM != null)
{
avalOM.setOptionId(newAttributeOptionOM.getOptionId());
avalOM.startActivitySet(activitySetOM);
avalOM.setAttribute(attributeOM);
avalOM.save();
LOG.debug("-------------Saved Attribute Value-------------");
}
else
{
LOG.warn("NewAttributeOptionOM is null for " +
activity.getNewOption());
}
}
else if(newAttributeOptionOM != null)
{
avalOM2.setOptionId(newAttributeOptionOM.getOptionId());
final HashMap map = new HashMap();
map.put(avalOM.getAttributeId(), avalOM2);
issueOM.setAttributeValues(activitySetOM, map, null, activitySetCreatedByOM);
LOG.debug("-------------Saved Option Attribute Change-------------");
}
}
else if (avalAttributeOM.isUserAttribute())
{
LOG.debug("We have a User Attribute: "
+ avalAttributeOM.getName());
if (activity.isNewActivity())
{
// Don't need to pass in the attachment because
// it is already in the activitySetOM.
// If we can't get an assignee new-user, then
// use the activity set creator as assignee.
ScarabUser assigneeOM = findUser(activity.getNewUser());
assigneeOM = (assigneeOM != null)
? assigneeOM: activitySetCreatedByOM;
if( assigneeOM != null ){
issueOM.assignUser(activitySetOM,
assigneeOM, null, avalAttributeOM, null);
}
LOG.debug("-------------Saved User Assign-------------");
}
else if (activity.isRemoveUserActivity())
{
// remove a user activity
final ScarabUser oldUserOM = findUser(activity.getOldUser());
// need to reset the aval because the current one
// is marked as new for some reason which causes an
// insert and that isn't the right behavior here
// (we want an update)
avalOM = null;
for (Iterator i = issueOM.getAttributeValues(
avalAttributeOM).iterator();
i.hasNext() && avalOM == null;)
{
final AttributeValue av = (AttributeValue)i.next();
if (oldUserOM.getUserId().equals(av.getUserId()))
{
avalOM = av;
}
}
if (avalOM == null)
{
if (LOG.isDebugEnabled())
{
LOG.debug("Could not find previous AttributeValue assigning " +
(oldUserOM == null ? "NULL" :
oldUserOM.getUserName()) +
" to attribute " +
avalAttributeOM.getName());
}
}
else
{
// don't need to pass in the attachment because
// it is already in the activitySetOM
issueOM.deleteUser(activitySetOM, oldUserOM,
activitySetCreatedByOM, avalOM, null);
LOG.debug("-------------Saved User Remove-------------");
}
}
}
else if (avalAttributeOM.isTextAttribute() || avalAttributeOM.isIntegerAttribute())
{
LOG.debug("We have a Text Attribute: " + avalAttributeOM.getName());
avalOM.startActivitySet(activitySetOM);
avalOM.setAttribute(attributeOM);
if (activity.isNewActivity())
{
avalOM.setValue(activity.getNewValue());
}
else if (!activity.getNewValue()
.equals(avalOM.getValue()))
{
avalOM2.setValue(activity.getNewValue());
avalOM.setProperties(avalOM2);
}
avalOM.save();
LOG.debug("-------------Saved Attribute Value-------------");
}
}
issueOM.save();
LOG.debug("-------------Saved Issue-------------");
}
}
}
// in java/org/tigris/scarab/util/xmlissues/ScarabIssues.java
private Activity createActivity(final XmlActivity activity,
final XmlModule module,
final Issue issueOM,
final Attribute attributeOM,
final ActivitySet activitySetOM)
throws TorqueException, ParseException, ScarabException
{
Activity activityOM = null;
if (getImportTypeCode() == UPDATE_SAME_DB)
{
try
{
activityOM = ActivityManager.getInstance(activity.getId());
}
catch (Exception e)
{
activityOM = ActivityManager.getInstance();
}
}
else
{
activityOM = ActivityManager.getInstance();
}
activityOM.setIssue(issueOM);
activityOM.setAttribute(attributeOM);
activityOM.setActivityType(ActivityType.OTHER.getCode());
activityOM.setActivitySet(activitySetOM);
if (activity.getEndDate() != null)
{
activityOM.setEndDate(activity.getEndDate().getDate());
}
// Set the attachment for the activity
Attachment newAttachmentOM = null;
if (activity.getAttachment() != null)
{
newAttachmentOM = createAttachment(issueOM, activity.getAttachment());
newAttachmentOM.save();
activityOM.setAttachment(newAttachmentOM);
}
LOG.debug("Created New Activity");
return activityOM;
}
// in java/org/tigris/scarab/util/xmlissues/ScarabIssues.java
private Attachment createAttachment(final Issue issueOM,
final XmlAttachment attachment)
throws TorqueException, ScarabException, ParseException
{
final Attachment attachmentOM = AttachmentManager.getInstance();
attachmentOM.setIssue(issueOM);
final AttachmentType type = AttachmentType.getInstance(attachment.getType());
if (allowFileAttachments || !Attachment.FILE__PK.equals(type.getAttachmentTypeId()))
{
attachmentOM.setName(attachment.getName());
attachmentOM.setAttachmentType(type);
attachmentOM.setMimeType(null != attachment.getMimetype()
? attachment.getMimetype()
: ComponentLocator.getMimeTypeService().getContentType(attachment.getFilename(), null));
attachmentOM.setFileName(attachment.getFilename());
attachmentOM.setData(attachment.getData());
}
else
{
// add a comment that the file will not be imported. An alternative would be
// to skip the activity altogether, but we will then need to check that there
// are other activities or we need to completely ignore the ActivitySet
attachmentOM.setName("comment");
attachmentOM.setTypeId(Attachment.COMMENT__PK);
attachmentOM.setMimeType("text/plain");
String text = "File, " + attachment.getFilename() +
", was not imported. The old description follows:\n\n" + attachment.getName();
final String data = attachment.getData(); // this should be null, but just in case
if (data != null)
{
text += "\n\n" + data;
}
attachmentOM.setData(text);
}
attachmentOM.setCreatedDate(attachment.getCreatedDate().getDate());
final ModifiedDate modifiedDate = attachment.getModifiedDate();
if (modifiedDate != null)
{
attachmentOM.setModifiedDate(modifiedDate.getDate());
}
final ScarabUser creUser = findUser(attachment.getCreatedBy());
if (creUser != null)
{
attachmentOM.setCreatedBy(creUser.getUserId());
}
final String modifiedBy = attachment.getModifiedBy();
if (modifiedBy != null)
{
final ScarabUser modUserOM = findUser(attachment.getModifiedBy());
if (modUserOM != null)
{
attachmentOM.setModifiedBy(modUserOM.getUserId());
}
}
attachmentOM.setDeleted(attachment.getDeleted());
return attachmentOM;
}
// in java/org/tigris/scarab/util/xmlissues/ScarabIssues.java
private ScarabUser findUser(final String userStr)
throws TorqueException,ScarabException
{
ScarabUser user = ScarabUserManager.getInstance(userStr);
if (user == null && userStr != null && userStr.indexOf("@") <0 )
{
LOG.debug("user specified possibly by email address: "+userStr);
// maybe it's an email not a username
user = ScarabUserManager.getInstanceByEmail(userStr);
LOG.debug("found "+user);
}
return user;
}
// in java/org/tigris/scarab/util/xmlissues/ScarabIssues.java
private Module getModuleForIssue(final XmlModule module, final XmlIssue issue)
throws TorqueException, ScarabException
{
if(issue.hasModuleCode() && !issue.getModuleCode().equals(module.getCode()) && !allowGlobalImport){
throw new ScarabException(
new L10NKey("Lacking permission to cross-module import. Contact your administor. <localize me>"));
}
return issue.hasModuleCode()
? ModuleManager.getInstance(module.getDomain(),
null,issue.getModuleCode())
: ModuleManager.getInstance(module.getDomain(),
module.getName(), module.getCode());
}
// in java/org/tigris/scarab/util/xmlissues/ImportIssues.java
protected ScarabIssues insert(
final String name,
final Reader is,
final BeanReader reader)
throws ParserConfigurationException,SAXException,IOException,ScarabException, TorqueException
{
setValidationMode(reader, false);
final ScarabIssues si = (ScarabIssues)reader.parse(is);
si.doHandleDependencies();
LOG.debug("Successfully imported " + name + '!');
return si;
}
// in java/org/tigris/scarab/util/xmlissues/ImportIssues.java
private Reader getScarabFormattedReader(
final Object input,
final ImportType type,
final Module currModule) throws IOException, TransformerException, TorqueException, JDOMException
{
Reader returnValue = null;
if( SCARAB == type )
{
// is in correct format already, just return the input stream
returnValue = readerFor(input);
}
else if( BUGZILLA == type )
{
// Location of the extensions directory for Bugzilla
// Transform configuration, mappings and attachments are here
// TODO move onto resourceDirectory derivative
final String extensions = System.getProperty("catalina.home") + "/../extensions/bugzilla";
// Locate the Bugzilla to Scarab XSL transform
final InputStream xsl = getClass().getResourceAsStream(BUGZILLA_XSL);
// Transform Bugzilla xml to scarab format
// (Trailing '/' to resources is deliberate)
final Reader result = transformXML(
new StreamSource(readerFor(input)), xsl, currModule, extensions);
// insert missing information (module)
returnValue = insertModuleNode(result, currModule);
}
else if( JIRA == type )
{
// transform xml to scarab format
final InputStream xsl = getClass().getResourceAsStream(JIRA_XSL);
final Reader result = transformXML(
new StreamSource(readerFor(input)), xsl, currModule, resourceDirectory);
// insert missing information (module)
returnValue = insertModuleNode(result, currModule);
}
return returnValue;
}
// in java/org/tigris/scarab/util/xmlissues/ImportIssues.java
private Reader insertModuleNode(final Reader result,
final Module currModule)
throws TorqueException, JDOMException, IOException, TransformerException
{
final ScarabUser user = ScarabUserManager.getInstance(currModule.getOwnerId());
// Core Java: org.w3c.dom version (jdk1.4+ compatible)
// final DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
// final Document doc = docBuilder.parse( new InputSource(result) );
// // insert module
// final Element root = doc.getDocumentElement();
// final Element moduleNode = doc.createElement("module");
// final Element idNode = doc.createElement("id");
// final Element parentIdNode = doc.createElement("parent-id");
// final Element nameNode = doc.createElement("name");
// final Element ownerNode = doc.createElement("owner");
// final Element descriptionNode = doc.createElement("description");
// final Element urlNode = doc.createElement("url");
// final Element domainNode = doc.createElement("domain");
// final Element codeNode = doc.createElement("code");
//
// idNode.appendChild(doc.createTextNode(String.valueOf(currModule.getModuleId())));
// parentIdNode.appendChild(doc.createTextNode(String.valueOf(currModule.getParentId())));
// nameNode.appendChild(doc.createTextNode(currModule.getName()));
// ownerNode.appendChild(doc.createTextNode(user.getUserName()));
// descriptionNode.appendChild(doc.createTextNode(currModule.getDescription()));
// urlNode.appendChild(doc.createTextNode(currModule.getUrl()));
// domainNode.appendChild(doc.createTextNode(currModule.getHttpDomain()));
// codeNode.appendChild(doc.createTextNode(currModule.getCode()));
//
// moduleNode.appendChild(idNode);
// moduleNode.appendChild(parentIdNode);
// moduleNode.appendChild(nameNode);
// moduleNode.appendChild(ownerNode);
// moduleNode.appendChild(descriptionNode);
// moduleNode.appendChild(urlNode);
// moduleNode.appendChild(domainNode);
// moduleNode.appendChild(codeNode);
//
// root.appendChild(moduleNode);
// JDom version (jdk1.3 compatible)
final SAXBuilder builder = new SAXBuilder();
builder.setEntityResolver(new EntityResolver()
{
public InputSource resolveEntity(String publicId,
String systemId)
throws SAXException
{
return ImportIssues.this.resolveEntity(this, publicId, systemId);
}
});
final Document doc = builder.build(result);
final Element root = doc.getRootElement();
final Element moduleNode = new Element("module");
final Element idNode = new Element("id");
final Element parentIdNode = new Element("parent-id");
final Element nameNode = new Element("name");
final Element ownerNode = new Element("owner");
final Element descriptionNode = new Element("description");
final Element urlNode = new Element("url");
final Element domainNode = new Element("domain");
final Element codeNode = new Element("code");
idNode.setText(String.valueOf(currModule.getModuleId()));
parentIdNode.setText(String.valueOf(currModule.getParentId()));
nameNode.setText(currModule.getRealName());
ownerNode.setText(user.getUserName());
descriptionNode.setText(currModule.getDescription());
urlNode.setText(currModule.getUrl());
domainNode.setText(currModule.getHttpDomain());
codeNode.setText(currModule.getCode());
moduleNode.addContent(idNode)
.addContent(parentIdNode)
.addContent(nameNode)
.addContent(ownerNode)
.addContent(descriptionNode)
/*
* These are excluded for now, since your database domain may
* not correspond to currModule.getHttpDomain().
.addContent(urlNode)
.addContent(domainNode)
*/
.addContent(codeNode);
root.addContent(2,moduleNode);
return transformXML(new JDOMSource(doc), null, currModule, null);
}
// in java/org/tigris/scarab/util/IssueIdParser.java
public static List getIssueIdTokens(Module module, String text)
throws TorqueException
{
List result = new ArrayList();
RE re = new RE(module.getIssueRegex());
re.setMatchFlags(RE.MATCH_CASEINDEPENDENT);
int pos = 0;
while (re.match(text, pos))
{
Log.get().debug(re.getParen(0) + " found at " + re.getParenStart(0));
result.add(re.getParen(0));
pos = re.getParenEnd(0);
}
return result;
}
// in java/org/tigris/scarab/util/IssueIdParser.java
public static List tokenizeText(Module module, String text)
throws TorqueException
{
List result = new ArrayList();
RE re = new RE(module.getIssueRegex());
re.setMatchFlags(RE.MATCH_CASEINDEPENDENT);
int pos = 0;
while (re.match(text, pos))
{
Log.get().debug(re.getParen(0) + " found at " + re.getParenStart(0));
// Add any text that did not contain an id
if (re.getParenStart(0) > pos)
{
result.add(text.substring(pos, re.getParenStart(0)));
}
String token = re.getParen(0);
String id = getIssueIdFromToken(module, token);
if (id == null)
{
result.add(token);
}
else
{
List tokenId = new ArrayList(2);
tokenId.add(token);
tokenId.add(id);
result.add(tokenId);
}
pos = re.getParenEnd(0);
}
if (pos < text.length())
{
result.add(text.substring(pos));
}
return result;
}
// in java/org/tigris/scarab/util/IssueIdParser.java
public static Map getIssueIds(Module module, String text)
throws TorqueException
{
List tokens = getIssueIdTokens(module, text);
Map idMap = new HashMap(presizeMap(tokens.size()));
Iterator i = tokens.iterator();
while (i.hasNext())
{
String token = (String)i.next();
String id = getIssueIdFromToken(module, token);
if (id != null)
{
idMap.put(token, id);
}
}
return idMap;
}
// in java/org/tigris/scarab/util/word/QueryResult.java
public final Issue getIssue()
throws TorqueException
{
return IssueManager.getInstance(issueId);
}
// in java/org/tigris/scarab/util/word/QueryResult.java
public final String getUniqueId()
throws TorqueException
{
return getIssue().getUniqueId();
}
// in java/org/tigris/scarab/util/word/QueryResult.java
public final List getAttributeValues()
throws TorqueException
{
if(attributeValues==null)
{
attributeValues = new ArrayList();
for(int j=0;j<issueListAttributeColumns.size();j++)
{
RModuleUserAttribute rmua = (RModuleUserAttribute)issueListAttributeColumns.get(j);
List value = null;
if(rmua.isInternal())
{
String attributeId = rmua.getInternalAttribute();
value = getInternalAttributeValue(attributeId);
}
else
{
Integer attributeId = rmua.getAttributeId();
value = getAttributeValue(attributeId);
}
attributeValues.add(value);
}
}
return attributeValues;
}
// in java/org/tigris/scarab/util/word/QueryResult.java
private List getAttributeValue(Integer attributeId)
throws TorqueException
{
List value = new ArrayList();
List attributeValue = getIssue().getAttributeValues(attributeId);
String singleValue = null;
if(attributeId.equals(sortAttrId))
{
if(sortValueId!=null)
{
AttributeValue sortValue = AttributeValueManager.getInstance(sortValueId);
singleValue = sortValue.getDisplayValue(L10N);
}
else
{
singleValue = "";
}
value.add(singleValue);
}
else
{
for(int i=0;i<attributeValue.size();i++)
{
singleValue = ((AttributeValue)attributeValue.get(i)).getDisplayValue(L10N);
value.add( singleValue );
}
}
return value;
}
// in java/org/tigris/scarab/util/word/QueryResult.java
private List getInternalAttributeValue(String attributeId)
throws TorqueException
{
List value = new ArrayList();
if (attributeId.equals(RModuleUserAttribute.CREATED_BY.getName()))
{
ScarabUser user = getIssue().getCreatedBy();
value.add(user.getUserName());
}
else if (attributeId.equals(RModuleUserAttribute.CREATED_DATE.getName()))
{
DateFormat df = new SimpleDateFormat(L10NKeySet.ShortDatePattern.getMessage(L10N));
value.add(df.format(getIssue().getCreatedDate()));
}
else if (attributeId.equals(RModuleUserAttribute.MODIFIED_BY.getName()))
{
ScarabUser user = getIssue().getModifiedBy();
value.add(user.getUserName());
}
else if (attributeId.equals(RModuleUserAttribute.MODIFIED_DATE.getName()))
{
DateFormat df = new SimpleDateFormat(L10NKeySet.ShortDatePattern.getMessage(L10N));
value.add(df.format(getIssue().getModifiedDate()));
}
else if (attributeId.equals(RModuleUserAttribute.MODULE.getName()))
{
value.add(getIssue().getModule().getRealName());
}
else if (attributeId.equals(RModuleUserAttribute.ISSUE_TYPE.getName()))
{
IssueType isueType = getIssue().getIssueType();
value.add(isueType.getDisplayName(getIssue().getModule()));
}
return value;
}
// in java/org/tigris/scarab/util/word/QueryResult.java
public final List getAttributeValuesAsCSV()
throws TorqueException
{
List result = null;
if (getAttributeValues() != null)
{
result = new ArrayList(getAttributeValues().size());
for (Iterator i = getAttributeValues().iterator(); i.hasNext();)
{
List multiVal = (List)i.next();
String csv = StringUtils.join(multiVal.iterator(), ", ");
if(csv.indexOf('\n') > -1)
{
csv = csv.replace('\n', '.');
}
if(csv.indexOf('\r') > -1)
{
csv = csv.replace('\r', '.');
}
result.add(csv);
}
}
return result;
}
// in java/org/tigris/scarab/util/word/LuceneSearchIndex.java
private Document document(Issue issue)
throws TorqueException
{
String issueId = issue.getIssueId().toString();
Document doc = new Document();
doc.add(new Field( ISSUE_ID, issueId, Field.Store.YES, Field.Index.UN_TOKENIZED ));
for(Iterator as = issue.getAttachments().iterator(); as.hasNext();)
{
Attachment a = (Attachment)as.next();
if ( a.getTypeId().equals(AttachmentTypePeer.COMMENT_PK)
&& !a.getDeleted())
{
doc.add(new Field( COMMENT, a.getData(), Field.Store.YES, Field.Index.TOKENIZED ));
}
}
for(Iterator vs = issue.getAttributeValuesMap().values().iterator(); vs.hasNext();)
{
AttributeValue v = (AttributeValue)vs.next();
if( v instanceof StringAttribute
&& !v.getDeleted())
{
doc.add(new Field( ATTRIBUTE_ID + v.getAttributeId().toString(), v.getValue(), Field.Store.YES, Field.Index.TOKENIZED ));
}
}
return doc;
}
// in java/org/tigris/scarab/util/word/IssueSearch.java
public static ScarabUser getSearchingUserPlaceholder()
throws TorqueException
{
if(searchingUserPlaceholder==null)
{
searchingUserPlaceholder = ScarabUserManager.getInstance();
searchingUserPlaceholder.setFirstName("");
searchingUserPlaceholder.setLastName(SEARCHING_USER_KEY);
searchingUserPlaceholder.setUserName(SEARCHING_USER_KEY);
searchingUserPlaceholder.setEmail("");
}
return searchingUserPlaceholder;
}
// in java/org/tigris/scarab/util/word/IssueSearch.java
private void addMITCriteria(Criteria crit)
throws org.apache.torque.TorqueException
{
mitList.addToCriteria(crit);
}
// in java/org/tigris/scarab/util/word/IssueSearch.java
private void setupSortColumn(Criteria crit, Integer sortAttrId)
throws TorqueException
{
crit.addAlias(SORT_TABLE, AttributeValuePeer.TABLE_NAME);
joinAttributeValue(crit, SORT_TABLE, sortAttrId, Criteria.LEFT_JOIN);
crit.addSelectColumn(useAlias(SORT_TABLE, AttributeValuePeer.VALUE_ID));
String sortColumn;
Attribute att = AttributeManager.getInstance(sortAttrId);
if (att.isOptionAttribute())
{
crit.addJoin(
IssuePeer.MODULE_ID,
RModuleOptionPeer.MODULE_ID
+ ( " AND "
+ IssuePeer.TYPE_ID + " = " + RModuleOptionPeer.ISSUE_TYPE_ID +
" AND " + RModuleOptionPeer.OPTION_ID + " = " + useAlias(SORT_TABLE, AttributeValuePeer.OPTION_ID)
).replace('.', DOT_REPLACEMENT_IN_JOIN_CONDITION ),
Criteria.LEFT_JOIN
);
sortColumn = RModuleOptionPeer.PREFERRED_ORDER;
}
else
{
sortColumn = useAlias(SORT_TABLE, AttributeValuePeer.VALUE);
}
addSortColumn(crit, sortColumn);
}
// in java/org/tigris/scarab/util/word/IssueSearch.java
private void addSortCriteria(Criteria crit)
throws org.apache.torque.TorqueException
{
Integer sortAttrId = getSortAttributeId();
String sortInternal = getSortInternalAttribute();
if (sortAttrId != null)
{
setupSortColumn(crit, sortAttrId);
}
else if (sortInternal != null)
{
setupInternalSortColumn(crit, sortInternal);
}
else
{
addSortColumn(crit, IssuePeer.ISSUE_ID);
}
crit.addAscendingOrderByColumn(IssuePeer.ISSUE_ID);
}
// in java/org/tigris/scarab/util/word/IssueSearch.java
public void addAttributeValue(Attribute attribute, String value)
throws TorqueException
{
AttributeValue av = AttributeValue.getNewInstance(attribute,searchIssue);
av.setValue(value);
searchIssue.addAttributeValue(av);
}
// in java/org/tigris/scarab/util/word/IssueSearch.java
public AttributeValue addAttributeValue(Attribute attribute, AttributeOption option)
throws TorqueException
{
AttributeValue av = AttributeValue.getNewInstance(attribute, searchIssue);
av.setAttributeOption(option);
searchIssue.addAttributeValue(av);
return av;
}
// in java/org/tigris/scarab/util/word/IssueSearch.java
public List getAttributeValues()
throws TorqueException
{
return searchIssue.getAttributeValues();
}
// in java/org/tigris/scarab/util/word/IssueSearch.java
public List getSetAttributeValues() throws TorqueException {
return removeUnsetValues(searchIssue.getAttributeValues());
}
// in java/org/tigris/scarab/util/Email.java
public static ScarabUser getArchiveUser()
throws TorqueException
{
if(archiveUser==null)
{
archiveUser = ScarabUserManager.getInstance();
archiveUser.setUserId(ARCHIVE_USER_ID);
}
return archiveUser;
}