}
final Experimenter exp = localAdmin.lookupExperimenter(p.getName()); exp.getGraphHolder().setToken(token, token); CurrentDetails.setOwner(exp);   List<Long> memberOfGroupsIds = exp .eachLinkedExperimenterGroup(new IdBlock()); CurrentDetails.setMemberOfGroups(memberOfGroupsIds);   List<Long> leaderOfGroupsIds = localAdmin.getLeaderOfGroupIds(exp); CurrentDetails.setLeaderOfGroups(leaderOfGroupsIds);    if (p.getGroup() == null) throw new InternalException( "Principal.group is null in EventContext. Security system failure.");  ExperimenterGroup grp = localAdmin.groupProxy(p.getGroup()); grp.getGraphHolder().setToken(token, token); CurrentDetails.setGroup(grp);    if (isSystemGroup(grp)) { CurrentDetails.setAdmin(true); }    if (p.getEventType() == null) throw new InternalException( "Principal.eventType is null in EventContext. Security system failure.");  EventType type = iTypes.getEnumeration(EventType.class, p .getEventType()); type.getGraphHolder().setToken(token, token); CurrentDetails.newEvent(type, token);  Event event = getCurrentEvent(); event.getGraphHolder().setToken(token, token); try { setCurrentEvent(iUpdate.saveAndReturnObject(event)); } catch (InvalidDataAccessApiUsageException ex) {  log.warn("Attempt to save event in SecuritySystem failed. " + "Using unsaved.", ex); setCurrentEvent(event); }  }
	public void setCurrentDetails()    {		LocalAdmin localAdmin = (LocalAdmin) sf.getAdminService();		ITypes iTypes = sf.getTypesService();		IUpdate iUpdate = sf.getUpdateService();				clearCurrentDetails();        if ( ec == null )             throw new InternalException(                    "EventContext is null in EventContext. Invalid configuration."            );                if ( ec.getPrincipal() == null )            throw new InternalException(                    "Principal is null in EventContext. Security system failure."            );                if (ec.getPrincipal().getName() == null)            throw new InternalException(                    "Principal.name is null in EventContext. Security system failure.");        final Principal p = ec.getPrincipal();                // Experimenter                final Experimenter exp = localAdmin.lookupExperimenter(p.getName());        exp.getGraphHolder().setToken(token, token);        CurrentDetails.setOwner(exp);                // Member of Groups        List<Long> memberOfGroupsIds =         	exp.eachLinkedExperimenterGroup(new IdBlock());        CurrentDetails.setMemberOfGroups(memberOfGroupsIds);                // Leader of Groups        List<Long> leaderOfGroupsIds = localAdmin.getLeaderOfGroupIds(exp);        CurrentDetails.setLeaderOfGroups(leaderOfGroupsIds);                // Active group                if (p.getGroup() == null)            throw new InternalException(            "Principal.group is null in EventContext. Security system failure.");        ExperimenterGroup grp = localAdmin.groupProxy(p.getGroup());         grp.getGraphHolder().setToken(token, token);        CurrentDetails.setGroup(grp);        // isAdmin                if (isSystemGroup(grp))        {        	CurrentDetails.setAdmin(true);        }                // Event                 if (p.getEventType() == null)            throw new InternalException(            "Principal.eventType is null in EventContext. Security system failure.");        EventType type = iTypes.getEnumeration(EventType.class,p.getEventType());        type.getGraphHolder().setToken(token, token);        CurrentDetails.newEvent(type,token);                Event event = getCurrentEvent();        event.getGraphHolder().setToken(token, token);        try         {        	setCurrentEvent(iUpdate.saveAndReturnObject(event));        } catch (InvalidDataAccessApiUsageException ex) {         	// TODO check for read-only bef. exception        	log.warn("Attempt to save event in SecuritySystem failed. " +        			"Using unsaved.",ex);        	setCurrentEvent( event );        }    }