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;
}
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);
}
}
Aggregations