ome.services.sharing
Class ShareBean

java.lang.Object
  extended by ome.logic.AbstractLevel2Service
      extended by ome.services.sharing.ShareBean
All Implemented Interfaces:
IShare, LocalShare, ServiceInterface, SelfConfigurableService

@Transactional(readOnly=true)
public class ShareBean
extends AbstractLevel2Service
implements LocalShare

Note: SessionManager should not be used to obtain the Share data since it may not be completely in sync. i.e. Don't use SM.find()

Since:
3.0-Beta4
Author:
Josh Moore, josh at glencoesoftware.com
See Also:
IShare

Field Summary
protected  LocalAdmin admin
           
protected  Executor executor
           
static org.apache.commons.logging.Log log
           
static String NS_COMMENT
           
static String NS_ENABLED
           
protected  SessionManager sessionManager
           
protected  ShareStore store
           
 
Fields inherited from class ome.logic.AbstractLevel2Service
iQuery, iUpdate, metadata, queryFactory, sec
 
Constructor Summary
ShareBean(LocalAdmin admin, SessionManager mgr, ShareStore store, Executor executor)
           
 
Method Summary
protected  void _addGraph(ShareData data, ome.services.sharing.ShareBean.Graph g)
           
 void activate(long shareId)
          Turns on the access control lists attached to the given share for the current session.
 ome.model.annotations.CommentAnnotation addComment(long shareId, String commentText)
          Creates comment for share.
 void addGuest(long shareId, String emailAddress)
          Add guest email address to the share.
 void addGuests(long shareId, String... emailAddresses)
          Adds guest email addresses to the share.
<T extends ome.model.IObject>
void
addObject(long shareId, T object)
          Adds new item to share.
<T extends ome.model.IObject>
void
addObjects(long shareId, T... objects)
          Adds new items to share.
 ome.model.annotations.CommentAnnotation addReply(long shareId, String comment, ome.model.annotations.CommentAnnotation replyTo)
          Creates comment which replies to an existing comment.
 void addUser(long shareId, ome.model.meta.Experimenter exp)
          Adds experimenter to share
 void addUsers(long shareId, ome.model.meta.Experimenter... exps)
          Adds experimenters to share
protected  void adminFlush()
           
protected  void applyIfShareAccessible(QueryBuilder qb)
          If the current user is not an admin, then this methods adds a subclause to the HQL: AND ( share.owner.id = :userId or user.id = :userId ) QueryBuilder.where() should already have been called.
 void closeShare(long shareId)
          Closes share.
<T extends ome.model.IObject>
long
createShare(String description, Timestamp expiration, List<T> items, List<ome.model.meta.Experimenter> exps, List<String> guests, boolean enabled)
          Creates share with all related: items, members, and guests.
 void deactivate()
          Turns off the access control lists with the current share.
 void deleteComment(ome.model.annotations.Annotation comment)
          Deletes comment from the database.
static long expirationAsLong(long started, Timestamp expiration)
          Convert a expiration into a long which can be set on Session.setTimeToLive(Long).
 Map<String,ome.model.meta.Experimenter> getActiveConnections(long shareId)
          Gets actual active connections to share.
 Set<String> getAllGuests(long shareId)
          Get the email addresses for all share guests.
 Set<ome.model.meta.Experimenter> getAllMembers(long shareId)
          Get all users who are a member of the share.
 Set<String> getAllUsers(long shareId)
          Get a single set containing the login names of the Experimenters as well email addresses for guests.
 Map<Long,Long> getCommentCount(Set<Long> ids)
          Returns a map from share id to comment count.
 List<ome.model.annotations.Annotation> getComments(long shareId)
          Looks up all comments which belong to the share.
<T extends ome.model.IObject>
Map<Class<T>,List<Long>>
getContentMap(long shareId)
          Returns the contents of the share keyed by type.
<T extends ome.model.IObject>
List<T>
getContents(long shareId)
          Looks up all items belong to the share.
 int getContentSize(long shareId)
          Returns the number of items in the share.
<T extends ome.model.IObject>
List<T>
getContentSubList(long shareId, int start, int finish)
          Returns a range of items from the share.
 List<ome.model.meta.Event> getEvents(long shareId, ome.model.meta.Experimenter experimenter, Timestamp from, Timestamp to)
          Gets events for share per experimenter for period of time.
 Map<Long,Long> getMemberCount(Set<Long> shareIds)
          Returns a map from share id to the count of total members (including the owner).
 Set<ome.model.meta.Session> getMemberShares(boolean active)
          Gets all shares where current Experimenter is a member.
 Set<ome.model.meta.Session> getMemberSharesFor(ome.model.meta.Experimenter user, boolean active)
          Gets all shares where given Experimenter is a member.
 Set<ome.model.meta.Session> getOwnShares(boolean active)
          Gets all owned shares for the current Experimenter
 Map<String,ome.model.meta.Experimenter> getPastConnections(long shareId)
          Gets previous connections to share.
 Class<? extends ServiceInterface> getServiceInterface()
           
 ome.model.meta.Share getShare(long sessionId)
          Gets a share as a Session with all related: comments, members, fully loaded.
protected  ShareData getShareIfAccessible(long shareId)
          Loads share and checks it's owner and member data against the current context (owner/member/admin).
 Set<ome.model.meta.Session> getSharesOwnedBy(ome.model.meta.Experimenter user, boolean active)
          Gets all shares owned by the given Experimenter.
protected  String idToUuid(long shareId)
           
 void invalidateConnection(long shareId, ome.model.meta.Experimenter exp)
          Makes the connection invalid for share for specifiec user.
protected
<T extends ome.model.IObject>
List<T>
list(List<Obj> objectList)
           
protected  List<ome.model.meta.Experimenter> loadMembers(ShareData data)
           
protected
<T extends ome.model.IObject>
Map<Class<T>,List<Long>>
map(Map<String,List<Long>> map)
           
 void removeGuest(long shareId, String emailAddress)
          Removes guest email address from share.
 void removeGuests(long shareId, String... emailAddresses)
          Removes guest email addresses from the share.
<T extends ome.model.IObject>
void
removeObject(long shareId, T object)
          Removes existing item from the share.
<T extends ome.model.IObject>
void
removeObjects(long shareId, T... objects)
          Remove existing items from the share.
 void removeUser(long shareId, ome.model.meta.Experimenter exp)
          Removes experimenter from share
 void removeUsers(long shareId, List<ome.model.meta.Experimenter> exps)
          Removes experimenters from share
 void resetReadFilter(org.hibernate.Session s)
           
 void setActive(long shareId, boolean active)
           
 void setDescription(long shareId, String description)
           
 void setExpiration(long shareId, Timestamp expiration)
           
 Long setShareId(Long shareId)
          Not in the public interface (since it allows setting to -1 which makes everything readable, but used internally similar to a LocalShare interface.
protected  Set<ome.model.meta.Session> sharesToSessions(List<ShareData> datas)
           
protected  ome.model.meta.Share shareToSession(ShareData data)
           
protected  void storeShareData(long shareId, ShareData data)
           
protected  void throwOnNullData(long shareId, ShareData data)
           
 
Methods inherited from class ome.logic.AbstractLevel2Service
getBeanHelper, getExtendedMetadata, getQueryFactory, getSecuritySystem, selfConfigure, setExtendedMetadata, setQueryFactory, setQueryService, setSecuritySystem, setUpdateService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final org.apache.commons.logging.Log log

NS_ENABLED

public static final String NS_ENABLED
See Also:
Constant Field Values

NS_COMMENT

public static final String NS_COMMENT
See Also:
Constant Field Values

admin

protected final LocalAdmin admin

sessionManager

protected final SessionManager sessionManager

store

protected final ShareStore store

executor

protected final Executor executor
Constructor Detail

ShareBean

public ShareBean(LocalAdmin admin,
                 SessionManager mgr,
                 ShareStore store,
                 Executor executor)
Method Detail

getServiceInterface

public final Class<? extends ServiceInterface> getServiceInterface()
Specified by:
getServiceInterface in interface SelfConfigurableService

activate

public void activate(long shareId)
Description copied from interface: IShare
Turns on the access control lists attached to the given share for the current session. Warning: this will slow down the execution of the current session for all database reads. Writing to the database will not be allowed. If share does not exist or is not accessible (non-members) or is disabled, then an ValidationException is thrown.

Specified by:
activate in interface IShare

deactivate

public void deactivate()
Description copied from interface: IShare
Turns off the access control lists with the current share.

Specified by:
deactivate in interface IShare

setShareId

public Long setShareId(Long shareId)
Not in the public interface (since it allows setting to -1 which makes everything readable, but used internally similar to a LocalShare interface.

Specified by:
setShareId in interface LocalShare
See Also:
ticket:2219

resetReadFilter

public void resetReadFilter(org.hibernate.Session s)
Specified by:
resetReadFilter in interface LocalShare
See Also:
ticket:2219

getMemberCount

public Map<Long,Long> getMemberCount(Set<Long> shareIds)
Description copied from interface: IShare
Returns a map from share id to the count of total members (including the owner). This is represented by ShareMember links.

Specified by:
getMemberCount in interface IShare
Parameters:
shareIds - Not null.
Returns:
Map with all ids present.

getOwnShares

public Set<ome.model.meta.Session> getOwnShares(boolean active)
Description copied from interface: IShare
Gets all owned shares for the current Experimenter

Specified by:
getOwnShares in interface IShare
Parameters:
active - if true, then only shares which can be used for login will be returned. All "draft" shares (see IShare.createShare(String, Timestamp, List, List, List, boolean) and closed shares will be filtered.
Returns:
set of shares. Never null. May be empty.

getMemberShares

public Set<ome.model.meta.Session> getMemberShares(boolean active)
Description copied from interface: IShare
Gets all shares where current Experimenter is a member.

Specified by:
getMemberShares in interface IShare
Parameters:
active - if true, then only shares which can be used for login will be returned. All "draft" shares (see IShare.createShare(String, Timestamp, List, List, List, boolean) and closed shares will be filtered.
Returns:
set of shares. Never null. May be empty.

getSharesOwnedBy

public Set<ome.model.meta.Session> getSharesOwnedBy(ome.model.meta.Experimenter user,
                                                    boolean active)
Description copied from interface: IShare
Gets all shares owned by the given Experimenter.

Specified by:
getSharesOwnedBy in interface IShare
active - if true, then only shares which can be used for login will be returned. All "draft" shares (see IShare.createShare(String, Timestamp, List, List, List, boolean) and closed shares will be filtered.
Returns:
set of shares. Never null. May be empty.

getMemberSharesFor

public Set<ome.model.meta.Session> getMemberSharesFor(ome.model.meta.Experimenter user,
                                                      boolean active)
Description copied from interface: IShare
Gets all shares where given Experimenter is a member.

Specified by:
getMemberSharesFor in interface IShare
active - if true, then only shares which can be used for login will be returned. All "draft" shares (see IShare.createShare(String, Timestamp, List, List, List, boolean) and closed shares will be filtered.
Returns:
set of shares. Never null. May be empty.

getShare

public ome.model.meta.Share getShare(long sessionId)
Description copied from interface: IShare
Gets a share as a Session with all related: comments, members, fully loaded. Unlike the other methods on this interface, if the sessionId is unknown, does not throw a ValidationException.

Specified by:
getShare in interface IShare
Returns:
a Session with id and Details set or null. The owner in the Details object is the true owner, and the group in the Details has all member users linked. Annotation instances of the share are linked to the Session. Missing is a list of share guests.

getContents

public <T extends ome.model.IObject> List<T> getContents(long shareId)
Description copied from interface: IShare
Looks up all items belong to the share.

Specified by:
getContents in interface IShare
Returns:
list of objects. Not null. Probably not empty.

getContentSubList

public <T extends ome.model.IObject> List<T> getContentSubList(long shareId,
                                                               int start,
                                                               int finish)
Description copied from interface: IShare
Returns a range of items from the share.

Specified by:
getContentSubList in interface IShare
See Also:
IShare.getContents(long)

getContentMap

public <T extends ome.model.IObject> Map<Class<T>,List<Long>> getContentMap(long shareId)
Description copied from interface: IShare
Returns the contents of the share keyed by type.

Specified by:
getContentMap in interface IShare

getContentSize

public int getContentSize(long shareId)
Description copied from interface: IShare
Returns the number of items in the share.

Specified by:
getContentSize in interface IShare

createShare

@Transactional(readOnly=false)
public <T extends ome.model.IObject> long createShare(String description,
                                                                    Timestamp expiration,
                                                                    List<T> items,
                                                                    List<ome.model.meta.Experimenter> exps,
                                                                    List<String> guests,
                                                                    boolean enabled)
Description copied from interface: IShare
Creates share with all related: items, members, and guests.

Specified by:
createShare in interface IShare
enabled - if true, then the share is immediately available for use. If false, then the share is in draft state. All methods on this interface will work for shares except IShare.activate(long). Similarly, the share password cannot be used by guests to login.

setDescription

@Transactional(readOnly=false)
public void setDescription(long shareId,
                                         String description)
Specified by:
setDescription in interface IShare

setExpiration

@Transactional(readOnly=false)
public void setExpiration(long shareId,
                                        Timestamp expiration)
Specified by:
setExpiration in interface IShare

setActive

@Transactional(readOnly=false)
public void setActive(long shareId,
                                    boolean active)
Specified by:
setActive in interface IShare

closeShare

@Transactional(readOnly=false)
public void closeShare(long shareId)
Description copied from interface: IShare
Closes share. No further logins will be possible and all getters (e.g. #getMemberShares(boolean), {@link #getAllShares(boolean), ...} will filter these results if "onlyActive" is true.

Specified by:
closeShare in interface IShare

addObjects

@Transactional(readOnly=false)
public <T extends ome.model.IObject> void addObjects(long shareId,
                                                                   T... objects)
Description copied from interface: IShare
Adds new items to share. Conceptually calls IShare.addObjects(long, IObject...) for every argument passed, but the graphs will be merged.

Specified by:
addObjects in interface IShare

addObject

@Transactional(readOnly=false)
public <T extends ome.model.IObject> void addObject(long shareId,
                                                                  T object)
Description copied from interface: IShare
Adds new item to share. The entire object graph with the exception of all Details will be loaded into the share. If you would like to load a single object, then pass an unloaded reference.

Specified by:
addObject in interface IShare

removeObjects

@Transactional(readOnly=false)
public <T extends ome.model.IObject> void removeObjects(long shareId,
                                                                      T... objects)
Description copied from interface: IShare
Remove existing items from the share.

Specified by:
removeObjects in interface IShare

removeObject

@Transactional(readOnly=false)
public <T extends ome.model.IObject> void removeObject(long shareId,
                                                                     T object)
Description copied from interface: IShare
Removes existing item from the share.

Specified by:
removeObject in interface IShare

getCommentCount

public Map<Long,Long> getCommentCount(Set<Long> ids)
Description copied from interface: IShare
Returns a map from share id to comment count.

Specified by:
getCommentCount in interface IShare
Parameters:
ids - Not null.
Returns:
Map with all ids present and 0 if no count exists.

getComments

public List<ome.model.annotations.Annotation> getComments(long shareId)
Description copied from interface: IShare
Looks up all comments which belong to the share.

Specified by:
getComments in interface IShare
Returns:
list of Annotation

addComment

@Transactional(readOnly=false)
public ome.model.annotations.CommentAnnotation addComment(long shareId,
                                                                        String commentText)
Description copied from interface: IShare
Creates comment for share.

Specified by:
addComment in interface IShare

addReply

@Transactional(readOnly=false)
public ome.model.annotations.CommentAnnotation addReply(long shareId,
                                                                      String comment,
                                                                      ome.model.annotations.CommentAnnotation replyTo)
Description copied from interface: IShare
Creates comment which replies to an existing comment.

Specified by:
addReply in interface IShare
Returns:

deleteComment

@Transactional(readOnly=false)
public void deleteComment(ome.model.annotations.Annotation comment)
Description copied from interface: IShare
Deletes comment from the database.

Specified by:
deleteComment in interface IShare

getAllMembers

public Set<ome.model.meta.Experimenter> getAllMembers(long shareId)
Description copied from interface: IShare
Get all users who are a member of the share.

Specified by:
getAllMembers in interface IShare

getAllGuests

public Set<String> getAllGuests(long shareId)
Description copied from interface: IShare
Get the email addresses for all share guests.

Specified by:
getAllGuests in interface IShare

getAllUsers

public Set<String> getAllUsers(long shareId)
                        throws ome.conditions.ValidationException
Description copied from interface: IShare
Get a single set containing the login names of the Experimenters as well email addresses for guests.

Specified by:
getAllUsers in interface IShare
Returns:
Throws:
ome.conditions.ValidationException - if there is a conflict between email addresses and user names.

addUsers

@Transactional(readOnly=false)
public void addUsers(long shareId,
                                   ome.model.meta.Experimenter... exps)
Description copied from interface: IShare
Adds experimenters to share

Specified by:
addUsers in interface IShare

addGuests

@Transactional(readOnly=false)
public void addGuests(long shareId,
                                    String... emailAddresses)
Description copied from interface: IShare
Adds guest email addresses to the share.

Specified by:
addGuests in interface IShare

removeUsers

@Transactional(readOnly=false)
public void removeUsers(long shareId,
                                      List<ome.model.meta.Experimenter> exps)
Description copied from interface: IShare
Removes experimenters from share

Specified by:
removeUsers in interface IShare

removeGuests

@Transactional(readOnly=false)
public void removeGuests(long shareId,
                                       String... emailAddresses)
Description copied from interface: IShare
Removes guest email addresses from the share.

Specified by:
removeGuests in interface IShare

addUser

@Transactional(readOnly=false)
public void addUser(long shareId,
                                  ome.model.meta.Experimenter exp)
Description copied from interface: IShare
Adds experimenter to share

Specified by:
addUser in interface IShare

addGuest

@Transactional(readOnly=false)
public void addGuest(long shareId,
                                   String emailAddress)
Description copied from interface: IShare
Add guest email address to the share.

Specified by:
addGuest in interface IShare

removeUser

@Transactional(readOnly=false)
public void removeUser(long shareId,
                                     ome.model.meta.Experimenter exp)
Description copied from interface: IShare
Removes experimenter from share

Specified by:
removeUser in interface IShare

removeGuest

@Transactional(readOnly=false)
public void removeGuest(long shareId,
                                      String emailAddress)
Description copied from interface: IShare
Removes guest email address from share.

Specified by:
removeGuest in interface IShare

getActiveConnections

public Map<String,ome.model.meta.Experimenter> getActiveConnections(long shareId)
Description copied from interface: IShare
Gets actual active connections to share.

Specified by:
getActiveConnections in interface IShare
Returns:
map of experimenter and IP address

getEvents

public List<ome.model.meta.Event> getEvents(long shareId,
                                            ome.model.meta.Experimenter experimenter,
                                            Timestamp from,
                                            Timestamp to)
Description copied from interface: IShare
Gets events for share per experimenter for period of time.

Specified by:
getEvents in interface IShare
from - - time
to - - time
Returns:
List of events

getPastConnections

public Map<String,ome.model.meta.Experimenter> getPastConnections(long shareId)
Description copied from interface: IShare
Gets previous connections to share.

Specified by:
getPastConnections in interface IShare
Returns:
map of experimenter and IP address

invalidateConnection

public void invalidateConnection(long shareId,
                                 ome.model.meta.Experimenter exp)
Description copied from interface: IShare
Makes the connection invalid for share for specifiec user.

Specified by:
invalidateConnection in interface IShare
exp - - connection

idToUuid

protected String idToUuid(long shareId)

loadMembers

protected List<ome.model.meta.Experimenter> loadMembers(ShareData data)

expirationAsLong

public static long expirationAsLong(long started,
                                    Timestamp expiration)
Convert a expiration into a long which can be set on Session.setTimeToLive(Long).

Returns:
the time in milliseconds that this session can exist.

sharesToSessions

protected Set<ome.model.meta.Session> sharesToSessions(List<ShareData> datas)

shareToSession

protected ome.model.meta.Share shareToSession(ShareData data)

map

protected <T extends ome.model.IObject> Map<Class<T>,List<Long>> map(Map<String,List<Long>> map)

list

protected <T extends ome.model.IObject> List<T> list(List<Obj> objectList)

adminFlush

protected void adminFlush()

throwOnNullData

protected void throwOnNullData(long shareId,
                               ShareData data)

applyIfShareAccessible

protected void applyIfShareAccessible(QueryBuilder qb)
If the current user is not an admin, then this methods adds a subclause to the HQL: AND ( share.owner.id = :userId or user.id = :userId ) QueryBuilder.where() should already have been called.


getShareIfAccessible

protected ShareData getShareIfAccessible(long shareId)
Loads share and checks it's owner and member data against the current context (owner/member/admin). This method must be kept in sync with applyIfShareAccessible(QueryBuilder) which does the same check at the database rather than binary data level.


_addGraph

protected void _addGraph(ShareData data,
                         ome.services.sharing.ShareBean.Graph g)

storeShareData

protected void storeShareData(long shareId,
                              ShareData data)


OmeroJava Api

Version: 4.3.3-00d1137e-b2894

Copyright © 2009 The University of Dundee. All Rights Reserved.