Package org.apache.marmotta.platform.core.api.task

Examples of org.apache.marmotta.platform.core.api.task.Task


        }
        if (type == null || !importService.getAcceptTypes().contains(type)) return Response.status(412).entity("define a valid content-type (types: "+importService.getAcceptTypes()+")").build();
        final String finalType = type;
        final InputStream in = request.getInputStream();

        Task t = taskManagerService.createTask(String.format("Upload-Import from %s (%s)", request.getRemoteHost(), finalType), TASK_GROUP_NAME);
        t.updateMessage("preparing import...");
        t.updateDetailMessage("type", finalType);
        try {
            //create context
            URI context = getContext(context_string);
            if (context != null) {
                t.updateDetailMessage("context", context.toString());
            }

            t.updateMessage("importing data...");
            importService.importData(in,finalType, userService.getCurrentUser(), context);
            t.updateMessage("import complete");

            return Response.ok().entity("import of content successful\n").build();
        } catch(Exception ex) {
            log.error("error while importing", ex);
            return Response.status(500).entity("error while importing: " + ex.getMessage()).build();
View Full Code Here


            final String finalType = type;
            Runnable r = new Runnable() {

                @Override
                public void run() {
                    Task task = taskManagerService.createTask("Import from external source", TASK_GROUP_NAME);
                    task.updateDetailMessage("source", finalUrl.toExternalForm());
                    task.updateDetailMessage("type", finalType);
                    if (context != null) {
                        task.updateDetailMessage("context", context.toString());
                    }
                    try {
                        importService.importData(finalUrl,finalType,userService.getCurrentUser(),context);
                    } catch(Exception e) {
                        log.error("exception while asynchronously importing data",e);
View Full Code Here

            return delegate.getConnectionManager();
        }

        @Override
        public HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException {
            final Task task = preProcess(request);

            final HttpResponse response;
            lock.readLock().lock();
            try {
                response = delegate.execute(request);
            } catch (ClientProtocolException cpe) {
                task.endTask();
                throw cpe;
            } catch (IOException io) {
                task.endTask();
                throw io;
            } finally {
                lock.readLock().unlock();
            }
View Full Code Here

            return postProcess(response, null, task);
        }

        @Override
        public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException, ClientProtocolException {
            final Task task = preProcess(request);

            final HttpResponse response;
            lock.readLock().lock();
            try {
                response = delegate.execute(request, context);
            } catch (ClientProtocolException cpe) {
                task.endTask();
                throw cpe;
            } catch (IOException io) {
                task.endTask();
                throw io;
            } finally {
                lock.readLock().unlock();
            }
View Full Code Here

        private Task preProcess(HttpRequest request) {
            final RequestLine rl = request.getRequestLine();
            final String taskName = String.format("%S %s %S", rl.getMethod(), rl.getUri(), request.getProtocolVersion());

            final Task task = taskManagerService.createSubTask(taskName, TASK_GROUP_CLIENT);
            task.updateMessage("preparing request");
            task.updateDetailMessage("method", rl.getMethod());
            task.updateDetailMessage("url", rl.getUri());
            // TODO: some more detail messages?

            if (request instanceof HttpEntityEnclosingRequest) {
                // To report upload progress, the entity is wrapped in a MonitoredHttpEntity.
                final HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request;
                entityRequest.setEntity(new MonitoredHttpEntity(entityRequest.getEntity(), task, bytesSent));
            }

            task.updateMessage("sending request");
            return task;
        }
View Full Code Here

            return response;
        }

        @Override
        public HttpResponse execute(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException {
            final Task task = preProcess(request);

            final HttpResponse response;
            lock.readLock().lock();
            try {
                response = delegate.execute(target, request);
            } catch (ClientProtocolException cpe) {
                task.endTask();
                throw cpe;
            } catch (IOException io) {
                task.endTask();
                throw io;
            } finally {
                lock.readLock().unlock();
            }
View Full Code Here

            return postProcess(response, null, task);
        }

        @Override
        public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException {
            final Task task = preProcess(request);

            final HttpResponse response;
            lock.readLock().lock();
            try {
                response = delegate.execute(target, request, context);
            } catch (ClientProtocolException cpe) {
                task.endTask();
                throw cpe;
            } catch (IOException io) {
                task.endTask();
                throw io;
            } finally {
                lock.readLock().unlock();
            }
View Full Code Here

    Runnable r = new Runnable() {

      @Override
      public void run() {
        final Task task = taskManagerService.createTask("Directory import watch", TASK_GROUP);
        task.updateMessage("watching...");
        task.updateDetailMessage(TASK_DETAIL_PATH, path);

        try {
          Path root = Paths.get(path);
          WatchService watcher = root.getFileSystem().newWatchService();
          register(root, watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE);
          while (true) {
            final WatchKey key = watcher.take();
            for (WatchEvent<?> event : key.pollEvents()) {
             
              @SuppressWarnings("unchecked")
              Path item = ((WatchEvent<Path>) event).context();
              Path dir = keys.get(key);
              File file = new File(dir.toString(), item.toString()).getAbsoluteFile();
             
              if (StandardWatchEventKinds.ENTRY_CREATE.equals(event.kind())) {
                if (file.isDirectory()) {
                  //recursive registration of sub-directories
                  register(Paths.get(dir.toString(), item.toString()), watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE);
                  task.updateProgress(++count);
                } else {
                  URI context = getTargetContext(file);
                  log.debug("Importing '{}'...", file.getAbsolutePath());
                  task.updateMessage("importing...");
                  task.updateDetailMessage(TASK_DETAIL_PATH, file.getAbsolutePath());
                  task.updateDetailMessage(TASK_DETAIL_CONTEXT, context.stringValue());
                  if (execImport(file, context)) {
                    log.info("Sucessfully imported file '{}' into {}", file.getAbsolutePath(), context.stringValue());
                    try {
                      //delete the imported file
                      log.debug("Deleting {}...", file.getAbsolutePath());
                      file.delete();
                    } catch (Exception ex) {
                      log.error("Error deleing {}: {}", file.getAbsolutePath(), ex.getMessage());
                    }
                  }
                  task.updateProgress(++count);
                  task.updateMessage("watching...");
                  task.updateDetailMessage(TASK_DETAIL_PATH, path);
                  task.removeDetailMessage(TASK_DETAIL_CONTEXT);
                }
              } else if (StandardWatchEventKinds.ENTRY_DELETE.equals(event.kind()) && Files.isDirectory(item)) {
                //TODO: unregister deleted directories?
                task.updateProgress(++count);
              }
             
            }
            if (!key.reset()) {
              // exit loop if the key is not valid
View Full Code Here

        }
        if (type == null || !importService.getAcceptTypes().contains(type)) return Response.status(412).entity("define a valid content-type (types: "+importService.getAcceptTypes()+")").build();
        final String finalType = type;
        final InputStream in = request.getInputStream();

        Task t = taskManagerService.createTask(String.format("Upload-Import from %s (%s)", request.getRemoteHost(), finalType), TASK_GROUP_NAME);
        t.updateMessage("preparing import...");
        t.updateDetailMessage("type", finalType);
        try {
            //create context
            URI context = getContext(context_string);
            if (context != null) {
                t.updateDetailMessage("context", context.toString());
            }

            t.updateMessage("importing data...");
            importService.importData(in,finalType, userService.getCurrentUser(), context);
            t.updateMessage("import complete");

            return Response.ok().entity("import of content successful\n").build();
        } catch(Exception ex) {
            log.error("error while importing", ex);
            return Response.status(500).entity("error while importing: " + ex.getMessage()).build();
View Full Code Here

            final String finalType = type;
            Runnable r = new Runnable() {

                @Override
                public void run() {
                    Task task = taskManagerService.createTask("Import from external source", TASK_GROUP_NAME);
                    task.updateDetailMessage("source", finalUrl.toExternalForm());
                    task.updateDetailMessage("type", finalType);
                    if (ctx != null) {
                        task.updateDetailMessage("context", ctx.toString());
                    }
                    try {
                        importService.importData(finalUrl,finalType,userService.getCurrentUser(),ctx);
                    } catch(Exception e) {
                        log.error("exception while asynchronously importing data",e);
View Full Code Here

TOP

Related Classes of org.apache.marmotta.platform.core.api.task.Task

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.