use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class ContentAccessHandler method doDelete.
public Response doDelete(final String packageType, final String type, final String name, final String path, EventMetadata eventMetadata, final Consumer<ResponseBuilder> builderModifier) {
if (!PackageTypes.contains(packageType)) {
ResponseBuilder builder = Response.status(400);
if (builderModifier != null) {
builderModifier.accept(builder);
}
return builder.build();
}
final StoreType st = StoreType.get(type);
StoreKey sk = new StoreKey(packageType, st, name);
eventMetadata = eventMetadata.set(ContentManager.ENTRY_POINT_STORE, sk);
Response response;
try {
final ApplicationStatus result = contentController.delete(st, name, path, eventMetadata);
ResponseBuilder builder = Response.status(result.code());
if (builderModifier != null) {
builderModifier.accept(builder);
}
response = builder.build();
} catch (final IndyWorkflowException e) {
logger.error(String.format("Failed to tryDelete artifact: %s from: %s. Reason: %s", path, name, e.getMessage()), e);
response = formatResponse(e, builderModifier);
}
return response;
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class ContentAccessHandler method doGet.
public Response doGet(final String packageType, final String type, final String name, final String path, final String baseUri, final HttpServletRequest request, EventMetadata eventMetadata, final Consumer<ResponseBuilder> builderModifier) {
if (!PackageTypes.contains(packageType)) {
ResponseBuilder builder = Response.status(400);
if (builderModifier != null) {
builderModifier.accept(builder);
}
return builder.build();
}
final StoreType st = StoreType.get(type);
final StoreKey sk = new StoreKey(packageType, st, name);
eventMetadata = eventMetadata.set(ContentManager.ENTRY_POINT_STORE, sk);
final AcceptInfo acceptInfo = jaxRsRequestHelper.findAccept(request, ApplicationContent.text_html);
final String standardAccept = ApplicationContent.getStandardAccept(acceptInfo.getBaseAccept());
Response response = null;
logger.info("GET path: '{}' (RAW: '{}')\nIn store: '{}'\nUser addMetadata header is: '{}'\nStandard addMetadata header for that is: '{}'", path, request.getPathInfo(), sk, acceptInfo.getRawAccept(), standardAccept);
if (path == null || path.equals("") || request.getPathInfo().endsWith("/") || path.endsWith(LISTING_HTML_FILE)) {
try {
logger.info("Getting listing at: {}", path);
final String content = contentController.renderListing(standardAccept, st, name, path, baseUri, uriFormatter);
response = formatOkResponseWithEntity(content, acceptInfo.getRawAccept(), builderModifier);
} catch (final IndyWorkflowException e) {
logger.error(String.format("Failed to render content listing: %s from: %s. Reason: %s", path, name, e.getMessage()), e);
response = formatResponse(e, builderModifier);
}
} else {
try {
logger.info("START: retrieval of content: {}:{}", sk, path);
final Transfer item = contentController.get(sk, path, eventMetadata);
logger.info("HANDLE: retrieval of content: {}:{}", sk, path);
if (item == null) {
return handleMissingContentQuery(sk, path, builderModifier);
}
boolean handleLocking = false;
if (!item.isWriteLocked()) {
item.lockWrite();
handleLocking = true;
}
try {
if (!item.exists()) {
return handleMissingContentQuery(sk, path, builderModifier);
} else if (item.isDirectory()) {
try {
logger.info("Getting listing at: {}", path + "/");
final String content = contentController.renderListing(standardAccept, st, name, path + "/", baseUri, uriFormatter);
response = formatOkResponseWithEntity(content, acceptInfo.getRawAccept(), builderModifier);
} catch (final IndyWorkflowException e) {
logger.error(String.format("Failed to render content listing: %s from: %s. Reason: %s", path, name, e.getMessage()), e);
response = formatResponse(e, builderModifier);
}
} else {
logger.info("RETURNING: retrieval of content: {}:{}", sk, path);
// open the stream here to prevent deletion while waiting for the transfer back to the user to start...
InputStream in = item.openInputStream(true, eventMetadata);
final ResponseBuilder builder = Response.ok(new TransferStreamingOutput(in));
setInfoHeaders(builder, item, sk, path, true, contentController.getContentType(path), contentController.getHttpMetadata(item));
if (builderModifier != null) {
builderModifier.accept(builder);
}
response = builder.build();
}
} finally {
if (handleLocking) {
item.unlock();
}
}
} catch (final IOException | IndyWorkflowException e) {
logger.error(String.format("Failed to download artifact: %s from: %s. Reason: %s", path, name, e.getMessage()), e);
response = formatResponse(e, builderModifier);
}
}
logger.info("RETURNING RESULT: {}:{}", sk, path);
return response;
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class LocationUtils method toLocation.
public static KeyedLocation toLocation(final ArtifactStore store) {
if (store == null) {
return null;
}
final StoreType type = store.getKey().getType();
KeyedLocation location = null;
switch(type) {
case group:
{
location = new GroupLocation(store.getName());
break;
}
case hosted:
{
location = new CacheOnlyLocation((HostedRepository) store);
break;
}
case remote:
default:
{
final RemoteRepository repository = (RemoteRepository) store;
location = new RepositoryLocation(repository);
AttributePasswordManager.bind(location, PasswordEntry.KEY_PASSWORD, repository.getKeyPassword());
AttributePasswordManager.bind(location, PasswordEntry.PROXY_PASSWORD, repository.getProxyPassword());
AttributePasswordManager.bind(location, PasswordEntry.USER_PASSWORD, repository.getPassword());
// FIXME: Make this configurable on the RemoteRepository!
location.setAttribute(Location.MAX_CONNECTIONS, 30);
}
}
if (location != null) {
location.setAttribute(PATH_STYLE, store.getPathStyle());
Map<String, String> metadata = store.getMetadata();
if (metadata != null) {
Location loc = location;
metadata.forEach((k, v) -> {
if (!loc.getAttributes().containsKey(k)) {
loc.setAttribute(k, v);
}
});
}
}
return location;
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class MemoryArtifactStoreQuery method recurseGroup.
private void recurseGroup(final Group master, final Map<StoreKey, ArtifactStore> stores, final List<ArtifactStore> result, final Set<StoreKey> seen, final boolean includeGroups, final boolean recurseGroups) {
if (master == null || master.isDisabled() && enabled) {
return;
}
List<StoreKey> members = new ArrayList<>(master.getConstituents());
if (includeGroups) {
result.add(master);
}
members.forEach((key) -> {
if (!seen.contains(key)) {
seen.add(key);
final StoreType type = key.getType();
if (recurseGroups && type == StoreType.group) {
// if we're here, we're definitely recursing groups...
recurseGroup((Group) stores.get(key), stores, result, seen, includeGroups, true);
} else {
final ArtifactStore store = stores.get(key);
if (store != null && !(store.isDisabled() && enabled)) {
result.add(store);
}
}
}
});
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class IndexingContentManagerDecorator method getTransfer.
@Override
public Transfer getTransfer(final StoreKey storeKey, final String path, final TransferOperation op) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
Transfer transfer = getIndexedTransfer(storeKey, null, path, TransferOperation.DOWNLOAD);
if (transfer != null) {
logger.debug("Returning indexed transfer: {}", transfer);
return transfer;
}
ArtifactStore store;
try {
store = storeDataManager.getArtifactStore(storeKey);
} catch (IndyDataException e) {
throw new IndyWorkflowException("Failed to lookup ArtifactStore: %s for NFC handling. Reason: %s", e, storeKey, e.getMessage());
}
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
StoreType type = storeKey.getType();
if (StoreType.group == type) {
Group g = (Group) store;
if (g == null) {
throw new IndyWorkflowException("Cannot find requested group: %s", storeKey);
}
if (nfc.isMissing(resource)) {
logger.debug("NFC / MISSING: {}", resource);
return null;
}
logger.debug("No group index hits. Devolving to member store indexes.");
for (StoreKey key : g.getConstituents()) {
transfer = getIndexedMemberTransfer((Group) store, path, op, (member) -> {
try {
return delegate.getTransfer(member, path, op);
} catch (IndyWorkflowException e) {
logger.error(String.format("Failed to getTransfer() for member path: %s:%s with operation: %s. Reason: %s", member.getKey(), path, op, e.getMessage()), e);
}
return null;
});
if (transfer != null) {
logger.debug("Returning indexed transfer: {} from member: {}", transfer, key);
return transfer;
}
}
}
transfer = delegate.getTransfer(storeKey, path, op);
if (transfer != null) {
logger.debug("Indexing transfer: {}", transfer);
indexManager.indexTransferIn(transfer, storeKey);
}
return transfer;
}
Aggregations