Search in sources :

Example 1 with Workspace

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;
}
Also used : SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) ArrayList(java.util.ArrayList) Course(fi.otavanopisto.pyramus.rest.model.Course) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace)

Example 2 with Workspace

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();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) User(fi.otavanopisto.muikku.schooldata.entity.User) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceFeeInfo(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceFeeInfo) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 3 with Workspace

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();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceMaterialProducer(fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 4 with Workspace

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()));
    }
}
Also used : WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) User(fi.otavanopisto.muikku.schooldata.entity.User) HashMap(java.util.HashMap) Subject(fi.otavanopisto.muikku.schooldata.entity.Subject) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) HashSet(java.util.HashSet) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace)

Example 5 with Workspace

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;
}
Also used : WorkspaceType(fi.otavanopisto.muikku.schooldata.entity.WorkspaceType) WorkspaceEntityFile(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) EducationType(fi.otavanopisto.muikku.schooldata.entity.EducationType) CourseLengthUnit(fi.otavanopisto.muikku.schooldata.entity.CourseLengthUnit) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) Subject(fi.otavanopisto.muikku.schooldata.entity.Subject) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Aggregations

Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)24 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)20 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)13 Path (javax.ws.rs.Path)13 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)10 User (fi.otavanopisto.muikku.schooldata.entity.User)10 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)10 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)9 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)7 ArrayList (java.util.ArrayList)6 WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)5 Date (java.util.Date)5 GET (javax.ws.rs.GET)5 POST (javax.ws.rs.POST)5 PUT (javax.ws.rs.PUT)5 WorkspaceGradingScale (fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale)4 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)4 GradingScale (fi.otavanopisto.muikku.schooldata.entity.GradingScale)4 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)4 WorkspaceDetails (fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceDetails)3