Package common.api

Examples of common.api.ApiClient


    }
   
    public static void dirs(String path) {
        checkAuthenticity();
        User u = Login.getUser();
        ApiClient client = ApiClientFactory.create(u);
        try {
          renderJSON(client.listDir(path, ApiClient.ListingType.DIRS));
        } catch (NotADirectoryException e) {
            Logger.error(e, "User attempt to list a directory which is infact a file: %s", u);
            renderJSON(Collections.emptyList());
        } catch (InvalidTokenException e) {
            Logger.error(e, "Invalid OAuth token for user %s", u);
View Full Code Here


   
    private static InitResult initSortbox(User user) {
        boolean createdSortboxDir = false;
        boolean createdCannedRules = false;
        try {
            ApiClient client = ApiClientFactory.create(user);

            // now get the new sorting folder path for the user and keep going forward
            String sortboxPath = user.sortingFolder;
            if (! client.exists(sortboxPath)) {
                // 1. create missing Sortbox folder
                Logger.info("SortMyBox folder missing for user '%s' at path '%s'",
                          user, sortboxPath);
                createdSortboxDir = client.mkdir(sortboxPath);
                if (createdSortboxDir) {
                    // 2. create canned rules
                    createdCannedRules = createCannedRules(user);
                }
            }
View Full Code Here

  public static void sortingFolder(@Required String folder) {
        User u = Login.getUser();
        folder = RuleUtils.normalize(folder, false);

      try {
          ApiClient api = ApiClientFactory.create(u);
          boolean createdFolder = false;
            if (! api.exists(folder)) {
                Logger.info("Folder does not exist attempting to create %s", folder);
                if (api.mkdir(folder)) {
                    Logger.info("Successfully created folder %s", folder);
                    createdFolder = true;
                } else {
                    Logger.error("Failed to create folder '%s'", folder);
                    flash.error("Error: folder %s is missing and we couldn't create it.", folder);
View Full Code Here

     *
     * @return list of file moves performed
     */
    public static List<FileMove> runRules(User user) {
        List<FileMove> fileMoves = Lists.newArrayList();
        ApiClient client = ApiClientFactory.create(user);
        try {
            Set<String> files = client.listDir(user.sortingFolder)

            if (files.isEmpty()) {
                Logger.info("Ran rules for %s, no files to process.", user);
                return fileMoves;
            }

            user.updateLastSyncDate();

            List<Rule> rules = Rule.findByUserId(user.getKey());
            Logger.info("Running rules for %s with files %s", user, files);

            for (String file : files) {
                String base = basename(file);
                for (Rule r : rules) {
                    if (r.matches(base)) {
                        Logger.info("Moving file '%s' to '%s'. Rule id: %s",
                                    file, r.dest, r.id);
                        boolean hasCollision = false;
                        String resolvedName = null;
                        for (int tries = 0; tries < MAX_TRIES; tries++) {
                            try {
                                String suffix = null;
                                if (hasCollision) {
                                    suffix = " conflict"
                                            + (tries > 1 ? " " + tries : "");
                                }

                                resolvedName = removeInvalidChars(insertIntoName(base, suffix));

                                String dest = r.dest +
                                              (r.dest.endsWith("/") ? "" : "/") +
                                              resolvedName;
                                client.move(file, dest);
                                break;
                            } catch (FileMoveCollisionException e) {
                                hasCollision = true;
                                resolvedName = null;
                            }
View Full Code Here

TOP

Related Classes of common.api.ApiClient

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.