-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SA-58 construct new IPortletScheduleVisitor interface
New interface for defining the ScheduleVisitor within the portlet
- Loading branch information
Showing
6 changed files
with
315 additions
and
23 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...d-assist-portlet/src/main/java/org/jasig/schedassist/portlet/IPortletScheduleVisitor.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,47 @@ | ||
/** | ||
* 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.schedassist.portlet; | ||
|
||
import org.jasig.schedassist.model.IScheduleVisitor; | ||
|
||
/** | ||
* Simple interface for representing a schedule visitor in the portlet, | ||
* where the full {@link IScheduleVisitor} is not needed/constructable. | ||
* | ||
* @author Nicholas Blair | ||
* @version $Id: IPortletScheduleVisitor.java $ | ||
*/ | ||
public interface IPortletScheduleVisitor { | ||
|
||
/** | ||
* Return a String that uniquely idenfies this visitor in the | ||
* remote calendar service. | ||
* This could be a username or an email address. | ||
* | ||
* @return a string that uniquely identifies this visitor. | ||
*/ | ||
String getAccountId(); | ||
|
||
/** | ||
* | ||
* @return true if this account is eligible for the remote calendar service | ||
*/ | ||
boolean isEligible(); | ||
} |
39 changes: 39 additions & 0 deletions
39
...t-portlet/src/main/java/org/jasig/schedassist/portlet/IPortletScheduleVisitorFactory.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,39 @@ | ||
/** | ||
* 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.schedassist.portlet; | ||
|
||
import javax.portlet.PortletRequest; | ||
|
||
/** | ||
* Factory for {@link IPortletScheduleVisitor}s. | ||
* | ||
* @author Nicholas Blair | ||
* @version $Id: IPortletScheduleVisitorFactory.java $ | ||
*/ | ||
public interface IPortletScheduleVisitorFactory { | ||
|
||
/** | ||
* Implementations should never return null. | ||
* | ||
* @param portletRequest | ||
* @return the {@link IPortletScheduleVisitor} associated with the request | ||
*/ | ||
IPortletScheduleVisitor getPortletScheduleVisitor(PortletRequest portletRequest); | ||
} |
79 changes: 79 additions & 0 deletions
79
...java/org/jasig/schedassist/portlet/visitors/DefaultPortletScheduleVisitorFactoryImpl.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,79 @@ | ||
/** | ||
* 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.schedassist.portlet.visitors; | ||
|
||
import javax.portlet.PortletRequest; | ||
|
||
import org.jasig.schedassist.portlet.IPortletScheduleVisitor; | ||
import org.jasig.schedassist.portlet.IPortletScheduleVisitorFactory; | ||
import org.jasig.schedassist.portlet.PortletSchedulingAssistantService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
|
||
/** | ||
* Default {@link IPortletScheduleVisitorFactory} implementation. | ||
* The AccountId returned on the {@link IPortletScheduleVisitor} is sourced | ||
* from {@link PortletRequest#getRemoteUser()}. | ||
* | ||
* @author Nicholas Blair | ||
*/ | ||
public class DefaultPortletScheduleVisitorFactoryImpl implements | ||
IPortletScheduleVisitorFactory { | ||
|
||
private PortletSchedulingAssistantService schedulingAssistantService; | ||
|
||
/** | ||
* @param schedulingAssistantService the schedulingAssistantService to set | ||
*/ | ||
@Autowired | ||
public void setSchedulingAssistantService( | ||
@Qualifier("portlet") PortletSchedulingAssistantService schedulingAssistantService) { | ||
this.schedulingAssistantService = schedulingAssistantService; | ||
} | ||
/** | ||
* @return the schedulingAssistantService | ||
*/ | ||
public PortletSchedulingAssistantService getSchedulingAssistantService() { | ||
return schedulingAssistantService; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.jasig.schedassist.portlet.IPortletScheduleVisitorFactory#getPortletScheduleVisitor(javax.portlet.PortletRequest) | ||
*/ | ||
@Override | ||
public IPortletScheduleVisitor getPortletScheduleVisitor( | ||
PortletRequest portletRequest) { | ||
final String remoteUser = portletRequest.getRemoteUser(); | ||
return doConstructVisitor(remoteUser); | ||
} | ||
|
||
/** | ||
* Invoke {@link PortletSchedulingAssistantService#isEligible(String)} and construct | ||
* a {@link DefaultPortletScheduleVisitorImpl} with the accountId and eligible result. | ||
* | ||
* @param accountId | ||
* @return the {@link IPortletScheduleVisitor}. | ||
*/ | ||
protected IPortletScheduleVisitor doConstructVisitor(String accountId) { | ||
boolean eligible = schedulingAssistantService.isEligible(accountId); | ||
DefaultPortletScheduleVisitorImpl visitor = new DefaultPortletScheduleVisitorImpl(accountId, eligible); | ||
return visitor; | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
...c/main/java/org/jasig/schedassist/portlet/visitors/DefaultPortletScheduleVisitorImpl.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,116 @@ | ||
/** | ||
* 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.schedassist.portlet.visitors; | ||
|
||
import org.jasig.schedassist.portlet.IPortletScheduleVisitor; | ||
|
||
/** | ||
* Default implementation of {@link IScheduleVisitor}. | ||
* | ||
* @author Nicholas Blair | ||
*/ | ||
public class DefaultPortletScheduleVisitorImpl implements IPortletScheduleVisitor { | ||
|
||
private final String username; | ||
private boolean eligible = false; | ||
/** | ||
* @param username | ||
*/ | ||
public DefaultPortletScheduleVisitorImpl(String username) { | ||
this.username = username; | ||
} | ||
|
||
/** | ||
* | ||
* @param username | ||
* @param eligible | ||
*/ | ||
public DefaultPortletScheduleVisitorImpl(String username, boolean eligible) { | ||
this(username); | ||
this.eligible = eligible; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.jasig.schedassist.portlet.IPortletScheduleVisitor#getAccountId() | ||
*/ | ||
@Override | ||
public String getAccountId() { | ||
return username; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.jasig.schedassist.portlet.IPortletScheduleVisitor#isEligible() | ||
*/ | ||
@Override | ||
public boolean isEligible() { | ||
return eligible; | ||
} | ||
/** | ||
* @param eligible the eligible to set | ||
*/ | ||
public void setEligible(boolean eligible) { | ||
this.eligible = eligible; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see java.lang.Object#hashCode() | ||
*/ | ||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + (eligible ? 1231 : 1237); | ||
result = prime * result | ||
+ ((username == null) ? 0 : username.hashCode()); | ||
return result; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see java.lang.Object#equals(java.lang.Object) | ||
*/ | ||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
DefaultPortletScheduleVisitorImpl other = (DefaultPortletScheduleVisitorImpl) obj; | ||
if (eligible != other.eligible) | ||
return false; | ||
if (username == null) { | ||
if (other.username != null) | ||
return false; | ||
} else if (!username.equals(other.username)) | ||
return false; | ||
return true; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see java.lang.Object#toString() | ||
*/ | ||
@Override | ||
public String toString() { | ||
return "DefaultPortletScheduleVisitorImpl [username=" + username | ||
+ ", eligible=" + eligible + "]"; | ||
} | ||
|
||
} |
Oops, something went wrong.