Package org.apache.archiva.metadata.repository

Examples of org.apache.archiva.metadata.repository.RepositorySession


            Map managedVersions = createManagedVersionMap( model );

            Set<Artifact> dependencyArtifacts = createArtifacts( model, null );

            RepositorySession repositorySession = repositorySessionFactory.createSession();
            try
            {
                ArtifactMetadataSource metadataSource =
                    new MetadataArtifactMetadataSource( repositoryIds, repositorySession );

                // Note that we don't permit going to external repositories. We don't need to pass in a local and remote
                // since our metadata source has control over them
                collector.collect( dependencyArtifacts, projectArtifact, managedVersions, null, null, metadataSource,
                                   null, Collections.singletonList( listener ) );

                //collector.collect( dependencyArtifacts, projectArtifact, null, Collections.<ArtifactRepository>emptyList(),
                //                   metadataSource, null,  Collections.singletonList( (ResolutionListener) listener ) );

                /*
                Set<Artifact> artifacts, Artifact originatingArtifact,
                                      ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
                                      ArtifactMetadataSource source, ArtifactFilter filter,
                                      List< ResolutionListener > listeners
                */
            }
            finally
            {
                repositorySession.close();
            }

            DependencyNode rootNode = listener.getRootNode();

            // TODO: remove the need for this when the serializer can calculate last nodes from visitor calls only
View Full Code Here


    public void setUp()
        throws Exception
    {
        setUpMockRepository();

        RepositorySession repositorySession = mock( RepositorySession.class );
        when( repositorySessionFactory.createSession() ).thenReturn( repositorySession );

        metadataRepository = mock( MetadataRepository.class );
        when( repositorySession.getRepository() ).thenReturn( metadataRepository );
    }
View Full Code Here

            throw new ArchivaRestServiceException( "repositoryId cannot be null", 400 );
        }

        // TODO more control on artifact fields

        RepositorySession repositorySession = repositorySessionFactory.createSession();
        try
        {
            Date lastUpdatedTimestamp = Calendar.getInstance().getTime();

            TimeZone timezone = TimeZone.getTimeZone( "UTC" );
            DateFormat fmt = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
            fmt.setTimeZone( timezone );
            ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository( repositoryId );

            VersionedReference ref = new VersionedReference();
            ref.setArtifactId( artifact.getArtifactId() );
            ref.setGroupId( artifact.getGroupId() );
            ref.setVersion( artifact.getVersion() );

            ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );

            if ( StringUtils.isNotBlank( artifact.getClassifier() ) )
            {
                if ( StringUtils.isBlank( artifact.getPackaging() ) )
                {
                    throw new ArchivaRestServiceException( "You must configure a type/packaging when using classifier",
                                                           400 );
                }
                ArtifactReference artifactReference = new ArtifactReference();
                artifactReference.setArtifactId( artifact.getArtifactId() );
                artifactReference.setGroupId( artifact.getGroupId() );
                artifactReference.setVersion( artifact.getVersion() );
                artifactReference.setClassifier( artifact.getClassifier() );
                artifactReference.setType( artifact.getPackaging() );
                repository.deleteArtifact( artifactReference );

                // TODO cleanup facet which contains classifier information
                return Boolean.TRUE;
            }

            String path = repository.toMetadataPath( ref );
            int index = path.lastIndexOf( '/' );
            path = path.substring( 0, index );
            File targetPath = new File( repoConfig.getLocation(), path );

            if ( !targetPath.exists() )
            {
                throw new ContentNotFoundException(
                    artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() );
            }

            // TODO: this should be in the storage mechanism so that it is all tied together
            // delete from file system
            repository.deleteVersion( ref );

            File metadataFile = getMetadata( targetPath.getAbsolutePath() );
            ArchivaRepositoryMetadata metadata = getMetadata( metadataFile );

            updateMetadata( metadata, metadataFile, lastUpdatedTimestamp, artifact );

            MetadataRepository metadataRepository = repositorySession.getRepository();

            Collection<ArtifactMetadata> artifacts =
                metadataRepository.getArtifacts( repositoryId, artifact.getGroupId(), artifact.getArtifactId(),
                                                 artifact.getVersion() );

            for ( ArtifactMetadata artifactMetadata : artifacts )
            {
                // TODO: mismatch between artifact (snapshot) version and project (base) version here
                if ( artifact.getVersion().equals( artifact.getVersion() ) )
                {
                    metadataRepository.removeArtifact( artifactMetadata.getRepositoryId(),
                                                       artifactMetadata.getNamespace(), artifactMetadata.getProject(),
                                                       artifact.getVersion(), artifactMetadata.getId() );

                    // TODO: move into the metadata repository proper - need to differentiate attachment of
                    //       repository metadata to an artifact
                    for ( RepositoryListener listener : listeners )
                    {
                        listener.deleteArtifact( metadataRepository, repository.getId(),
                                                 artifactMetadata.getNamespace(), artifactMetadata.getProject(),
                                                 artifactMetadata.getVersion(), artifactMetadata.getId() );
                    }

                    triggerAuditEvent( repositoryId, path, AuditEvent.REMOVE_FILE );
                }
            }
            repositorySession.save();
        }

        catch ( ContentNotFoundException e )
        {
            throw new ArchivaRestServiceException( "Artifact does not exist: " + e.getMessage(), 400 );
        }
        catch ( RepositoryNotFoundException e )
        {
            throw new ArchivaRestServiceException( "Target repository cannot be found: " + e.getMessage(), 400 );
        }
        catch ( RepositoryException e )
        {
            throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 400 );
        }
        catch ( MetadataResolutionException e )
        {
            throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 400 );
        }
        catch ( MetadataRepositoryException e )
        {
            throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 400 );
        }
        catch ( RepositoryAdminException e )
        {
            throw new ArchivaRestServiceException( "RepositoryAdmin exception: " + e.getMessage(), 400 );
        }
        finally

        {
            repositorySession.close();
        }
        return Boolean.TRUE;
    }
View Full Code Here

            return INPUT;
        }
        Date startDateInDF;
        Date endDateInDF;

        RepositorySession repositorySession = repositorySessionFactory.createSession();
        try
        {
            MetadataRepository metadataRepository = repositorySession.getRepository();
            if ( selectedRepositories.size() > 1 )
            {
                numPages = 1;

                try
                {
                    startDateInDF = getStartDateInDateFormat();
                    endDateInDF = getEndDateInDateFormat();
                }
                catch ( ParseException e )
                {
                    addActionError( "Error parsing date(s)." );
                    return ERROR;
                }

                if ( startDateInDF != null && endDateInDF != null && startDateInDF.after( endDateInDF ) )
                {
                    addFieldError( "startDate", "Start Date must be earlier than the End Date" );
                    return INPUT;
                }

                // multiple repos
                for ( String repo : selectedRepositories )
                {
                    List<RepositoryStatistics> stats = null;
                    try
                    {
                        stats =
                            repositoryStatisticsManager.getStatisticsInRange( metadataRepository, repo, startDateInDF,
                                                                              endDateInDF );
                    }
                    catch ( MetadataRepositoryException e )
                    {
                        log.warn( "Unable to retrieve stats, assuming is empty: " + e.getMessage(), e );
                    }
                    if ( stats == null || stats.isEmpty() )
                    {
                        log.info( "No statistics available for repository '" + repo + "'." );
                        // TODO set repo's stats to 0
                        continue;
                    }

                    repositoryStatistics.add( stats.get( 0 ) );
                }
            }
            else if ( selectedRepositories.size() == 1 )
            {
                repositoryId = selectedRepositories.get( 0 );
                try
                {
                    startDateInDF = getStartDateInDateFormat();
                    endDateInDF = getEndDateInDateFormat();

                    if ( startDateInDF != null && endDateInDF != null && startDateInDF.after( endDateInDF ) )
                    {
                        addFieldError( "startDate", "Start Date must be earlier than the End Date" );
                        return INPUT;
                    }

                    List<RepositoryStatistics> stats = null;
                    try
                    {
                        stats = repositoryStatisticsManager.getStatisticsInRange( metadataRepository, repositoryId,
                                                                                  startDateInDF, endDateInDF );
                    }
                    catch ( MetadataRepositoryException e )
                    {
                        log.warn( "Unable to retrieve stats, assuming is empty: " + e.getMessage(), e );
                    }
                    if ( stats == null || stats.isEmpty() )
                    {
                        addActionError(
                            "No statistics available for repository. Repository might not have been scanned." );
                        return ERROR;
                    }

                    int rowCount = getRowCount();
                    int extraPage = ( stats.size() % rowCount ) != 0 ? 1 : 0;
                    int totalPages = ( stats.size() / rowCount ) + extraPage;
                    numPages = totalPages;

                    int currentPage = getPage();
                    if ( currentPage > totalPages )
                    {
                        addActionError(
                            "Error encountered while generating report :: The requested page exceeds the total number of pages." );
                        return ERROR;
                    }

                    int start = rowCount * ( currentPage - 1 );
                    int end = ( start + rowCount ) - 1;

                    if ( end >= stats.size() )
                    {
                        end = stats.size() - 1;
                    }

                    repositoryStatistics = stats.subList( start, end + 1 );
                }
                catch ( ParseException pe )
                {
                    addActionError( pe.getMessage() );
                    return ERROR;
                }
            }
            else
            {
                addFieldError( "availableRepositories", "Please select a repository (or repositories) from the list." );
                return INPUT;
            }
        }
        finally
        {
            repositorySession.close();
        }

        if ( repositoryStatistics.isEmpty() )
        {
            return BLANK;
View Full Code Here

        selectedRepositories = parseSelectedRepositories();
        List<RepositoryStatistics> repositoryStatistics = new ArrayList<RepositoryStatistics>();

        StringBuilder input;
        RepositorySession repositorySession = repositorySessionFactory.createSession();
        try
        {
            MetadataRepository metadataRepository = repositorySession.getRepository();
            if ( selectedRepositories.size() > 1 )
            {
                try
                {
                    startDateInDF = getStartDateInDateFormat();
                    endDateInDF = getEndDateInDateFormat();
                }
                catch ( ParseException e )
                {
                    addActionError( "Error parsing date(s)." );
                    return ERROR;
                }

                if ( startDateInDF != null && endDateInDF != null && startDateInDF.after( endDateInDF ) )
                {
                    addFieldError( "startDate", "Start Date must be earlier than the End Date" );
                    return INPUT;
                }

                input = new StringBuilder(
                    "Repository,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,Archetypes,"
                        + "Jars,Wars\n" );

                // multiple repos
                for ( String repo : selectedRepositories )
                {
                    List<RepositoryStatistics> stats = null;
                    try
                    {
                        stats =
                            repositoryStatisticsManager.getStatisticsInRange( metadataRepository, repo, startDateInDF,
                                                                              endDateInDF );
                    }
                    catch ( MetadataRepositoryException e )
                    {
                        log.warn( "Unable to retrieve stats, assuming is empty: " + e.getMessage(), e );
                    }
                    if ( stats == null || stats.isEmpty() )
                    {
                        log.info( "No statistics available for repository '" + repo + "'." );
                        // TODO set repo's stats to 0
                        continue;
                    }

                    // only the first one
                    RepositoryStatistics repositoryStats = stats.get( 0 );
                    repositoryStatistics.add( repositoryStats );

                    input.append( repo ).append( "," );
                    input.append( repositoryStats.getTotalFileCount() ).append( "," );
                    input.append( repositoryStats.getTotalArtifactFileSize() ).append( "," );
                    input.append( repositoryStats.getTotalArtifactCount() ).append( "," );
                    input.append( repositoryStats.getTotalGroupCount() ).append( "," );
                    input.append( repositoryStats.getTotalProjectCount() ).append( "," );
                    input.append( repositoryStats.getTotalCountForType( "maven-plugin" ) ).append( "," );
                    input.append( repositoryStats.getTotalCountForType( "maven-archetype" ) ).append( "," );
                    input.append( repositoryStats.getTotalCountForType( "jar" ) ).append( "," );
                    input.append( repositoryStats.getTotalCountForType( "war" ) );
                    input.append( "\n" );
                }
            }
            else if ( selectedRepositories.size() == 1 )
            {
                repositoryId = selectedRepositories.get( 0 );
                try
                {
                    startDateInDF = getStartDateInDateFormat();
                    endDateInDF = getEndDateInDateFormat();

                    if ( startDateInDF != null && endDateInDF != null && startDateInDF.after( endDateInDF ) )
                    {
                        addFieldError( "startDate", "Start Date must be earlier than the End Date" );
                        return INPUT;
                    }

                    List<RepositoryStatistics> stats = null;
                    try
                    {
                        stats = repositoryStatisticsManager.getStatisticsInRange( metadataRepository, repositoryId,
                                                                                  startDateInDF, endDateInDF );
                    }
                    catch ( MetadataRepositoryException e )
                    {
                        log.warn( "Unable to retrieve stats, assuming is empty: " + e.getMessage(), e );
                    }
                    if ( stats == null || stats.isEmpty() )
                    {
                        addActionError(
                            "No statistics available for repository. Repository might not have been scanned." );
                        return ERROR;
                    }

                    input = new StringBuilder(
                        "Date of Scan,Total File Count,Total Size,Artifact Count,Group Count,Project Count,Plugins,"
                            + "Archetypes,Jars,Wars\n" );

                    for ( RepositoryStatistics repositoryStats : stats )
                    {
                        input.append( repositoryStats.getScanStartTime() ).append( "," );
                        input.append( repositoryStats.getTotalFileCount() ).append( "," );
                        input.append( repositoryStats.getTotalArtifactFileSize() ).append( "," );
                        input.append( repositoryStats.getTotalArtifactCount() ).append( "," );
                        input.append( repositoryStats.getTotalGroupCount() ).append( "," );
                        input.append( repositoryStats.getTotalProjectCount() ).append( "," );
                        input.append( repositoryStats.getTotalCountForType( "maven-plugin" ) ).append( "," );
                        input.append( repositoryStats.getTotalCountForType( "maven-archetype" ) ).append( "," );
                        input.append( repositoryStats.getTotalCountForType( "jar" ) ).append( "," );
                        input.append( repositoryStats.getTotalCountForType( "war" ) );
                        input.append( "\n" );
                    }

                    repositoryStatistics = stats;
                }
                catch ( ParseException pe )
                {
                    addActionError( pe.getMessage() );
                    return ERROR;
                }
            }
            else
            {
                addFieldError( "availableRepositories", "Please select a repository (or repositories) from the list." );
                return INPUT;
            }
        }
        finally
        {
            repositorySession.close();
        }

        if ( repositoryStatistics.isEmpty() )
        {
            return BLANK;
View Full Code Here

        {
            repoIds = Collections.emptyList();
        }

        List<RepositoryProblemFacet> problemArtifacts = new ArrayList<RepositoryProblemFacet>();
        RepositorySession repositorySession = repositorySessionFactory.createSession();
        try
        {
            MetadataRepository metadataRepository = repositorySession.getRepository();
            for ( String repoId : repoIds )
            {
                // TODO: improve performance by navigating into a group subtree. Currently group is property, not part of name of item
                for ( String name : metadataRepository.getMetadataFacets( repoId, RepositoryProblemFacet.FACET_ID ) )
                {
                    RepositoryProblemFacet metadataFacet =
                        (RepositoryProblemFacet) metadataRepository.getMetadataFacet( repoId,
                                                                                      RepositoryProblemFacet.FACET_ID,
                                                                                      name );

                    if ( StringUtils.isEmpty( groupId ) || groupId.equals( metadataFacet.getNamespace() ) )
                    {
                        problemArtifacts.add( metadataFacet );
                    }
                }
            }
        }
        finally
        {
            repositorySession.close();
        }

        // TODO: getting range only after reading is not efficient for a large number of artifacts
        int lowerBound = ( page - 1 ) * rowCount;
        int upperBound = ( page * rowCount ) + 1; // Add 1 to check if it's the last page or not.
View Full Code Here

        else
        {
            headerName = HEADER_RESULTS;
        }

        RepositorySession repositorySession = repositorySessionFactory.createSession();
        try
        {
            auditLogs = auditManager.getMostRecentAuditEvents( repositorySession.getRepository(), repos );
        }
        finally
        {
            repositorySession.close();
        }
    }
View Full Code Here

            {
                resource = groupIdAsPath + "/" + artifactId;
            }
        }

        RepositorySession repositorySession = repositorySessionFactory.createSession();
        try
        {
            auditLogs =
                auditManager.getAuditEventsInRange( repositorySession.getRepository(), repos, resource, startDateInDF,
                                                    endDateInDF );
        }
        finally
        {
            repositorySession.close();
        }

        headerName = HEADER_RESULTS;

        if ( auditLogs.isEmpty() )
View Full Code Here

        action.setRepositoryStatisticsManager( repositoryStatisticsManager );

        metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
        metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();

        RepositorySession repositorySession = mock( RepositorySession.class );
        when( repositorySession.getRepository() ).thenReturn( metadataRepository );

        TestRepositorySessionFactory factory =
            applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
        factory.setRepositorySession( repositorySession );
    }
View Full Code Here

            addActionError("Unable to search for a blank checksum");
            return INPUT;
        }

        databaseResults = new ArrayList<ArtifactMetadata>();
        RepositorySession repositorySession = repositorySessionFactory.createSession();
        try
        {
            MetadataRepository metadataRepository = repositorySession.getRepository();
            for ( String repoId : getObservableRepos() )
            {
                databaseResults.addAll(metadataRepository.getArtifactsByChecksum(repoId, q));
            }
        }
        finally
        {
            repositorySession.close();
        }

        if ( databaseResults.isEmpty() )
        {
            addActionError("No results found");
View Full Code Here

TOP

Related Classes of org.apache.archiva.metadata.repository.RepositorySession

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.