use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.
the class WorkspaceRESTService method updateWorkspaceStudent.
@PUT
@Path("/workspaces/{WORKSPACEENTITYID}/students/{ID}")
@RESTPermit(handling = Handling.INLINE)
public Response updateWorkspaceStudent(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("ID") String workspaceStudentId, WorkspaceStudent workspaceStudent) {
// Workspace
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.BAD_REQUEST).build();
}
// Access check
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).entity("Not logged in").build();
}
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE_MEMBERS, workspaceEntity)) {
return Response.status(Status.FORBIDDEN).build();
}
// Workspace student and school data user
SchoolDataIdentifier workspaceUserIdentifier = SchoolDataIdentifier.fromId(workspaceStudentId);
if (workspaceUserIdentifier == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid workspace user id").build();
}
SchoolDataIdentifier workspaceIdentifier = new SchoolDataIdentifier(workspaceEntity.getIdentifier(), workspaceEntity.getDataSource().getIdentifier());
fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser bridgeUser = workspaceController.findWorkspaceUser(workspaceIdentifier, workspaceUserIdentifier);
if (bridgeUser == null) {
return Response.status(Status.NOT_FOUND).entity("School data user not found").build();
}
WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifier(workspaceUserIdentifier);
// Reindex user when switching between active and inactive
if (workspaceStudent.getActive() != null && !workspaceStudent.getActive().equals(workspaceUserEntity.getActive())) {
workspaceController.updateWorkspaceStudentActivity(bridgeUser, workspaceStudent.getActive());
workspaceUserEntityController.updateActive(workspaceUserEntity, workspaceStudent.getActive());
UserSchoolDataIdentifier userSchoolDataIdentifier = workspaceUserEntity.getUserSchoolDataIdentifier();
userIndexer.indexUser(userSchoolDataIdentifier.getDataSource().getIdentifier(), userSchoolDataIdentifier.getIdentifier());
}
return Response.ok(workspaceStudent).build();
}
use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.
the class UserIndexer method indexUser.
public void indexUser(UserEntity userEntity) {
schoolDataBridgeSessionController.startSystemSession();
try {
List<UserSchoolDataIdentifier> identifiers = userSchoolDataIdentifierController.listUserSchoolDataIdentifiersByUserEntity(userEntity);
for (UserSchoolDataIdentifier schoolDataIdentifier : identifiers) {
SchoolDataIdentifier identifier = new SchoolDataIdentifier(schoolDataIdentifier.getIdentifier(), schoolDataIdentifier.getDataSource().getIdentifier());
indexUser(identifier);
}
} finally {
schoolDataBridgeSessionController.endSystemSession();
}
}
use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.
the class UserSchoolDataIdentifierDAO method findByDataSourceAndIdentifierAndArchived.
public UserSchoolDataIdentifier findByDataSourceAndIdentifierAndArchived(SchoolDataSource dataSource, String identifier, Boolean archived) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<UserSchoolDataIdentifier> criteria = criteriaBuilder.createQuery(UserSchoolDataIdentifier.class);
Root<UserSchoolDataIdentifier> root = criteria.from(UserSchoolDataIdentifier.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(UserSchoolDataIdentifier_.dataSource), dataSource), criteriaBuilder.equal(root.get(UserSchoolDataIdentifier_.identifier), identifier), criteriaBuilder.equal(root.get(UserSchoolDataIdentifier_.archived), archived)));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.
the class UserSchoolDataIdentifierDAO method create.
public UserSchoolDataIdentifier create(SchoolDataSource dataSource, String identifier, UserEntity userEntity, Boolean archived) {
UserSchoolDataIdentifier userSchoolDataIdentifier = new UserSchoolDataIdentifier();
userSchoolDataIdentifier.setIdentifier(identifier);
userSchoolDataIdentifier.setDataSource(dataSource);
userSchoolDataIdentifier.setUserEntity(userEntity);
userSchoolDataIdentifier.setArchived(archived);
return persist(userSchoolDataIdentifier);
}
use of fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier in project muikku by otavanopisto.
the class UserSchoolDataIdentifierDAO method listByDataSourceAndArchived.
public List<UserSchoolDataIdentifier> listByDataSourceAndArchived(SchoolDataSource dataSource, Boolean archived) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<UserSchoolDataIdentifier> criteria = criteriaBuilder.createQuery(UserSchoolDataIdentifier.class);
Root<UserSchoolDataIdentifier> root = criteria.from(UserSchoolDataIdentifier.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(UserSchoolDataIdentifier_.dataSource), dataSource), criteriaBuilder.equal(root.get(UserSchoolDataIdentifier_.archived), archived)));
return entityManager.createQuery(criteria).getResultList();
}
Aggregations