Search in sources :

Example 1 with PropertyManager

use of org.olat.properties.PropertyManager in project OpenOLAT by OpenOLAT.

the class MessageListController method doExportForumItem.

private void doExportForumItem(UserRequest ureq, MessageView messageToMove) {
    if (foCallback.mayEditMessageAsModerator()) {
        StepRunnerCallback finish = new FinishCallback();
        Translator trans = Util.createPackageTranslator(Step_1_SelectCourse.class, getLocale());
        Step start = new Step_1_SelectCourse(ureq);
        Message message = forumManager.getMessageById(messageToMove.getKey());
        String wizardTitle = trans.translate("title.wizard.movethread", new String[] { message.getTitle() });
        exportCtrl = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, wizardTitle, "o_sel_bulk_assessment_wizard");
        StepsRunContext runContext = exportCtrl.getRunContext();
        // can be threadtop message
        runContext.put(SendMailStepForm.MESSAGE_TO_MOVE, message);
        // starting thread
        runContext.put(SendMailStepForm.START_THREADTOP, message.getThreadtop() == null ? message : message.getThreadtop());
        // get start course
        PropertyManager propertyManager = PropertyManager.getInstance();
        Long forumResourceableId = forum.getResourceableId();
        Property forumproperty = propertyManager.getPropertyByLongValue(forumResourceableId, FOCourseNode.FORUM_KEY);
        if (forumproperty != null) {
            Long resourcetypeId = forumproperty.getResourceTypeId();
            String resourcetypeName = forumproperty.getResourceTypeName();
            OLATResourceable olatResourceable = olatManager.findResourceable(resourcetypeId, resourcetypeName);
            RepositoryEntry startCourse = repositoryManager.lookupRepositoryEntry(olatResourceable, false);
            if (startCourse != null) {
                runContext.put(SendMailStepForm.START_COURSE, startCourse);
            }
        }
        listenTo(exportCtrl);
        getWindowControl().pushAsModalDialog(exportCtrl.getInitialComponent());
    } else {
        showWarning("may.not.move.message");
    }
}
Also used : ErrorEditMessage(org.olat.modules.fo.ui.events.ErrorEditMessage) Message(org.olat.modules.fo.Message) OLATResourceable(org.olat.core.id.OLATResourceable) PropertyManager(org.olat.properties.PropertyManager) Step(org.olat.core.gui.control.generic.wizard.Step) RepositoryEntry(org.olat.repository.RepositoryEntry) StepsRunContext(org.olat.core.gui.control.generic.wizard.StepsRunContext) Step_1_SelectCourse(org.olat.modules.fo.export.Step_1_SelectCourse) Translator(org.olat.core.gui.translator.Translator) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) Property(org.olat.properties.Property) StepRunnerCallback(org.olat.core.gui.control.generic.wizard.StepRunnerCallback) FinishCallback(org.olat.modules.fo.export.FinishCallback)

Example 2 with PropertyManager

use of org.olat.properties.PropertyManager in project OpenOLAT by OpenOLAT.

the class MyForumsWebService method getForums.

/**
 * Retrieves a list of forums on a user base. All forums of groups
 * where the user is participant/tutor + all forums in course where
 * the user is a participant (owner, tutor or participant)
 * @response.representation.200.qname {http://www.example.com}forumVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The forums
 * @response.representation.200.example {@link org.olat.modules.fo.restapi.Examples#SAMPLE_FORUMVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param identityKey The key of the user (IdentityImpl)
 * @param httpRequest The HTTP request
 * @return The forums
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getForums(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    Roles roles;
    Identity retrievedUser = getIdentity(httpRequest);
    if (retrievedUser == null) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    } else if (!identityKey.equals(retrievedUser.getKey())) {
        if (isAdmin(httpRequest)) {
            retrievedUser = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey);
            roles = BaseSecurityManager.getInstance().getRoles(retrievedUser);
        } else {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    } else {
        roles = getRoles(httpRequest);
    }
    Map<Long, Long> groupNotified = new HashMap<Long, Long>();
    Map<Long, Collection<Long>> courseNotified = new HashMap<Long, Collection<Long>>();
    final Set<Long> subscriptions = new HashSet<Long>();
    NotificationsManager man = NotificationsManager.getInstance();
    {
        // collect subscriptions
        List<String> notiTypes = Collections.singletonList("Forum");
        List<Subscriber> subs = man.getSubscribers(retrievedUser, notiTypes);
        for (Subscriber sub : subs) {
            String resName = sub.getPublisher().getResName();
            Long forumKey = Long.parseLong(sub.getPublisher().getData());
            subscriptions.add(forumKey);
            if ("BusinessGroup".equals(resName)) {
                Long groupKey = sub.getPublisher().getResId();
                groupNotified.put(groupKey, forumKey);
            } else if ("CourseModule".equals(resName)) {
                Long courseKey = sub.getPublisher().getResId();
                if (!courseNotified.containsKey(courseKey)) {
                    courseNotified.put(courseKey, new ArrayList<Long>());
                }
                courseNotified.get(courseKey).add(forumKey);
            }
        }
    }
    final List<ForumVO> forumVOs = new ArrayList<ForumVO>();
    final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
    for (Map.Entry<Long, Collection<Long>> e : courseNotified.entrySet()) {
        final Long courseKey = e.getKey();
        final Collection<Long> forumKeys = e.getValue();
        final ICourse course = CourseFactory.loadCourse(courseKey);
        new CourseTreeVisitor(course, ienv).visit(new Visitor() {

            @Override
            public void visit(INode node) {
                if (node instanceof FOCourseNode) {
                    FOCourseNode forumNode = (FOCourseNode) node;
                    ForumVO forumVo = ForumCourseNodeWebService.createForumVO(course, forumNode, subscriptions);
                    if (forumKeys.contains(forumVo.getForumKey())) {
                        forumVOs.add(forumVo);
                    }
                }
            }
        }, new VisibleTreeFilter());
    }
    /*
		RepositoryManager rm = RepositoryManager.getInstance();
		ACService acManager = CoreSpringFactory.getImpl(ACService.class);
		SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule");
		repoParams.setOnlyExplicitMember(true);
		List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(repoParams, 0, -1, true);
		for(RepositoryEntry entry:entries) {
			AccessResult result = acManager.isAccessible(entry, retrievedUser, false);
			if(result.isAccessible()) {
				try {
					final ICourse course = CourseFactory.loadCourse(entry.getOlatResource());
					final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
					new CourseTreeVisitor(course, ienv).visit(new Visitor() {
						@Override
						public void visit(INode node) {
							if(node instanceof FOCourseNode) {
								FOCourseNode forumNode = (FOCourseNode)node;	
								ForumVO forumVo = ForumCourseNodeWebService.createForumVO(course, forumNode, subscriptions);
								forumVOs.add(forumVo);
							}
						}
					});
				} catch (Exception e) {
					log.error("", e);
				}
			}
		}*/
    // start found forums in groups
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
    params.addTools(CollaborationTools.TOOL_FORUM);
    List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
    // list forum keys
    List<Long> groupIds = new ArrayList<Long>();
    Map<Long, BusinessGroup> groupsMap = new HashMap<Long, BusinessGroup>();
    for (BusinessGroup group : groups) {
        if (groupNotified.containsKey(group.getKey())) {
            ForumVO forumVo = new ForumVO();
            forumVo.setName(group.getName());
            forumVo.setGroupKey(group.getKey());
            forumVo.setForumKey(groupNotified.get(group.getKey()));
            forumVo.setSubscribed(true);
            forumVOs.add(forumVo);
            groupIds.remove(group.getKey());
        } else {
            groupIds.add(group.getKey());
            groupsMap.put(group.getKey(), group);
        }
    }
    PropertyManager pm = PropertyManager.getInstance();
    List<Property> forumProperties = pm.findProperties(OresHelper.calculateTypeName(BusinessGroup.class), groupIds, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
    for (Property prop : forumProperties) {
        Long forumKey = prop.getLongValue();
        if (forumKey != null && groupsMap.containsKey(prop.getResourceTypeId())) {
            BusinessGroup group = groupsMap.get(prop.getResourceTypeId());
            ForumVO forumVo = new ForumVO();
            forumVo.setName(group.getName());
            forumVo.setGroupKey(group.getKey());
            forumVo.setForumKey(prop.getLongValue());
            forumVo.setSubscribed(false);
            forumVOs.add(forumVo);
        }
    }
    ForumVOes voes = new ForumVOes();
    voes.setForums(forumVOs.toArray(new ForumVO[forumVOs.size()]));
    voes.setTotalCount(forumVOs.size());
    return Response.ok(voes).build();
}
Also used : INode(org.olat.core.util.nodes.INode) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) HashMap(java.util.HashMap) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) PropertyManager(org.olat.properties.PropertyManager) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) FOCourseNode(org.olat.course.nodes.FOCourseNode) Subscriber(org.olat.core.commons.services.notifications.Subscriber) ArrayList(java.util.ArrayList) List(java.util.List) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) Property(org.olat.properties.Property) HashSet(java.util.HashSet) BusinessGroup(org.olat.group.BusinessGroup) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) BusinessGroupService(org.olat.group.BusinessGroupService) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with PropertyManager

use of org.olat.properties.PropertyManager in project OpenOLAT by OpenOLAT.

the class StatusWebservice method getSystemSummaryVO.

/**
 * Return the statistics about runtime: uptime, classes loaded, memory
 * summary, threads count...
 *
 * @response.representation.200.qname {http://www.example.com}runtimeVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The version of the instance
 * @response.representation.200.example {@link org.olat.restapi.system.vo.Examples#SAMPLE_RUNTIMEVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param request The HTTP request
 * @return The informations about runtime, uptime, classes loaded, memory summary...
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getSystemSummaryVO() {
    StatusVO stats = new StatusVO();
    // File
    try {
        long startFile = System.nanoTime();
        File infoFile = setInfoFiles("ping");
        WorkThreadInformations.unset();
        stats.setWriteFileInMilliseconds(CodeHelper.nanoToMilliTime(startFile));
        stats.setWriteFile(infoFile.exists());
        infoFile.delete();
    } catch (Exception e) {
        stats.setWriteFile(false);
        stats.setWriteFileInMilliseconds(-1l);
        log.error("", e);
    }
    // Datebase
    try {
        stats.setWriteDb(true);
        PropertyManager propertyManager = CoreSpringFactory.getImpl(PropertyManager.class);
        List<Property> props = propertyManager.findProperties((Identity) null, (BusinessGroup) null, PING_RESOURCE, PING_REF, PING_REF);
        if (props != null && props.size() > 0) {
            for (Property prop : props) {
                propertyManager.deleteProperty(prop);
            }
            DBFactory.getInstance().commit();
        }
        long startDB = System.nanoTime();
        Property prop = propertyManager.createPropertyInstance(null, null, PING_RESOURCE, PING_REF, PING_REF, 0f, 0l, "-", "-");
        DBFactory.getInstance().commit();
        stats.setWriteDbInMilliseconds(CodeHelper.nanoToMilliTime(startDB));
        propertyManager.deleteProperty(prop);
        DBFactory.getInstance().commit();
    } catch (Exception e) {
        stats.setWriteDb(false);
        stats.setWriteDbInMilliseconds(-1l);
        log.error("", e);
    }
    // Secure authenticated user
    UserSessionManager sessionManager = CoreSpringFactory.getImpl(UserSessionManager.class);
    Set<UserSession> userSessions = sessionManager.getAuthenticatedUserSessions();
    int secureAuthenticatedCount = 0;
    for (UserSession usess : userSessions) {
        SessionInfo sessInfo = usess.getSessionInfo();
        if (sessInfo.isWebDAV() || sessInfo.isREST()) {
        // 
        } else if (sessInfo.isSecure()) {
            secureAuthenticatedCount++;
        }
    }
    stats.setSecureAuthenticatedCount(secureAuthenticatedCount);
    // Concurrent dispatch threads
    SessionStatsManager sessionStatsManager = CoreSpringFactory.getImpl(SessionStatsManager.class);
    stats.setConcurrentDispatchThreads(sessionStatsManager.getConcurrentCounter());
    return Response.ok(stats).build();
}
Also used : PropertyManager(org.olat.properties.PropertyManager) SessionInfo(org.olat.core.util.SessionInfo) SessionStatsManager(org.olat.admin.sysinfo.manager.SessionStatsManager) IOException(java.io.IOException) UserSessionManager(org.olat.core.util.session.UserSessionManager) UserSession(org.olat.core.util.UserSession) File(java.io.File) Property(org.olat.properties.Property) StatusVO(org.olat.restapi.system.vo.StatusVO) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with PropertyManager

use of org.olat.properties.PropertyManager in project OpenOLAT by OpenOLAT.

the class StatisticUpdateManagerImpl method getAndUpdateLastUpdated.

@Override
public long getAndUpdateLastUpdated(long lastUpdated) {
    PropertyManager pm = PropertyManager.getInstance();
    Property p = pm.findProperty(null, null, null, STATISTICS_PROPERTIES_CATEGORY, LAST_UPDATED_PROPERTY_NAME);
    if (p == null) {
        Property newp = pm.createPropertyInstance(null, null, null, STATISTICS_PROPERTIES_CATEGORY, LAST_UPDATED_PROPERTY_NAME, null, lastUpdated, null, null);
        pm.saveProperty(newp);
        return -1;
    } else {
        final long result = p.getLongValue();
        p.setLongValue(lastUpdated);
        pm.saveProperty(p);
        return result;
    }
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property)

Example 5 with PropertyManager

use of org.olat.properties.PropertyManager in project OpenOLAT by OpenOLAT.

the class StatisticUpdateManagerImpl method getLastUpdated.

@Override
public long getLastUpdated() {
    PropertyManager pm = PropertyManager.getInstance();
    Property p = pm.findProperty(null, null, null, STATISTICS_PROPERTIES_CATEGORY, LAST_UPDATED_PROPERTY_NAME);
    if (p == null) {
        return -1;
    } else {
        return p.getLongValue();
    }
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property)

Aggregations

PropertyManager (org.olat.properties.PropertyManager)50 Property (org.olat.properties.Property)48 Test (org.junit.Test)10 Identity (org.olat.core.id.Identity)8 DBRuntimeException (org.olat.core.logging.DBRuntimeException)8 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)6 ArrayList (java.util.ArrayList)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 UserSession (org.olat.core.util.UserSession)4 NarrowedPropertyManager (org.olat.properties.NarrowedPropertyManager)4 OLATResourceable (org.olat.core.id.OLATResourceable)3 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)3 File (java.io.File)2 IOException (java.io.IOException)2 Calendar (java.util.Calendar)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2