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");
}
}
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();
}
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();
}
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;
}
}
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();
}
}
Aggregations