use of fi.otavanopisto.muikku.schooldata.entity.Workspace in project muikku by otavanopisto.
the class PyramusWorkspaceSchoolDataBridge method listWorkspacesByCourseIdentifier.
@Override
public List<Workspace> listWorkspacesByCourseIdentifier(String courseIdentifierIdentifier) {
if (courseIdentifierIdentifier.indexOf("/") == -1)
throw new SchoolDataBridgeInternalException("Invalid CourseIdentifierId");
String subjectId = courseIdentifierIdentifier.substring(0, courseIdentifierIdentifier.indexOf("/"));
String courseNumber = courseIdentifierIdentifier.substring(courseIdentifierIdentifier.indexOf("/") + 1);
Course[] courses = pyramusClient.get("/common/subjects/" + subjectId + "/courses", fi.otavanopisto.pyramus.rest.model.Course[].class);
List<Workspace> result = new ArrayList<Workspace>();
for (Course course : courses) {
String courseNumber2 = course.getCourseNumber() != null ? course.getCourseNumber().toString() : "null";
if (courseNumber.equals(courseNumber2))
result.add(createWorkspaceEntity(course));
}
return result;
}
use of fi.otavanopisto.muikku.schooldata.entity.Workspace in project muikku by otavanopisto.
the class WorkspaceRESTService method getFeeInfo.
@GET
@Path("/workspaces/{ID}/feeInfo")
@RESTPermit(value = MuikkuPermissions.VIEW_WORKSPACE_FEE, requireLoggedIn = true)
public Response getFeeInfo(@PathParam("ID") Long workspaceEntityId) {
SchoolDataIdentifier userIdentifier = sessionController.getLoggedUser();
if (userIdentifier == null) {
return Response.status(Status.UNAUTHORIZED).build();
}
User user = userController.findUserByIdentifier(userIdentifier);
if (user == null) {
return Response.status(Status.FORBIDDEN).build();
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceEntityId);
if (workspaceEntity == null) {
return Response.status(Status.NOT_FOUND).build();
}
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
if (workspace == null) {
return Response.status(Status.NOT_FOUND).build();
}
// #3069: If the user has evaluation fees and a school set, all workspaces have an
// evaluation fee. Otherwise it depends on the applicability of the workspace itself.
boolean evaluationFees = user.hasEvaluationFees() && (StringUtils.isNotEmpty(user.getSchool()) || workspace.isEvaluationFeeApplicable());
return Response.ok(new WorkspaceFeeInfo(evaluationFees)).build();
}
use of fi.otavanopisto.muikku.schooldata.entity.Workspace in project muikku by otavanopisto.
the class WorkspaceRESTService method createWorkspace.
@POST
@Path("/workspaces/")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createWorkspace(@QueryParam("sourceWorkspaceIdentifier") String sourceWorkspaceId, @QueryParam("sourceWorkspaceEntityId") Long sourceWorkspaceEntityId, fi.otavanopisto.muikku.plugins.workspace.rest.model.Workspace payload) {
SchoolDataIdentifier workspaceIdentifier = null;
if (sourceWorkspaceId != null) {
workspaceIdentifier = SchoolDataIdentifier.fromId(sourceWorkspaceId);
if (workspaceIdentifier == null) {
return Response.status(Status.BAD_REQUEST).entity(String.format("Invalid source workspace identifier %s", sourceWorkspaceId)).build();
}
}
WorkspaceEntity sourceWorkspaceEntity = null;
if (sourceWorkspaceEntityId != null) {
sourceWorkspaceEntity = workspaceEntityController.findWorkspaceEntityById(sourceWorkspaceEntityId);
if (sourceWorkspaceEntity == null) {
return Response.status(Status.BAD_REQUEST).entity(String.format("Invalid source workspace entity id %d", sourceWorkspaceEntityId)).build();
}
workspaceIdentifier = new SchoolDataIdentifier(sourceWorkspaceEntity.getIdentifier(), sourceWorkspaceEntity.getDataSource().getIdentifier());
}
if (workspaceIdentifier == null) {
return Response.status(Status.NOT_IMPLEMENTED).entity("Creating new workspaces without sourceWorkspace is not not implemented yet").build();
}
if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.COPY_WORKSPACE)) {
return Response.status(Status.FORBIDDEN).build();
}
if (StringUtils.isBlank(payload.getName())) {
return Response.status(Status.BAD_REQUEST).entity("Name is required").build();
}
Workspace workspace = workspaceController.copyWorkspace(workspaceIdentifier, payload.getName(), payload.getNameExtension(), payload.getDescription());
if (workspace == null) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(String.format("Failed to create copy of workspace %s", sourceWorkspaceId)).build();
}
WorkspaceEntity workspaceEntity = findCopiedWorkspaceEntity(workspace);
if (workspaceEntity == null) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(String.format("Failed to create local copy of workspace %s", sourceWorkspaceId)).build();
}
// #2599: Also copy workspace default license and producers
if (sourceWorkspaceEntity != null) {
workspaceEntityController.updateDefaultMaterialLicense(workspaceEntity, sourceWorkspaceEntity.getDefaultMaterialLicense());
List<WorkspaceMaterialProducer> workspaceMaterialProducers = workspaceController.listWorkspaceMaterialProducers(sourceWorkspaceEntity);
for (WorkspaceMaterialProducer workspaceMaterialProducer : workspaceMaterialProducers) {
workspaceController.createWorkspaceMaterialProducer(workspaceEntity, workspaceMaterialProducer.getName());
}
}
return Response.ok(createRestModel(workspaceEntity, workspace.getName(), workspace.getNameExtension(), workspace.getDescription(), convertWorkspaceCurriculumIds(workspace), workspace.getSubjectIdentifier())).build();
}
use of fi.otavanopisto.muikku.schooldata.entity.Workspace in project muikku by otavanopisto.
the class WorkspaceIndexer method indexWorkspace.
private void indexWorkspace(Workspace workspace, WorkspaceEntity workspaceEntity) {
try {
Map<String, Object> extra = new HashMap<>();
extra.put("published", workspaceEntity.getPublished());
extra.put("access", workspaceEntity.getAccess());
if (workspace.getSubjectIdentifier() != null) {
Subject subject = courseMetaController.findSubject(workspace.getSchoolDataSource(), workspace.getSubjectIdentifier());
extra.put("subject", subject.getName());
}
List<WorkspaceUser> staffMembers = workspaceController.listWorkspaceStaffMembers(workspaceEntity);
Set<IndexedWorkspaceUser> indexedWorkspaceStaffMembers = new HashSet<IndexedWorkspaceUser>();
for (WorkspaceUser staffMember : staffMembers) {
// TODO: more efficient name fetching
User staffMemberUser = userController.findUserByIdentifier(staffMember.getUserIdentifier());
if (staffMemberUser != null) {
indexedWorkspaceStaffMembers.add(new IndexedWorkspaceUser(staffMember.getUserIdentifier(), staffMemberUser.getFirstName(), staffMemberUser.getLastName()));
} else {
String userId = staffMember.getUserIdentifier() != null ? staffMember.getUserIdentifier().toId() : "NULL";
logger.warning(String.format("Couldn't find staffmember #%s in workspace %s", userId, workspace.getIdentifier(), workspace.getSchoolDataSource()));
}
}
extra.put("staffMembers", indexedWorkspaceStaffMembers);
indexer.index(Workspace.class.getSimpleName(), workspace, extra);
} catch (Exception e) {
logger.warning(String.format("could not index workspace #%s/%s", workspace.getIdentifier(), workspace.getSchoolDataSource()));
}
}
use of fi.otavanopisto.muikku.schooldata.entity.Workspace in project muikku by otavanopisto.
the class WorkspaceIndexBackingBean method init.
@RequestAction
public String init() {
String urlName = getWorkspaceUrlName();
if (StringUtils.isBlank(urlName)) {
return NavigationRules.NOT_FOUND;
}
WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
if (workspaceEntity == null) {
return NavigationRules.NOT_FOUND;
}
canPublish = sessionController.hasWorkspacePermission(MuikkuPermissions.PUBLISH_WORKSPACE, workspaceEntity);
workspaceEntityId = workspaceEntity.getId();
published = workspaceEntity.getPublished();
if (!published) {
if (!sessionController.hasWorkspacePermission(MuikkuPermissions.ACCESS_UNPUBLISHED_WORKSPACE, workspaceEntity)) {
return NavigationRules.NOT_FOUND;
}
}
try {
WorkspaceMaterial frontPage = workspaceMaterialController.ensureWorkspaceFrontPageExists(workspaceEntity);
contentNodes = Arrays.asList(workspaceMaterialController.createContentNode(frontPage));
} catch (WorkspaceMaterialException e) {
logger.log(Level.SEVERE, "Error loading materials", e);
return NavigationRules.INTERNAL_ERROR;
}
workspaceBackingBean.setWorkspaceUrlName(urlName);
schoolDataBridgeSessionController.startSystemSession();
try {
Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
if (workspace == null) {
logger.warning(String.format("Could not find workspace for workspaceEntity #%d", workspaceEntity.getId()));
return NavigationRules.NOT_FOUND;
}
WorkspaceType workspaceType = workspaceController.findWorkspaceType(workspace.getWorkspaceTypeId());
EducationType educationTypeObject = workspace.getEducationTypeIdentifier() == null ? null : courseMetaController.findEducationType(workspace.getEducationTypeIdentifier());
Subject subjectObject = courseMetaController.findSubject(workspace.getSchoolDataSource(), workspace.getSubjectIdentifier());
CourseLengthUnit lengthUnit = null;
if ((workspace.getLength() != null) && (workspace.getLengthUnitIdentifier() != null)) {
lengthUnit = courseMetaController.findCourseLengthUnit(workspace.getSchoolDataSource(), workspace.getLengthUnitIdentifier());
}
workspaceId = workspaceEntity.getId();
workspaceName = workspace.getName();
workspaceNameExtension = workspace.getNameExtension();
subject = subjectObject != null ? subjectObject.getName() : null;
educationType = educationTypeObject != null ? educationTypeObject.getName() : null;
if (lengthUnit != null) {
courseLength = workspace.getLength();
courseLengthSymbol = lengthUnit.getSymbol();
}
beginDate = workspace.getBeginDate() != null ? Date.from(workspace.getBeginDate().toInstant()) : null;
endDate = workspace.getEndDate() != null ? Date.from(workspace.getEndDate().toInstant()) : null;
if (workspaceType != null) {
this.workspaceType = workspaceType.getName();
}
} finally {
schoolDataBridgeSessionController.endSystemSession();
}
WorkspaceEntityFile customFrontImage = workspaceEntityFileController.findWorkspaceEntityFile(workspaceEntity, "workspace-frontpage-image-cropped");
hasCustomFrontPageImage = customFrontImage != null;
customFrontPageImageUrl = hasCustomFrontPageImage ? String.format("/rest/workspace/workspaces/%d/workspacefile/workspace-frontpage-image-cropped", workspaceEntity.getId()) : null;
materialsBaseUrl = String.format("/workspace/%s/materials", workspaceUrlName);
announcementsBaseUrl = String.format("/workspace/%s/announcements", workspaceUrlName);
workspaceVisitController.visit(workspaceEntity);
return null;
}
Aggregations