use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.
the class DefaultSchoolDataWorkspaceListener method onSchoolDataWorkspaceUserUpdatedEvent.
public void onSchoolDataWorkspaceUserUpdatedEvent(@Observes SchoolDataWorkspaceUserUpdatedEvent event) {
UserEntity userEntity = userEntityController.findUserEntityByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
if (userEntity != null) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByDataSourceAndIdentifier(event.getWorkspaceDataSource(), event.getWorkspaceIdentifier());
if (workspaceEntity != null) {
SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(event.getIdentifier(), event.getDataSource());
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
if (workspaceUserEntity != null) {
String currentUserIdentifier = workspaceUserEntity.getUserSchoolDataIdentifier().getIdentifier();
if (!StringUtils.equals(currentUserIdentifier, event.getUserIdentifier())) {
// WorkspaceUserEntity found, but it points to a new study program
UserSchoolDataIdentifier newUserIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierByDataSourceAndIdentifier(event.getUserDataSource(), event.getUserIdentifier());
if (newUserIdentifier == null) {
logger.warning(String.format("Unable to update workspace user. UserSchoolDataIdentifier for %s/%s not found", event.getUserDataSource(), event.getUserIdentifier()));
} else {
WorkspaceUserEntity existingUser = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceAndUserSchoolDataIdentifierIncludeArchived(workspaceEntity, newUserIdentifier);
if (existingUser != null) {
if (!existingUser.getArchived().equals(workspaceUserEntity.getArchived())) {
if (existingUser.getArchived()) {
workspaceUserEntityController.unarchiveWorkspaceUserEntity(existingUser);
} else {
workspaceUserEntityController.archiveWorkspaceUserEntity(existingUser);
}
}
workspaceUserEntityController.updateIdentifier(existingUser, workspaceUserEntity.getIdentifier());
// #3308: If the new study program is active, reactivate the corresponding workspace student in Muikku
if (event.getIsActive() && !existingUser.getActive()) {
workspaceUserEntityController.updateActive(existingUser, event.getIsActive());
}
workspaceUserEntityController.archiveWorkspaceUserEntity(workspaceUserEntity);
} else {
workspaceUserEntityController.updateUserSchoolDataIdentifier(workspaceUserEntity, newUserIdentifier);
// #3308: If the new study program is active, reactivate the corresponding workspace student in Muikku
if (event.getIsActive() && !workspaceUserEntity.getActive()) {
workspaceUserEntityController.updateActive(workspaceUserEntity, event.getIsActive());
}
}
}
} else {
WorkspaceRoleEntity workspaceRoleEntity = workspaceController.findWorkspaceRoleEntityByDataSourceAndIdentifier(event.getRoleDataSource(), event.getRoleIdentifier());
if (workspaceRoleEntity != null && !workspaceRoleEntity.getId().equals(workspaceUserEntity.getWorkspaceUserRole().getId())) {
workspaceUserEntityController.updateWorkspaceUserRole(workspaceUserEntity, workspaceRoleEntity);
}
}
if (!event.getIsActive() && workspaceUserEntity.getActive()) {
workspaceUserEntityController.updateActive(workspaceUserEntity, event.getIsActive());
}
}
} else {
logger.warning("could not update workspace user because workspace entity #" + event.getWorkspaceIdentifier() + '/' + event.getWorkspaceDataSource() + " could not be found");
}
} else {
logger.warning("could not update workspace user because user entity #" + event.getUserIdentifier() + '/' + event.getUserDataSource() + " could not be found");
}
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.
the class FlagController method hasFlagPermission.
public boolean hasFlagPermission(Flag flag, SchoolDataIdentifier userIdentifier) {
UserSchoolDataIdentifier owner = flag.getOwnerIdentifier();
SchoolDataIdentifier ownerIdentfier = toIdentifier(owner);
if (ownerIdentfier.equals(userIdentifier)) {
return true;
}
UserSchoolDataIdentifier userSchoolDataIdentifier = userSchoolDataIdentifierController.findUserSchoolDataIdentifierBySchoolDataIdentifier(userIdentifier);
if (userSchoolDataIdentifier == null) {
logger.severe(String.format("Could not find school data user by identifier %s", userIdentifier));
return false;
}
FlagShare flagShare = flagShareDAO.findByFlagAndUserIdentifier(flag, userSchoolDataIdentifier);
if (flagShare != null) {
return true;
}
return false;
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.
the class WorkspaceUserEntityController method listWorkspaceEntitiesByUserEntity.
public List<WorkspaceEntity> listWorkspaceEntitiesByUserEntity(UserEntity userEntity) {
SchoolDataIdentifier schoolDataIdentifier = toSchoolDataIdentifier(userEntity);
List<WorkspaceEntity> result = new ArrayList<>();
List<WorkspaceUserEntity> workspaceUserEntities = listWorkspaceUserEntitiesByUserIdentifier(schoolDataIdentifier);
for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
result.add(workspaceUserEntity.getWorkspaceEntity());
}
return result;
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.
the class WorkspaceUserEntityController method listActiveWorkspaceEntitiesByUserEntity.
public List<WorkspaceEntity> listActiveWorkspaceEntitiesByUserEntity(UserEntity userEntity) {
SchoolDataIdentifier schoolDataIdentifier = toSchoolDataIdentifier(userEntity);
List<WorkspaceEntity> result = new ArrayList<>();
List<WorkspaceUserEntity> workspaceUserEntities = listActiveWorkspaceUserEntitiesByUserIdentifier(schoolDataIdentifier);
for (WorkspaceUserEntity workspaceUserEntity : workspaceUserEntities) {
result.add(workspaceUserEntity.getWorkspaceEntity());
}
return result;
}
use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.
the class IndexEntityProcessor method process.
public Map<String, Object> process(Object entity) throws IllegalArgumentException, IllegalAccessException, IntrospectionException, InvocationTargetException, IndexIdMissingException {
if (isIndexable(entity)) {
String id = getEnitityId(entity);
if (StringUtils.isBlank(id)) {
throw new IndexIdMissingException("Indexable object is missing an id.");
}
Map<String, Object> indexObject = new HashMap<String, Object>();
indexObject.put("id", id);
for (Method indexableGetter : getIndexableGetters(entity)) {
String fieldName = StringUtils.uncapitalize(indexableGetter.getName().substring(3));
IndexField indexField = findIndexField(indexableGetter);
if (indexField != null) {
if (indexField.skip()) {
continue;
}
String name = indexField.name();
if (StringUtils.isNotBlank(name)) {
fieldName = name;
}
}
Object fieldValue = indexableGetter.invoke(entity);
if (indexField != null && indexField.toId()) {
if (fieldValue != null) {
if (fieldValue instanceof Collection) {
Collection<?> collection = (Collection<?>) fieldValue;
Set<String> ids = new HashSet<String>();
for (Object o : collection) {
if (o != null) {
if (o instanceof SchoolDataIdentifier)
ids.add(((SchoolDataIdentifier) o).toId());
else {
logger.severe(String.format("@Indexable toId for Collection must be Collection<SchoolDataIdentifier> but was Collection<%s>", o.getClass().getName()));
}
}
}
fieldValue = ids;
} else if (fieldValue instanceof SchoolDataIdentifier) {
fieldValue = ((SchoolDataIdentifier) fieldValue).toId();
} else {
logger.severe(String.format("@Indexable toId must be SchoolDataIdentifier but was %s", fieldValue.getClass().getName()));
}
}
}
indexObject.put(fieldName, fieldValue);
}
return indexObject;
}
return null;
}
Aggregations