@GET @Produces(MediaType.APPLICATION_JSON) public List<ResultEntity> search( @QueryParam("query") String query, @QueryParam("taxonomyPosition") String position, @QueryParam("spaceId") String spaceId, @QueryParam("appId") String appId, @QueryParam("startDate") String startDate, @QueryParam("endDate") String endDate) { QueryDescription queryDescription = new QueryDescription(query); queryDescription.setTaxonomyPosition(position); if (StringUtil.isDefined(startDate)) { try { String date = Instant.ofEpochMilli(Long.valueOf(startDate)) .atZone(ZoneId.systemDefault()) .toLocalDate() .format(formatter); queryDescription.setRequestedCreatedAfter(date); } catch (Exception e) { SilverLogger.getLogger(this) .info("Can't parse start date as Long : {0}", new String[] {startDate}, e); } } if (StringUtil.isDefined(endDate)) { try { String date = Instant.ofEpochMilli(Long.valueOf(endDate)) .atZone(ZoneId.systemDefault()) .toLocalDate() .format(formatter); queryDescription.setRequestedCreatedBefore(date); } catch (Exception e) { SilverLogger.getLogger(this) .info("Can't parse end date as Long : {0}", new String[] {endDate}, e); } } // determine where to search setComponents(queryDescription, spaceId, appId); SearchService searchService = SearchService.get(); List<ResultEntity> entities = new ArrayList<>(); try { List<SearchResult> results = searchService.search(queryDescription); for (SearchResult result : results) { entities.add(ResultEntity.fromSearchResult(result)); } } catch (Exception e) { SilverLogger.getLogger(this).error("Error during search...", e); throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); } return entities; }
/** Clears all the resources referenced into this instance of volatile cache. */ public void clear() { final VolatileResourceCacheService current = this; try { ManagedThreadPool.invoke( () -> { try { current.deleteAllAttachments(); } catch (RuntimeException e) { // This treatment must not disturb the server in any case, so nothing is thrown here. SilverLogger.getLogger(this) .error("The clear of volatile cache did not end successfully...", e); } }); } catch (RuntimeException e) { // This treatment must not disturb the server in any case, so nothing is thrown here. SilverLogger.getLogger(this) .error("The clear of volatile cache did not end successfully...", e); } }
public void initialize(String cron, List<String> domainIds) { try { this.domainIds = domainIds; Scheduler scheduler = SchedulerProvider.getScheduler(); scheduler.unscheduleJob(ADMINSYNCHRODOMAIN_JOB_NAME); JobTrigger trigger = JobTrigger.triggerAt(cron); scheduler.scheduleJob(ADMINSYNCHRODOMAIN_JOB_NAME, trigger, this); } catch (Exception e) { SilverLogger.getLogger(this).error(e.getMessage(), e); } }
public void doSynchro() { if (domainIds != null) { for (String domainId : domainIds) { try { AdministrationServiceProvider.getAdminService() .synchronizeSilverpeasWithDomain(domainId, true); } catch (Exception e) { SilverLogger.getLogger(this).error(e.getMessage(), e); } } } }
@Override public void init() throws Exception { try { Scheduler scheduler = SchedulerProvider.getScheduler(); if (scheduler.isJobScheduled(MAILING_LIST_JOB_NAME)) { scheduler.unscheduleJob(MAILING_LIST_JOB_NAME); } if (hasToCheckForNewMails()) { SilverLogger.getLogger(this) .info("Check mails from mailing lists every " + getFrequency() + " minutes"); MessageChecker checker = getMessageChecker(); JobTrigger trigger = JobTrigger.triggerEvery(getFrequency(), TimeUnit.MINUTE); scheduler.scheduleJob(MAILING_LIST_JOB_NAME, trigger, checker); List<MailingList> mailingLists = getMailingListService().listAllMailingLists(); for (MailingList list : mailingLists) { MailingListComponent component = new MailingListComponent(list.getComponentId()); checker.addMessageListener(component); } } } catch (SchedulerException ex) { SilverLogger.getLogger(this).error(ex.getMessage(), ex); } }
/** * Evaluates a simple Silverpeas rule. * * @param simpleSilverpeasRule the simple Silverpeas rule to evaluate. * @return a list of user identifiers. * @throws AdminException */ private List<String> evaluateSimpleSilverpeasRule(final String simpleSilverpeasRule) throws AdminException { if (simpleSilverpeasRule == null) { return null; } Matcher matcher = ACCESSLEVEL_STANDARD_DATA_PATTERN.matcher(simpleSilverpeasRule); if (matcher.find()) { return getUserIdsByAccessLevel(matcher.group(1)); } matcher = DOMAIN_STANDARD_DATA_PATTERN.matcher(simpleSilverpeasRule); if (matcher.find()) { // Split parameters as a list using comma separator and trimming spaces List<String> domainIds = asList(matcher.group(1).replaceAll("\\s", "").split(",")); List<String> userIds = new ArrayList<>(); for (String domainId : domainIds) { userIds.addAll(getUserIdsByDomain(domainId)); } return userIds; } matcher = GROUP_RULE_DATA_PATTERN.matcher(simpleSilverpeasRule); if (matcher.find()) { boolean withSubGroups = StringUtil.isDefined(matcher.group(1)); // Split parameters as a list using comma separator and trimming spaces String groupValues = matcher.group(2).replaceAll("\\s", ""); List<String> groupIds = asList(groupValues.split(",")); return getUserIdsByGroups(groupIds, withSubGroups); } matcher = COMPLEMENTARY_DATA_PATTERN.matcher(simpleSilverpeasRule); if (matcher.find()) { String propertyName = matcher.group(1); String propertyValue = matcher.group(2); return getUserIdsBySpecificProperty(propertyName, propertyValue); } SilverLogger.getLogger(this) .error( "ground rule '" + simpleSilverpeasRule + "' for groupId '" + group.getId() + "' is not correct !"); throw new GroundRuleError(simpleSilverpeasRule); }
public String getUserAutoRedirectURL(final String userId, final String target) { String encodedTarget = URLUtil.encodeURL(target); try { final UserDetail ud = UserDetail.getById(userId); final Domain dom = ud.getDomain(); String url; if (URLUtil.isPermalink(target)) { url = dom.getSilverpeasServerURL() + getApplicationURL() + target; } else { url = getUserAutoRedirectURL(dom) + encodedTarget; } return url; } catch (final Exception e) { SilverLogger.getLogger(this) .error( "Error while getting user auto redirect url {0} for user {1}", new String[] {target, userId}, e); return "ErrorGettingDomainServer" + encodedTarget; } }
@Override public void jobFailed(SchedulerEvent anEvent) { String jobName = anEvent.getJobExecutionContext().getJobName(); SilverLogger.getLogger(this).error("The domain synchronization job {0} failed!", jobName); }