Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SSP-256 Additions for Completed state on click
- Loading branch information
1 parent
448fd31
commit 07b26c1
Showing
21 changed files
with
614 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...t-webapp/src/main/java/org/jasig/portlet/notice/action/stateChange/StateChangeAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Licensed to Jasig under one or more contributor license | ||
* agreements. See the NOTICE file distributed with this work | ||
* for additional information regarding copyright ownership. | ||
* Jasig licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a | ||
* copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.jasig.portlet.notice.action.stateChange; | ||
|
||
import java.io.IOException; | ||
import java.util.Date; | ||
import java.util.Map; | ||
import javax.portlet.ActionRequest; | ||
import javax.portlet.ActionResponse; | ||
import javax.portlet.PortletPreferences; | ||
import org.jasig.portlet.notice.NotificationAction; | ||
import org.jasig.portlet.notice.NotificationEntry; | ||
import org.jasig.portlet.notice.NotificationState; | ||
import org.jasig.portlet.notice.service.jpa.JpaNotificationService; | ||
import org.jasig.portlet.notice.util.SpringContext; | ||
|
||
/** | ||
* | ||
* @author mglazier | ||
*/ | ||
public class StateChangeAction extends NotificationAction { | ||
|
||
@Override | ||
public void invoke(final ActionRequest req, final ActionResponse res) throws IOException { | ||
JpaNotificationService jpaService = (JpaNotificationService) SpringContext.getApplicationContext().getBean("jpaNotificationService"); | ||
|
||
final PortletPreferences prefs = req.getPreferences(); | ||
final String clickedState = prefs.getValue("applyStateWhenClicked", "COMPLETED"); | ||
NotificationState notificationState = NotificationState.valueOf(clickedState); | ||
|
||
boolean completedStateFound = false; | ||
|
||
final NotificationEntry entry = getTarget(); | ||
Map<NotificationState,Date> stateMap = entry.getStates(); | ||
if (stateMap != null && stateMap.size() > 0) { | ||
for ( NotificationState state: stateMap.keySet()) { | ||
if (state == notificationState) { | ||
completedStateFound = true; | ||
} | ||
} | ||
} | ||
|
||
if (!completedStateFound) { | ||
jpaService.updateEntryState(req, entry.getId(), notificationState); | ||
} | ||
|
||
res.sendRedirect(entry.getUrl()); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
.../org/jasig/portlet/notice/action/stateChange/StateChangeNotificationServiceDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* Licensed to Jasig under one or more contributor license | ||
* agreements. See the NOTICE file distributed with this work | ||
* for additional information regarding copyright ownership. | ||
* Jasig licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a | ||
* copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.jasig.portlet.notice.action.stateChange; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.portlet.ActionRequest; | ||
import javax.portlet.ActionResponse; | ||
import javax.portlet.EventRequest; | ||
import javax.portlet.EventResponse; | ||
import javax.portlet.PortletPreferences; | ||
import javax.portlet.PortletRequest; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.jasig.portlet.notice.INotificationService; | ||
import org.jasig.portlet.notice.NotificationAction; | ||
import org.jasig.portlet.notice.NotificationCategory; | ||
import org.jasig.portlet.notice.NotificationEntry; | ||
import org.jasig.portlet.notice.NotificationResponse; | ||
|
||
/** | ||
* | ||
* @author mglazier | ||
*/ | ||
public class StateChangeNotificationServiceDecorator implements INotificationService { | ||
|
||
public static final String STATE_CHANGE_ENABLED_PREFERENCE = "autoApplyStateWhenClicked"; | ||
public static final String DEFAULT_STATE_CHANGE_BEHAVIOR = "false"; // The feature is disabled by default | ||
|
||
// Instance members | ||
private INotificationService enclosedNotificationService; | ||
private final Log log = LogFactory.getLog(getClass()); | ||
|
||
public void setEnclosedNotificationService(INotificationService enclosedNotificationService) { | ||
this.enclosedNotificationService = enclosedNotificationService; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return enclosedNotificationService.getName(); | ||
} | ||
|
||
@Override | ||
public void invoke(ActionRequest req, ActionResponse res, boolean refresh) { | ||
enclosedNotificationService.invoke(req, res, refresh); | ||
} | ||
|
||
@Override | ||
public void collect(EventRequest req, EventResponse res) { | ||
enclosedNotificationService.collect(req, res); | ||
} | ||
|
||
@Override | ||
public NotificationResponse fetch(PortletRequest req) { | ||
// Just pass through the enclosed collection if this feature is disabled | ||
if (!stateChangeEnabled(req)) { | ||
return enclosedNotificationService.fetch(req); | ||
} | ||
|
||
// Build a fresh NotificationResponse based on a deep-copy of the one we enclose | ||
final NotificationResponse sourceResponse = enclosedNotificationService.fetch(req); | ||
NotificationResponse rslt = sourceResponse.cloneIfNotCloned(); | ||
|
||
for (NotificationCategory category : rslt.getCategories()) { | ||
for (NotificationEntry entry : category.getEntries()) { | ||
final List<NotificationAction> currentList = entry.getAvailableActions(); | ||
|
||
if (StringUtils.isNotBlank(entry.getId())) { | ||
if (StringUtils.isNotBlank(entry.getId())) { | ||
final List<NotificationAction> replacementList = new ArrayList<>(currentList); | ||
replacementList.add( new StateChangeAction()); | ||
entry.setAvailableActions( replacementList); | ||
} | ||
} | ||
} | ||
} | ||
return rslt; | ||
} | ||
|
||
@Override | ||
public boolean isValid(PortletRequest req, NotificationResponse previousResponse) { | ||
return enclosedNotificationService.isValid(req, previousResponse); | ||
} | ||
|
||
private boolean stateChangeEnabled(PortletRequest request) { | ||
PortletPreferences prefs = request.getPreferences(); | ||
return Boolean.valueOf(prefs.getValue(STATE_CHANGE_ENABLED_PREFERENCE, DEFAULT_STATE_CHANGE_BEHAVIOR)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
notification-portlet-webapp/src/main/java/org/jasig/portlet/notice/util/SpringContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Licensed to Jasig under one or more contributor license | ||
* agreements. See the NOTICE file distributed with this work | ||
* for additional information regarding copyright ownership. | ||
* Jasig licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a | ||
* copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.jasig.portlet.notice.util; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
|
||
/** | ||
* | ||
* @author mglazier | ||
*/ | ||
public class SpringContext implements ApplicationContextAware { | ||
|
||
private static ApplicationContext context; | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext context) throws BeansException { | ||
SpringContext.context = context; | ||
} | ||
|
||
public static ApplicationContext getApplicationContext() { | ||
return context; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.