Search in sources :

Example 6 with MetadataSessionException

use of org.apache.archiva.metadata.repository.MetadataSessionException in project archiva by apache.

the class DefaultManagedRepositoryAdmin method updateManagedRepository.

@Override
public Boolean updateManagedRepository(ManagedRepository managedRepository, boolean needStageRepo, AuditInformation auditInformation, boolean resetStats) throws RepositoryAdminException {
    log.debug("updateManagedConfiguration repo {} needStage {} resetStats {} ", managedRepository, needStageRepo, resetStats);
    // Ensure that the fields are valid.
    getRepositoryCommonValidator().basicValidation(managedRepository, true);
    getRepositoryCommonValidator().validateManagedRepository(managedRepository);
    ManagedRepositoryConfiguration updatedRepoConfig = getRepositoryConfiguration(managedRepository);
    updatedRepoConfig.setStageRepoNeeded(needStageRepo);
    org.apache.archiva.repository.ManagedRepository oldRepo = repositoryRegistry.getManagedRepository(managedRepository.getId());
    boolean stagingExists = false;
    if (oldRepo.supportsFeature(StagingRepositoryFeature.class)) {
        stagingExists = oldRepo.getFeature(StagingRepositoryFeature.class).getStagingRepository() != null;
    }
    boolean updateIndexContext = !StringUtils.equals(updatedRepoConfig.getIndexDir(), managedRepository.getIndexDirectory());
    org.apache.archiva.repository.ManagedRepository newRepo;
    // TODO remove content from old if path has changed !!!!!
    try {
        newRepo = repositoryRegistry.putRepository(updatedRepoConfig);
        if (newRepo.supportsFeature(StagingRepositoryFeature.class)) {
            org.apache.archiva.repository.ManagedRepository stagingRepo = newRepo.getFeature(StagingRepositoryFeature.class).getStagingRepository();
            if (stagingRepo != null && !stagingExists) {
                triggerAuditEvent(stagingRepo.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation);
                addRepositoryRoles(stagingRepo.getId());
            }
        }
    } catch (RepositoryException e) {
        log.error("Could not update repository {}: {}", managedRepository.getId(), e.getMessage(), e);
        throw new RepositoryAdminException("Could not update repository " + managedRepository.getId());
    } catch (RoleManagerException e) {
        log.error("Error during role update of stage repo {}", managedRepository.getId(), e);
        throw new RepositoryAdminException("Could not update repository " + managedRepository.getId());
    }
    triggerAuditEvent(managedRepository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO, auditInformation);
    // Save the repository configuration.
    RepositorySession repositorySession = null;
    try {
        repositorySession = getRepositorySessionFactory().createSession();
    } catch (MetadataRepositoryException e) {
        e.printStackTrace();
    }
    try {
        if (resetStats) {
            log.debug("call repositoryStatisticsManager.deleteStatistics");
            getRepositoryStatisticsManager().deleteStatistics(managedRepository.getId());
            repositorySession.save();
        }
    } catch (MetadataRepositoryException | MetadataSessionException e) {
        throw new RepositoryAdminException(e.getMessage(), e);
    } finally {
        repositorySession.close();
    }
    if (updateIndexContext) {
        try {
            repositoryRegistry.resetIndexingContext(newRepo);
        } catch (IndexUpdateFailedException e) {
            e.printStackTrace();
        }
    }
    return true;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MetadataSessionException(org.apache.archiva.metadata.repository.MetadataSessionException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException)

Example 7 with MetadataSessionException

use of org.apache.archiva.metadata.repository.MetadataSessionException in project archiva by apache.

the class JcrMetadataRepository method addMetadataFacet.

@Override
public void addMetadataFacet(RepositorySession session, String repositoryId, MetadataFacet metadataFacet) throws MetadataRepositoryException {
    final Session jcrSession = getSession(session);
    try {
        Node repo = getOrAddRepositoryNode(jcrSession, repositoryId);
        Node facets = JcrUtils.getOrAddNode(repo, "facets", FACETS_FOLDER_TYPE);
        String id = metadataFacet.getFacetId();
        Node facetNode = JcrUtils.getOrAddNode(facets, id, FACET_ID_CONTAINER_TYPE);
        if (!facetNode.hasProperty("id")) {
            facetNode.setProperty("id", id);
        }
        Node facetInstance = getOrAddNodeByPath(facetNode, metadataFacet.getName(), FACET_NODE_TYPE, true);
        if (!facetInstance.hasProperty("archiva:facetId")) {
            facetInstance.setProperty("archiva:facetId", id);
            facetInstance.setProperty("archiva:name", metadataFacet.getName());
        }
        for (Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet()) {
            facetInstance.setProperty(entry.getKey(), entry.getValue());
        }
        session.save();
    } catch (RepositoryException | MetadataSessionException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Node(javax.jcr.Node) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Map(java.util.Map) HashMap(java.util.HashMap) MetadataSessionException(org.apache.archiva.metadata.repository.MetadataSessionException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) Session(javax.jcr.Session)

Aggregations

MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)7 MetadataSessionException (org.apache.archiva.metadata.repository.MetadataSessionException)7 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)7 RepositoryException (org.apache.archiva.repository.RepositoryException)6 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)5 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)4 ItemNotFoundException (org.apache.archiva.repository.content.ItemNotFoundException)4 ArchivaItemSelector (org.apache.archiva.repository.content.base.ArchivaItemSelector)4 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)4 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)2 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)2 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)2 RoleManagerException (org.apache.archiva.redback.role.RoleManagerException)2 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)2 ContentItem (org.apache.archiva.repository.content.ContentItem)2 ContentNotFoundException (org.apache.archiva.repository.content.ContentNotFoundException)2 LayoutException (org.apache.archiva.repository.content.LayoutException)2 Version (org.apache.archiva.repository.content.Version)2 Path (java.nio.file.Path)1 DateFormat (java.text.DateFormat)1