use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class CassandraMetadataRepository method updateProjectVersion.
@Override
public void updateProjectVersion(String repositoryId, String namespaceId, String projectId, ProjectVersionMetadata versionMetadata) throws MetadataRepositoryException {
try {
Namespace namespace = getNamespace(repositoryId, namespaceId);
if (namespace == null) {
updateOrAddNamespace(repositoryId, namespaceId);
}
if (getProject(repositoryId, namespaceId, projectId) == null) {
ProjectMetadata projectMetadata = new ProjectMetadata();
projectMetadata.setNamespace(namespaceId);
projectMetadata.setId(projectId);
updateProject(repositoryId, projectMetadata);
}
} catch (MetadataResolutionException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
QueryResult<OrderedRows<String, String, String>> result = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ss).setColumnFamily(//
cassandraArchivaManager.getProjectVersionMetadataFamilyName()).setColumnNames(//
PROJECT_VERSION.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), //
repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), //
namespaceId).addEqualsExpression(PROJECT_ID.toString(), //
projectId).addEqualsExpression(PROJECT_VERSION.toString(), //
versionMetadata.getId()).execute();
ProjectVersionMetadataModel projectVersionMetadataModel = null;
boolean creation = true;
if (result.get().getCount() > 0) {
projectVersionMetadataModel = mapProjectVersionMetadataModel(result.get().getList().get(0).getColumnSlice());
creation = false;
} else {
projectVersionMetadataModel = getModelMapper().map(versionMetadata, ProjectVersionMetadataModel.class);
}
projectVersionMetadataModel.setProjectId(projectId);
projectVersionMetadataModel.setNamespace(new Namespace(namespaceId, new Repository(repositoryId)));
projectVersionMetadataModel.setCiManagement(versionMetadata.getCiManagement());
projectVersionMetadataModel.setIssueManagement(versionMetadata.getIssueManagement());
projectVersionMetadataModel.setOrganization(versionMetadata.getOrganization());
projectVersionMetadataModel.setScm(versionMetadata.getScm());
projectVersionMetadataModel.setMailingLists(versionMetadata.getMailingLists());
projectVersionMetadataModel.setDependencies(versionMetadata.getDependencies());
projectVersionMetadataModel.setLicenses(versionMetadata.getLicenses());
// we don't test of repository and namespace really exist !
String key = //
new ProjectVersionMetadataModel.KeyBuilder().withRepository(//
repositoryId).withNamespace(//
namespaceId).withProjectId(//
projectId).withProjectVersion(//
versionMetadata.getVersion()).withId(//
versionMetadata.getId()).build();
// FIXME nested objects to store!!!
if (creation) {
String cf = cassandraArchivaManager.getProjectVersionMetadataFamilyName();
Mutator<String> mutator = projectVersionMetadataTemplate.createMutator().addInsertion(key, cf, //
column(PROJECT_ID.toString(), projectId)).addInsertion(key, cf, //
column(REPOSITORY_NAME.toString(), repositoryId)).addInsertion(key, cf, //
column(NAMESPACE_ID.toString(), namespaceId)).addInsertion(key, cf, //
column(PROJECT_VERSION.toString(), versionMetadata.getVersion()));
addInsertion(mutator, key, cf, DESCRIPTION.toString(), versionMetadata.getDescription());
addInsertion(mutator, key, cf, NAME.toString(), versionMetadata.getName());
addInsertion(mutator, key, cf, "incomplete", Boolean.toString(versionMetadata.isIncomplete()));
addInsertion(mutator, key, cf, URL.toString(), versionMetadata.getUrl());
{
CiManagement ci = versionMetadata.getCiManagement();
if (ci != null) {
addInsertion(mutator, key, cf, "ciManagement.system", ci.getSystem());
addInsertion(mutator, key, cf, "ciManagement.url", ci.getUrl());
}
}
{
IssueManagement issueManagement = versionMetadata.getIssueManagement();
if (issueManagement != null) {
addInsertion(mutator, key, cf, "issueManagement.system", issueManagement.getSystem());
addInsertion(mutator, key, cf, "issueManagement.url", issueManagement.getUrl());
}
}
{
Organization organization = versionMetadata.getOrganization();
if (organization != null) {
addInsertion(mutator, key, cf, "organization.name", organization.getName());
addInsertion(mutator, key, cf, "organization.url", organization.getUrl());
}
}
{
Scm scm = versionMetadata.getScm();
if (scm != null) {
addInsertion(mutator, key, cf, "scm.url", scm.getUrl());
addInsertion(mutator, key, cf, "scm.connection", scm.getConnection());
addInsertion(mutator, key, cf, "scm.developerConnection", scm.getDeveloperConnection());
}
}
recordMailingList(key, versionMetadata.getMailingLists());
recordLicenses(key, versionMetadata.getLicenses());
recordDependencies(key, versionMetadata.getDependencies(), repositoryId);
MutationResult mutationResult = mutator.execute();
} else {
ColumnFamilyUpdater<String, String> updater = projectVersionMetadataTemplate.createUpdater(key);
addUpdateStringValue(updater, PROJECT_ID.toString(), projectId);
addUpdateStringValue(updater, REPOSITORY_NAME.toString(), repositoryId);
addUpdateStringValue(updater, NAMESPACE_ID.toString(), namespaceId);
addUpdateStringValue(updater, PROJECT_VERSION.toString(), versionMetadata.getVersion());
addUpdateStringValue(updater, DESCRIPTION.toString(), versionMetadata.getDescription());
addUpdateStringValue(updater, NAME.toString(), versionMetadata.getName());
updater.setString("incomplete", Boolean.toString(versionMetadata.isIncomplete()));
addUpdateStringValue(updater, URL.toString(), versionMetadata.getUrl());
{
CiManagement ci = versionMetadata.getCiManagement();
if (ci != null) {
addUpdateStringValue(updater, "ciManagement.system", ci.getSystem());
addUpdateStringValue(updater, "ciManagement.url", ci.getUrl());
}
}
{
IssueManagement issueManagement = versionMetadata.getIssueManagement();
if (issueManagement != null) {
addUpdateStringValue(updater, "issueManagement.system", issueManagement.getSystem());
addUpdateStringValue(updater, "issueManagement.url", issueManagement.getUrl());
}
}
{
Organization organization = versionMetadata.getOrganization();
if (organization != null) {
addUpdateStringValue(updater, "organization.name", organization.getName());
addUpdateStringValue(updater, "organization.url", organization.getUrl());
}
}
{
Scm scm = versionMetadata.getScm();
if (scm != null) {
addUpdateStringValue(updater, "scm.url", scm.getUrl());
addUpdateStringValue(updater, "scm.connection", scm.getConnection());
addUpdateStringValue(updater, "scm.developerConnection", scm.getDeveloperConnection());
}
}
// update is a delete record
removeMailingList(key);
recordMailingList(key, versionMetadata.getMailingLists());
removeLicenses(key);
recordLicenses(key, versionMetadata.getLicenses());
removeDependencies(key);
recordDependencies(key, versionMetadata.getDependencies(), repositoryId);
projectVersionMetadataTemplate.update(updater);
}
ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
artifactMetadataModel.setRepositoryId(repositoryId);
artifactMetadataModel.setNamespace(namespaceId);
artifactMetadataModel.setProject(projectId);
artifactMetadataModel.setProjectVersion(versionMetadata.getVersion());
artifactMetadataModel.setVersion(versionMetadata.getVersion());
updateFacets(versionMetadata, artifactMetadataModel);
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class FileMetadataRepository method removeArtifact.
@Override
public void removeArtifact(String repoId, String namespace, String project, String version, String id) throws MetadataRepositoryException {
try {
Path directory = getDirectory(repoId).resolve(namespace + "/" + project + "/" + version);
Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);
properties.remove("artifact:updated:" + id);
properties.remove("artifact:whenGathered:" + id);
properties.remove("artifact:size:" + id);
properties.remove("artifact:md5:" + id);
properties.remove("artifact:sha1:" + id);
properties.remove("artifact:version:" + id);
properties.remove("artifact:facetIds:" + id);
String prefix = "artifact:facet:" + id + ":";
for (Object key : new ArrayList<>(properties.keySet())) {
String property = (String) key;
if (property.startsWith(prefix)) {
properties.remove(property);
}
}
org.apache.archiva.common.utils.FileUtils.deleteDirectory(directory);
// writeProperties( properties, directory, PROJECT_VERSION_METADATA_KEY );
} catch (IOException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class FileMetadataRepository method removeProjectVersion.
@Override
public void removeProjectVersion(String repoId, String namespace, String projectId, String projectVersion) throws MetadataRepositoryException {
try {
Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + projectVersion);
org.apache.archiva.common.utils.FileUtils.deleteDirectory(directory);
} catch (IOException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class FileMetadataRepository method hasMetadataFacet.
@Override
public boolean hasMetadataFacet(String repositoryId, String facetId) throws MetadataRepositoryException {
try {
Path directory = getMetadataDirectory(repositoryId, facetId);
if (!(Files.exists(directory) && Files.isDirectory(directory))) {
return false;
}
final String searchFile = METADATA_KEY + ".properties";
try (Stream<Path> fs = Files.walk(directory, FileVisitOption.FOLLOW_LINKS)) {
return fs.filter(Files::isDirectory).anyMatch(path -> Files.exists(path.resolve(searchFile)));
}
} catch (IOException e) {
log.error("Could not retrieve facet metatadata {}, {}: {}", repositoryId, facetId, e.getMessage(), e);
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.
the class FileMetadataRepository method removeProject.
@Override
public void removeProject(String repositoryId, String namespace, String projectId) throws MetadataRepositoryException {
try {
Path directory = getDirectory(repositoryId).resolve(namespace + "/" + projectId);
org.apache.archiva.common.utils.FileUtils.deleteDirectory(directory);
} catch (IOException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
Aggregations