use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class KojiMavenMetadataProvider method clearPaths.
private void clearPaths(final Set<Group> affected, final String path) {
Logger logger = LoggerFactory.getLogger(getClass());
affected.forEach(group -> {
try {
// delete so it'll be recomputed.
final Transfer target = fileManager.getTransfer(group, path);
if (target.exists()) {
logger.debug("Deleting merged file: {}", target);
target.delete(false);
if (target.exists()) {
logger.error("\n\n\n\nDID NOT DELETE merged metadata file at: {} in group: {}\n\n\n\n", path, group.getName());
}
helper.deleteChecksumsAndMergeInfo(group, path);
} else {
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(group), path);
nfc.clearMissing(resource);
}
// make sure we delete these, even if they're left over.
helper.deleteChecksumsAndMergeInfo(group, path);
} catch (final IndyWorkflowException | IOException e) {
logger.error("Failed to delete generated file (to allow re-generation on demand: {}/{}. Error: {}", e, group.getKey(), path, e.getMessage());
}
});
}
use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class KojiContentManagerDecorator method getTransfer.
@Override
public Transfer getTransfer(final ArtifactStore store, final String path, final TransferOperation operation) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("KOJI: Delegating initial getTransfer() attempt for: {}/{}", store.getKey(), path);
Transfer result = delegate.getTransfer(store, path, operation);
if (result == null && kojiUtils.isVersionSignatureAllowedWithPath(path) && TransferOperation.DOWNLOAD == operation && StoreType.group == store.getKey().getType()) {
logger.info("KOJI: Checking for Koji build matching: {}", path);
Group group = (Group) store;
RemoteRepository kojiProxy = findKojiBuildAnd(store, path, new EventMetadata(), null, this::createRemoteRepository);
if (kojiProxy != null) {
adjustTargetGroup(kojiProxy, group);
EventMetadata eventMetadata = new EventMetadata().set(ContentManager.ENTRY_POINT_STORE, store.getKey());
result = delegate.retrieve(kojiProxy, path, eventMetadata);
}
if (result != null && result.exists()) {
nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(store), path));
}
}
// Finally, pass the Transfer back.
return result;
}
use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class AbstractMergedContentGenerator method clearMergedFile.
protected void clearMergedFile(final Group group, final String path) {
try {
// delete so it'll be recomputed.
final Transfer target = fileManager.getTransfer(group, path);
if (target.exists()) {
logger.debug("Deleting merged file: {}", target);
target.delete(false);
if (target.exists()) {
logger.error("\n\n\n\nDID NOT DELETE merged metadata file at: {} in group: {}\n\n\n\n", path, group.getName());
}
helper.deleteChecksumsAndMergeInfo(group, path);
} else {
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(group), path);
nfc.clearMissing(resource);
}
// make sure we delete these, even if they're left over.
helper.deleteChecksumsAndMergeInfo(group, path);
} catch (final IndyWorkflowException | IOException e) {
logger.error("Failed to delete generated file (to allow re-generation on demand: {}/{}. Error: {}", e, group.getKey(), path, e.getMessage());
}
}
use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class DefaultContentManager method clearNFCEntries.
@Measure
protected void clearNFCEntries(final KeyedLocation kl, final String path, EventMetadata eventMetadata) {
try {
Set<Group> groups = storeManager.affectedBy(Arrays.asList(kl.getKey()), eventMetadata);
groups.stream().map((g) -> new ConcreteResource(LocationUtils.toLocation(g), path)).forEach((cr) -> nfc.clearMissing(cr));
nfc.clearMissing(new ConcreteResource(kl, path));
} catch (IndyDataException e) {
logger.error(String.format("Failed to clear NFC entries affected by upload of: %s to: %s. Reason: %s", path, kl.getKey(), e.getMessage()), e);
}
}
use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.
the class ContentController method renderListing.
/**
* @deprecated directory listing has been moved to addons/content-browse
*/
@Deprecated
public String renderListing(final String acceptHeader, final StoreKey key, final String requestPath, final String serviceUrl, final UriFormatter uriFormatter, final EventMetadata eventMetadata) throws IndyWorkflowException {
String path = requestPath;
if (path.endsWith(LISTING_HTML_FILE)) {
path = normalize(parentPath(path));
}
validatePath(key, path);
final List<StoreResource> listed = getListing(key, path, eventMetadata);
if (ApplicationContent.application_json.equals(acceptHeader)) {
final DirectoryListingDTO dto = new DirectoryListingDTO(StoreResource.convertToEntries(listed));
try {
return mapper.writeValueAsString(dto);
} catch (final JsonProcessingException e) {
throw new IndyWorkflowException("Failed to render listing to JSON: %s. Reason: %s", e, dto, e.getMessage());
}
}
final Map<String, Set<String>> listingUrls = new TreeMap<>();
final String storeUrl = uriFormatter.formatAbsolutePathTo(serviceUrl, key.getType().singularEndpointName(), key.getName());
if (listed != null) {
// second pass, process the remainder.
for (int pass = 0; pass < 2; pass++) {
for (final ConcreteResource res : listed) {
String p = res.getPath();
if (pass == 0 && !p.endsWith("/")) {
continue;
}
if (p.endsWith("-") || p.endsWith("-/")) {
// skip npm adduser path to avoid the sensitive info showing.
continue;
} else if (pass == 1) {
if (!p.endsWith("/")) {
final String dirpath = p + "/";
if (listingUrls.containsKey(normalize(storeUrl, dirpath))) {
p = dirpath;
}
} else {
continue;
}
}
final String localUrl = normalize(storeUrl, p);
Set<String> sources = listingUrls.get(localUrl);
if (sources == null) {
sources = new HashSet<>();
listingUrls.put(localUrl, sources);
}
sources.add(normalize(res.getLocationUri(), res.getPath()));
}
}
}
final List<String> sources = new ArrayList<>();
if (listed != null) {
for (final ConcreteResource res : listed) {
// KeyedLocation is all we use in Indy.
logger.debug("Formatting sources URL for: {}", res);
final KeyedLocation kl = (KeyedLocation) res.getLocation();
final String uri = uriFormatter.formatAbsolutePathTo(serviceUrl, kl.getKey().getType().singularEndpointName(), kl.getKey().getName());
if (!sources.contains(uri)) {
logger.debug("adding source URI: '{}'", uri);
sources.add(uri);
}
}
}
Collections.sort(sources);
String parentPath = normalize(parentPath(path));
if (!parentPath.endsWith("/")) {
parentPath += "/";
}
final String parentUrl;
if (parentPath.equals(path)) {
parentPath = null;
parentUrl = null;
} else {
parentUrl = uriFormatter.formatAbsolutePathTo(serviceUrl, key.getType().singularEndpointName(), key.getName(), parentPath);
}
final Map<String, Object> params = new HashMap<>();
params.put("items", listingUrls);
params.put("parentUrl", parentUrl);
params.put("parentPath", parentPath);
params.put("path", path);
params.put("storeKey", key);
params.put("storeUrl", storeUrl);
params.put("baseUrl", serviceUrl);
params.put("sources", sources);
// render...
try {
return templates.render(acceptHeader, "directory-listing", params);
} catch (final IndyGroovyException e) {
throw new IndyWorkflowException(e.getMessage(), e);
}
}
Aggregations