/** * Attempt to parse a {@link Repository} from the given {@link Uri} * * @param uri * @return {@link Repository} or null if unparseable */ public static Repository getRepository(Uri uri) { List<String> segments = uri.getPathSegments(); if (segments == null) return null; if (segments.size() < 2) return null; String repoOwner = segments.get(0); if (!RepositoryUtils.isValidOwner(repoOwner)) return null; String repoName = segments.get(1); if (!RepositoryUtils.isValidRepo(repoName)) return null; return InfoUtils.createRepoFromData(repoOwner, repoName); }
public ListBoxModel doFillTypeItems( @QueryParameter(value = "credential") @RelativePath(value = "..") String credentialExistingEmbeddeds, @QueryParameter(value = "credential") @RelativePath(value = "../..") String credentialNewEmbeddeds, @AncestorInPath AbstractProject project) { String creds = credentialExistingEmbeddeds != null ? credentialExistingEmbeddeds : credentialNewEmbeddeds; Credential credential = RepositoryUtils.retrieveOverridingCredentialFromProject(project); DeployitServer deployitServer = RepositoryUtils.getDeployitServer(creds, credential); return of(RepositoryUtils.getAllEmbeddedResourceTypes(deployitServer)); }
@Test public void testGetFolder() throws Exception { final MockUnifiedRepository repository = new MockUnifiedRepository(new SpringSecurityCurrentUserProvider()); final RepositoryUtils repositoryUtils = new RepositoryUtils(repository); RepositoryFile test = repositoryUtils.getFolder("/public/one/two/three", true, true, null); assertNotNull(test); assertEquals("The folder name is invalid", "three", test.getName()); assertEquals("The path is invalid", "/public/one/two/three", test.getPath()); assertTrue("The folder should be defined as a folder", test.isFolder()); // Make sure it created the parents RepositoryFile one = repositoryUtils.getFolder("/public/one", false, false, null); assertNotNull(one); RepositoryFile two = repositoryUtils.getFolder("/public/one/two", false, false, null); assertNotNull(two); }
/** * Get repository and throw a {@link MojoExecutionException} on failures * * @param project * @param owner * @param name * @return non-null repository id * @throws MojoExecutionException */ protected RepositoryId getRepository( final MavenProject project, final String owner, final String name) throws MojoExecutionException { RepositoryId repository = RepositoryUtils.getRepository(project, owner, name); if (repository == null) throw new MojoExecutionException("No GitHub repository (owner and name) configured"); if (isDebug()) debug(MessageFormat.format("Using GitHub repository {0}", repository.generateId())); return repository; }
@Test public void testGetFile() throws Exception { final MockUnifiedRepository repository = new MockUnifiedRepository(new SpringSecurityCurrentUserProvider()); final RepositoryUtils repositoryUtils = new RepositoryUtils(repository); final SimpleRepositoryFileData data = new SimpleRepositoryFileData( new ByteArrayInputStream("Test".getBytes()), "UTF-8", "text/plain"); RepositoryFile test = repositoryUtils.getFile("/public/one/two/three.prpt", data, true, true, null); assertNotNull(test); assertEquals("The filename is invalid", "three.prpt", test.getName()); assertEquals("The path is invalid", "/public/one/two/three.prpt", test.getPath()); assertFalse("The file should not be defined as a folder", test.isFolder()); // Make sure it created the parents RepositoryFile one = repositoryUtils.getFolder("/public/one", false, false, null); assertNotNull(one); RepositoryFile two = repositoryUtils.getFolder("/public/one/two", false, false, null); assertNotNull(two); }
@Override public Object getObject() throws Exception { if (connectionPool == null) { // locate the repository directory String repositoryDirectoryPath = properties.getProperty(NiFiProperties.REPOSITORY_DATABASE_DIRECTORY); // ensure the repository directory is specified if (repositoryDirectoryPath == null) { throw new NullPointerException("Database directory must be specified."); } // create a handle to the repository directory File repositoryDirectory = new File(repositoryDirectoryPath); // create a handle to the database directory and file File databaseFile = new File(repositoryDirectory, AUDIT_DATABASE_FILE_NAME); String databaseUrl = getDatabaseUrl(databaseFile); // create the pool connectionPool = JdbcConnectionPool.create(databaseUrl, NF_USERNAME_PASSWORD, NF_USERNAME_PASSWORD); connectionPool.setMaxConnections(MAX_CONNECTIONS); Connection connection = null; ResultSet rs = null; Statement statement = null; try { // get a connection connection = connectionPool.getConnection(); connection.setAutoCommit(false); // create a statement for creating/updating the database statement = connection.createStatement(); // determine if the tables need to be created rs = connection.getMetaData().getTables(null, null, "USER", null); if (!rs.next()) { logger.info("Database not built for repository: " + databaseUrl + ". Building now..."); // create the tables statement.execute(CREATE_USER_TABLE); statement.execute(CREATE_AUTHORITY_TABLE); // seed the anonymous user statement.execute(INSERT_ANONYMOUS_USER); statement.execute(INSERT_ANONYMOUS_MONITOR_AUTHORITY); statement.execute(INSERT_ANONYMOUS_DFM_AUTHORITY); statement.execute(INSERT_ANONYMOUS_ADMIN_AUTHORITY); statement.execute(INSERT_ANONYMOUS_NIFI_AUTHORITY); } else { logger.info("Existing database found and connected to at: " + databaseUrl); } // close the previous result set RepositoryUtils.closeQuietly(rs); // merge in the provenance role to handle existing databases rs = statement.executeQuery(SELECT_ANONYMOUS_PROVENANCE_AUTHORITY); if (!rs.next()) { statement.execute(INSERT_ANONYMOUS_PROVENANCE_AUTHORITY); } // commit any changes connection.commit(); } catch (SQLException sqle) { RepositoryUtils.rollback(connection, logger); throw sqle; } finally { RepositoryUtils.closeQuietly(rs); RepositoryUtils.closeQuietly(statement); RepositoryUtils.closeQuietly(connection); } } return connectionPool; }