Add a path to a profile, returns the id

@param id ID of profile
@param pathname name of path
@param actualPath value of path
@return ID of path created
@throws Exception exception
559767
public int addPathnameToProfile(int id, String pathname, String actualPath) throws Exception {
        int pathOrder = getPathOrder(id).size() + 1;
        int pathId = -1;
        PreparedStatement statement = null;
        ResultSet results = null;

        try (Connection sqlConnection = sqlService.getConnection()) {
            statement = sqlConnection.prepareStatement(
                "INSERT INTO " + Constants.DB_TABLE_PATH
                    + "(" + Constants.PATH_PROFILE_PATHNAME + ","
                    + Constants.PATH_PROFILE_ACTUAL_PATH + ","
                    + Constants.PATH_PROFILE_GROUP_IDS + ","
                    + Constants.PATH_PROFILE_PROFILE_ID + ","
                    + Constants.PATH_PROFILE_PATH_ORDER + ","
                    + Constants.PATH_PROFILE_CONTENT_TYPE + ","
                    + Constants.PATH_PROFILE_REQUEST_TYPE + ","
                    + Constants.PATH_PROFILE_GLOBAL + ")"
                    + " VALUES (?, ?, ?, ?, ?, ?, ?, ?);",
                PreparedStatement.RETURN_GENERATED_KEYS
            );
            statement.setString(1, pathname);
            statement.setString(2, actualPath);
            statement.setString(3, "");
            statement.setInt(4, id);
            statement.setInt(5, pathOrder);
            statement.setString(6, Constants.PATH_PROFILE_DEFAULT_CONTENT_TYPE); // should be set by UI/API
            statement.setInt(7, Constants.REQUEST_TYPE_GET); // should be set by UI/API
            statement.setBoolean(8, false);
            statement.executeUpdate();

            // execute statement and get resultSet which will have the generated path ID as the first field
            results = statement.getGeneratedKeys();

            if (results.next()) {
                pathId = results.getInt(1);
            } else {
                // something went wrong
                throw new Exception("Could not add path");
            }
        } catch (SQLException e) {
            throw e;
        } finally {
            try {
                if (results != null) {
                    results.close();
                }
            } catch (Exception e) {
            }
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }

        // need to add to request response table for all clients
        for (Client client : ClientService.getInstance().findAllClients(id)) {
            this.addPathToRequestResponseTable(id, client.getUUID(), pathId);
        }

        return pathId;
    }
513660
private void createPathQuery(String path, int operation)
   {
      MergingPathQueryNode pathNode =
         new MergingPathQueryNode(operation, factory.createPathQueryNode(null).getValidJcrSystemNodeTypeNames());
      pathNode.setAbsolute(true);

      if (path.equals("/"))
      {
         pathNode.addPathStep(factory.createLocationStepQueryNode(pathNode));
         pathConstraints.add(pathNode);
         return;
      }

      String[] names = path.split("/");

      for (int i = 0; i < names.length; i++)
      {
         if (names[i].length() == 0)
         {
            if (i == 0)
            {
               // root
               pathNode.addPathStep(factory.createLocationStepQueryNode(pathNode));
            }
            else
            {
               // descendant '//' -> invalid path
               // todo throw or ignore?
               // we currently do not throw and add location step for an
               // empty name (which is basically the root node)
               pathNode.addPathStep(factory.createLocationStepQueryNode(pathNode));
            }
         }
         else
         {
            int idx = names[i].indexOf('[');
            String name;
            int index = LocationStepQueryNode.NONE;
            if (idx > -1)
            {
               // contains index
               name = names[i].substring(0, idx);
               String suffix = names[i].substring(idx);
               String indexStr = suffix.substring(1, suffix.length() - 1);
               if (indexStr.equals("%"))
               {
                  // select all same name siblings
                  index = LocationStepQueryNode.NONE;
               }
               else
               {
                  try
                  {
                     index = Integer.parseInt(indexStr);
                  }
                  catch (NumberFormatException e)
                  {
                     log.warn("Unable to parse index for path element: " + names[i]);
                  }
               }
               if (name.equals("%"))
               {
                  name = null;
               }
            }
            else
            {
               // no index specified
               // - index defaults to 1 if there is an explicit name test
               // - index defaults to NONE if name test is %
               name = names[i];
               if (name.equals("%"))
               {
                  name = null;
               }
               else
               {
                  index = 1;
               }
            }
            InternalQName qName = null;
            if (name != null)
            {
               try
               {
                  qName = resolver.parseJCRName(name).getInternalName();
               }
               catch (NamespaceException e)
               {
                  throw new IllegalArgumentException("Illegal name: " + name, e);
               }
               catch (RepositoryException e)
               {
                  throw new IllegalArgumentException("Illegal name: " + name, e);
               }

            }
            // if name test is % this means also search descendants
            boolean descendant = name == null;
            LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode);
            step.setNameTest(qName);
            step.setIncludeDescendants(descendant);
            if (index > 0)
            {
               step.setIndex(index);
            }
            pathNode.addPathStep(step);
         }
      }
      pathConstraints.add(pathNode);
   }
1265419
protected String getObjectPath(String id, String name) {
        // The format of the object id is <type>/<path>/<objectName>
        id = id.substring(id.indexOf('/') + 1);
        if (id.charAt(0) == '/') {
            id = id.substring(1);
        }
        if (id.lastIndexOf(name) <= 0) {
            return id;
        }
        return id.substring(0, id.lastIndexOf(name) - 1);
    }
60589
@RequestMapping(value = "{accountId}", method = RequestMethod.GET)
    public Account getAccount(@PathVariable ID accountId) {
        return accountService.getAccount(accountId);
    }
994195
public void setName(int pathId, String pathName) {
        PreparedStatement statement = null;
        try (Connection sqlConnection = sqlService.getConnection()) {
            statement = sqlConnection.prepareStatement(
                "UPDATE " + Constants.DB_TABLE_PATH +
                    " SET " + Constants.PATH_PROFILE_PATHNAME + " = ?" +
                    " WHERE " + Constants.GENERIC_ID + " = ?"
            );
            statement.setString(1, pathName);
            statement.setInt(2, pathId);
            statement.executeUpdate();
            statement.close();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
    }
1209230
private void indexDirectory(String id, fr.pilato.elasticsearch.crawler.fs.beans.Path path) throws Exception {
        esIndex(fsSettings.getElasticsearch().getIndexFolder(),
                id,
                PathParser.toJson(path),
                null);
    }
115895
public boolean addPath(String path) throws MalformedURLException {
        File file = new File(path);
        return addPath( file );
    }
973551
public static boolean setCustomRequestForDefaultClient(String profileName, String pathName, String customData) {
        try {
            return setCustomForDefaultClient(profileName, pathName, false, customData);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
1271365
@Path("{id}")
    public InstanceResource getInstanceInfo(@PathParam("id") String id) {
        return new InstanceResource(this, id, serverConfig, registry);
    }
816068
Node getProfileNode(Session session, String userName) throws PathNotFoundException, RepositoryException
   {
      return (Node)session.getItem(service.getStoragePath() + "/" + JCROrganizationServiceImpl.STORAGE_JOS_USERS + "/"
         + userName + "/" + JCROrganizationServiceImpl.JOS_PROFILE);
   }
1017167
public GetTrackRequest.Builder getTrack(String id) {
    return new GetTrackRequest.Builder(accessToken)
            .setDefaults(httpManager, scheme, host, port)
            .id(id);
  }
331098
@GET
    @Path("{id}/history")
    public Response fetchHistory(@PathParam("id") URI_ID id) throws Exception {
        return super.fetchHistory(id);
    }
241312
public void setPath(int pathId, String path) {
        PreparedStatement statement = null;
        try (Connection sqlConnection = sqlService.getConnection()) {
            statement = sqlConnection.prepareStatement(
                "UPDATE " + Constants.DB_TABLE_PATH +
                    " SET " + Constants.PATH_PROFILE_ACTUAL_PATH + " = ? " +
                    " WHERE " + Constants.GENERIC_ID + " = ?"
            );
            statement.setString(1, path);
            statement.setInt(2, pathId);
            statement.executeUpdate();
            statement.close();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }
    }
40884
@RequestMapping(value = "", method = RequestMethod.GET)
    public String pathOrderHome(Model model, @PathVariable int profileId,
                                @RequestParam(value = "clientUUID", defaultValue = "-1") String clientUUID) throws Exception {

        model.addAttribute("profile_id", profileId);
        model.addAttribute("profile_name", ProfileService.getInstance().getNamefromId(profileId));
        model.addAttribute("pathnames", PathOverrideService.getInstance().getPaths(profileId, clientUUID, null));

        return "pathOrder";
    }
1026749
public static Error get(final BandwidthClient client, final String id) throws Exception {
        final String errorsUri = client.getUserResourceInstanceUri(BandwidthConstants.ERRORS_URI_PATH, id);

        final JSONObject jsonObject = toJSONObject(client.get(errorsUri, null));
        return new Error(client, errorsUri, jsonObject);
    }
361651
@RequestMapping(value = "/getThumbnail.action", method = RequestMethod.GET)
    public ResponseEntity<?> getThumbnail(@RequestParam Integer id) {

        final HttpHeaders responseHeaders = new HttpHeaders();
        Map<String, Object> responseMap;

        try {
            // try to get the image
            ImageFile image = service.findById(id);
            if (image == null) {
                throw new Exception("Could not find the image with id " + id);
            }

            byte[] imageBytes = null;

            imageBytes = image.getThumbnail();

            responseHeaders.setContentType(
                MediaType.parseMediaType(image.getFileType()));

            LOG.info("Successfully got the image thumbnail " +
                image.getFileName());

            return new ResponseEntity<byte[]>(
                imageBytes, responseHeaders, HttpStatus.OK);
        } catch (Exception e) {
            final String errorMessage = "Could not get the image thumbnail: "
                + e.getMessage();

            LOG.error(errorMessage);
            responseMap = ResultSet.error(errorMessage);

            responseHeaders.setContentType(MediaType.APPLICATION_JSON);

            return new ResponseEntity<Map<String, Object>>(
                responseMap, responseHeaders, HttpStatus.OK);
        }
    }
134084
static String getJobIdFromPath(Path aPath) {
    String fileName = aPath.getName();
    JobFile jf = new JobFile(fileName);
    String jobId = jf.getJobid();
    if(jobId == null) {
      throw new ProcessingException("job id is null for " + aPath.toUri());
    }
    return jobId;
  }