001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.useroptions;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.Date;
022: import java.util.List;
023: import java.util.Properties;
024:
025: import edu.iu.uis.eden.EdenConstants;
026: import edu.iu.uis.eden.user.WorkflowUser;
027: import edu.iu.uis.eden.useroptions.dao.UserOptionsDAO;
028:
029: public class UserOptionsServiceImpl implements UserOptionsService {
030:
031: private UserOptionsDAO userOptionsDAO;
032:
033: private static final Properties defaultProperties = new Properties();
034:
035: static {
036: defaultProperties.setProperty(EdenConstants.EMAIL_RMNDR_KEY,
037: EdenConstants.EMAIL_RMNDR_WEEK_VAL);
038: }
039:
040: private Long getNewOptionIdForActionList() {
041: return getUserOptionsDAO().getNewOptionIdForActionList();
042: }
043:
044: public List findByUserQualified(WorkflowUser user, String likeString) {
045: if ((user == null)) {
046: return new ArrayList(0);
047: }
048: return this .getUserOptionsDAO().findByUserQualified(user,
049: likeString);
050: }
051:
052: public UserOptions findByOptionId(String optionId, WorkflowUser user) {
053: if (optionId == null || "".equals(optionId) || user == null
054: || user.getWorkflowUserId() == null) {
055: return null;
056: }
057: return this .getUserOptionsDAO().findByOptionId(optionId, user);
058: }
059:
060: public Collection findByOptionValue(String optionId,
061: String optionValue) {
062: return this .getUserOptionsDAO().findByOptionValue(optionId,
063: optionValue);
064: }
065:
066: public Collection findByWorkflowUser(WorkflowUser user) {
067: return this .getUserOptionsDAO().findByWorkflowUser(user);
068: }
069:
070: public void save(UserOptions userOptions) {
071: this .getUserOptionsDAO().save(userOptions);
072: }
073:
074: public void deleteUserOptions(UserOptions userOptions) {
075: this .getUserOptionsDAO().deleteUserOptions(userOptions);
076: }
077:
078: public void save(WorkflowUser user, String optionId,
079: String optionValue) {
080: UserOptions option = findByOptionId(optionId, user);
081: if (option == null) {
082: option = new UserOptions();
083: option.setWorkflowId(user.getWorkflowUserId()
084: .getWorkflowId());
085: }
086: option.setOptionId(optionId);
087: option.setOptionVal(optionValue);
088: getUserOptionsDAO().save(option);
089: }
090:
091: public boolean refreshActionList(WorkflowUser user) {
092: List options = findByUserQualified(user,
093: EdenConstants.RELOAD_ACTION_LIST + "%");
094: boolean refresh = !options.isEmpty();
095: if (refresh && user != null) {
096: getUserOptionsDAO().deleteByUserQualified(user,
097: EdenConstants.RELOAD_ACTION_LIST + "%");
098: }
099: return refresh;
100: }
101:
102: public void saveRefreshUserOption(WorkflowUser user) {
103: save(user, EdenConstants.RELOAD_ACTION_LIST
104: + new Date().getTime() + getNewOptionIdForActionList(),
105: "true");
106: }
107:
108: public UserOptionsDAO getUserOptionsDAO() {
109: return userOptionsDAO;
110: }
111:
112: public void setUserOptionsDAO(UserOptionsDAO optionsDAO) {
113: userOptionsDAO = optionsDAO;
114: }
115:
116: }
|