Search in sources :

Example 6 with Schedule

use of javax.ejb.Schedule in project quickstart by wildfly.

the class ScheduleExample method doWork.

@Schedule(second = "*/6", minute = "*", hour = "*", persistent = false)
public void doWork() {
    Date currentTime = new Date();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z");
    System.out.println("ScheduleExample.doWork() invoked at " + simpleDateFormat.format(currentTime));
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Schedule(javax.ejb.Schedule)

Example 7 with Schedule

use of javax.ejb.Schedule in project Payara by payara.

the class SchedulesHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    Schedules annotation = (Schedules) ainfo.getAnnotation();
    Schedule[] schAnnotations = annotation.value();
    List<HandlerProcessingResult> results = new ArrayList<HandlerProcessingResult>();
    for (Schedule sch : schAnnotations) {
        results.add(processSchedule(sch, ainfo, ejbContexts));
    }
    return getOverallProcessingResult(results);
}
Also used : Schedules(javax.ejb.Schedules) HandlerProcessingResult(org.glassfish.apf.HandlerProcessingResult) Schedule(javax.ejb.Schedule) ArrayList(java.util.ArrayList)

Example 8 with Schedule

use of javax.ejb.Schedule in project ART-TIME by Artezio.

the class NotificationScheduler method notifyAboutIncorrectTimesheet.

@Schedule(dayOfMonth = "1", persistent = false, info = NOTIFY_ABOUT_INCORRECT_TIMESHEET_INFO)
public void notifyAboutIncorrectTimesheet() {
    if (settingsService.getSettings().isIncorrectTimesheetNotificationEnabled()) {
        List<Employee> employees = employeeService.getCurrent();
        Period period = getPeriodForPreviousMonth();
        notificationManager.notifyAboutIncorrectTimesheet(employees, period);
    }
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) Period(com.artezio.arttime.datamodel.Period) Schedule(javax.ejb.Schedule)

Example 9 with Schedule

use of javax.ejb.Schedule in project muikku by otavanopisto.

the class DeusNexServiceDownloadUpdater method downloadNext.

@Schedule(hour = "*", minute = "*", second = "*/20", persistent = false)
public void downloadNext() {
    if (contextInitialized) {
        if (!running) {
            running = true;
            try {
                Long pendingDownload = deusNexImportQueueController.getNextPendingDownload();
                if (pendingDownload != null) {
                    logger.info(String.format("Processing dnm document #%d", pendingDownload));
                    try {
                        Document document = client.getDocument(pendingDownload);
                        if (document != null) {
                            logger.info(String.format("Downloading dnm document #%d (%s)", document.getId(), document.getPath()));
                            String documentData = client.getDocumentData(pendingDownload);
                            if (documentData != null) {
                                String path = document.getPath();
                                int slashIndex = path.indexOf('/');
                                String workspacePath = slashIndex > -1 ? path.substring(slashIndex + 1) : null;
                                String dnmId = slashIndex > -1 ? path.substring(0, slashIndex) : path;
                                Long workspaceEntityId = deusNexMachinaController.getWorkspaceEntityIdDnmId(dnmId);
                                WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
                                if (workspaceEntity != null) {
                                    if ("[_FPF_]".equals(workspacePath)) {
                                        logger.info(String.format("Importing front-page document #%d into workspace %s", document.getId(), workspaceEntity.getUrlName()));
                                        InputStream documentStream = new ByteArrayInputStream(documentData.getBytes("UTF-8"));
                                        try {
                                            deusNexMachinaController.importFrontPageDocument(workspaceEntity, documentStream);
                                        } finally {
                                            documentStream.close();
                                        }
                                    } else if ("[_HELP_PAGE_]".equals(workspacePath)) {
                                        logger.info(String.format("Importing help-page document #%d into workspace %s", document.getId(), workspaceEntity.getUrlName()));
                                        InputStream documentStream = new ByteArrayInputStream(documentData.getBytes("UTF-8"));
                                        try {
                                            deusNexMachinaController.importHelpPageDocument(workspaceEntity, documentStream);
                                        } finally {
                                            documentStream.close();
                                        }
                                    } else {
                                        WorkspaceNode parentNode = null;
                                        if (StringUtils.isBlank(workspacePath)) {
                                            parentNode = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
                                        } else {
                                            String[] pathElements = workspacePath.split("/");
                                            parentNode = workspaceMaterialController.findWorkspaceRootFolderByWorkspaceEntity(workspaceEntity);
                                            WorkspaceNode parent = parentNode;
                                            for (int i = 0, l = pathElements.length; i < l; i++) {
                                                String pathElement = pathElements[i];
                                                parentNode = workspaceMaterialController.findWorkspaceNodeByParentAndUrlName(parent, pathElement);
                                                if (parentNode == null) {
                                                    parentNode = workspaceMaterialController.createWorkspaceFolder(parent, pathElement, pathElement);
                                                }
                                                parent = parentNode;
                                            }
                                        }
                                        logger.info(String.format("Importing dnm document #%d into workspace %s", document.getId(), workspaceEntity.getUrlName()));
                                        InputStream documentStream = new ByteArrayInputStream(documentData.getBytes("UTF-8"));
                                        try {
                                            deusNexMachinaController.importDeusNexDocument(parentNode, documentStream);
                                        } finally {
                                            documentStream.close();
                                        }
                                    }
                                    deusNexImportQueueController.removePendingDownload(pendingDownload);
                                    deusNexImportQueueController.addDownloaded(document.getId());
                                    logger.info(String.format("Processed dnm document #%d (%s)", document.getId(), document.getPath()));
                                } else {
                                    logger.log(Level.WARNING, String.format("Ignoring import for document %s because maching workspace could not be found", document.getPath()));
                                }
                            } else {
                                logger.severe(String.format("Pending dnm document %d did not contain any data", pendingDownload));
                            }
                        } else {
                            logger.severe(String.format("Pending dnm document %d could not be found", pendingDownload));
                        }
                    } catch (Exception e) {
                        logger.warning(String.format("Dnm document %d processing failed, added it back to queue: " + e.getMessage(), pendingDownload));
                    }
                }
            } finally {
                running = false;
            }
        }
    }
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) Schedule(javax.ejb.Schedule)

Example 10 with Schedule

use of javax.ejb.Schedule in project muikku by otavanopisto.

the class ChatRoomSyncScheduler method updateChatRooms.

@Schedule(second = "*", minute = "*/15", hour = "*", persistent = false)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void updateChatRooms() {
    String enabledWorkspacesCsv = pluginSettingsController.getPluginSetting("chat", "enabledWorkspaces");
    if (enabledWorkspacesCsv == null) {
        return;
    }
    List<String> enabledWorkspaces = Arrays.asList(enabledWorkspacesCsv.split(","));
    String openfireToken = pluginSettingsController.getPluginSetting("chat", "openfireToken");
    if (openfireToken == null) {
        logger.log(Level.INFO, "No openfire token set, skipping room sync");
        return;
    }
    String openfireUrl = pluginSettingsController.getPluginSetting("chat", "openfireUrl");
    if (openfireUrl == null) {
        logger.log(Level.INFO, "No openfire url set, skipping room sync");
        return;
    }
    String openfirePort = pluginSettingsController.getPluginSetting("chat", "openfirePort");
    if (openfirePort == null) {
        logger.log(Level.INFO, "No openfire port set, skipping room sync");
        return;
    }
    if (!StringUtils.isNumeric(openfirePort)) {
        logger.log(Level.WARNING, "Invalid openfire port, skipping room sync");
        return;
    }
    AuthenticationToken token = new AuthenticationToken(openfireToken);
    RestApiClient client = new RestApiClient(openfireUrl, Integer.parseInt(openfirePort, 10), token);
    for (String enabledWorkspace : enabledWorkspaces) {
        try {
            // Checking before creating is subject to a race condition, but in the worst case
            // the creation just fails, resulting in a log entry
            MUCRoomEntity chatRoomEntity = client.getChatRoom(enabledWorkspace);
            if (chatRoomEntity == null) {
                logger.log(Level.INFO, "Syncing chat workspace " + enabledWorkspace);
                SchoolDataIdentifier identifier = SchoolDataIdentifier.fromId(enabledWorkspace);
                if (identifier == null) {
                    logger.log(Level.WARNING, "Invalid workspace identifier " + enabledWorkspace + ", skipping...");
                    continue;
                }
                WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceByUrlName(enabledWorkspace);
                if (workspaceEntity == null) {
                    logger.log(Level.WARNING, "No workspace entity found for identifier " + enabledWorkspace + ", skipping...");
                    continue;
                }
                Workspace workspace = workspaceController.findWorkspace(workspaceEntity);
                chatRoomEntity = new MUCRoomEntity(enabledWorkspace, workspace.getName(), workspace.getDescription());
                client.createChatRoom(chatRoomEntity);
            }
        } catch (Exception e) {
            logger.log(Level.INFO, "Exception when syncing chat workspace " + enabledWorkspace, e);
        }
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) AuthenticationToken(fi.otavanopisto.muikku.openfire.rest.client.entity.AuthenticationToken) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) MUCRoomEntity(fi.otavanopisto.muikku.openfire.rest.client.entity.MUCRoomEntity) RestApiClient(fi.otavanopisto.muikku.openfire.rest.client.RestApiClient) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) TransactionAttribute(javax.ejb.TransactionAttribute) Schedule(javax.ejb.Schedule)

Aggregations

Schedule (javax.ejb.Schedule)11 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)3 TransactionAttribute (javax.ejb.TransactionAttribute)3 Employee (com.artezio.arttime.datamodel.Employee)2 Period (com.artezio.arttime.datamodel.Period)2 RestApiClient (fi.otavanopisto.muikku.openfire.rest.client.RestApiClient)2 AuthenticationToken (fi.otavanopisto.muikku.openfire.rest.client.entity.AuthenticationToken)2 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)1 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)1 FeedException (com.rometools.rome.io.FeedException)1 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)1 XmlReader (com.rometools.rome.io.XmlReader)1 HiddenMonitor (eu.ggnet.saft.api.progress.HiddenMonitor)1 MUCRoomEntity (fi.otavanopisto.muikku.openfire.rest.client.entity.MUCRoomEntity)1 UserEntity (fi.otavanopisto.muikku.openfire.rest.client.entity.UserEntity)1 Feed (fi.otavanopisto.muikku.plugins.feed.model.Feed)1 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)1