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, String path, final String baseUri, final HttpServletRequest request, EventMetadata eventMetadata, final Consumer<ResponseBuilder> builderModifier) {
setContext(PACKAGE_TYPE, packageType);
setContext(PATH, path);
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);
setContext(CONTENT_ENTRY_POINT, sk.toString());
final AcceptInfo acceptInfo = jaxRsRequestHelper.findAccept(request, ApplicationContent.text_html);
final String standardAccept = ApplicationContent.getStandardAccept(acceptInfo.getBaseAccept());
Response response;
logger.debug("GET path: '{}' (RAW: '{}')\nIn store: '{}'\nUser addMetadata header is: '{}'\nStandard addMetadata header for that is: '{}'", path, request.getPathInfo(), sk, acceptInfo.getRawAccept(), standardAccept);
if (isDirectoryPath(path, request)) {
response = RequestUtils.redirectContentListing(packageType, type, name, path, request, builderModifier);
} else {
try {
logger.debug("START: retrieval of content: {}:{}", sk, path);
final Transfer item = contentController.get(sk, path, eventMetadata);
SpecialPathInfo spi = specialPathManager.getSpecialPathInfo(item, packageType);
setContext(METADATA_CONTENT, Boolean.toString(spi != null && spi.isMetadata()));
logger.debug("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()) {
logger.debug("Getting listing at: {}", path + "/");
response = RequestUtils.redirectContentListing(packageType, type, name, path, request, builderModifier);
} else {
logger.debug("RETURNING: retrieval of content: {}:{}", sk, path);
// open the stream here to prevent deletion while waiting for the transfer back to the user to start...
addFieldToActiveSpan(TRANSFER_SIZE, item.length());
InputStream in = item.openInputStream(true, eventMetadata);
final ResponseBuilder builder = Response.ok(new TransferStreamingOutput(in, metricsManager, metricsConfig));
responseHelper.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 = responseHelper.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 ContentAccessHandler method doDelete.
public Response doDelete(final String packageType, final String type, final String name, final String path, EventMetadata eventMetadata, final Consumer<ResponseBuilder> builderModifier) {
setContext(PACKAGE_TYPE, packageType);
setContext(PATH, path);
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);
setContext(CONTENT_ENTRY_POINT, sk.toString());
Response response;
try {
final ApplicationStatus result = contentController.delete(sk, path, eventMetadata);
setContext(HTTP_STATUS, String.valueOf(result.code()));
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 = responseHelper.formatResponse(e, builderModifier);
}
return response;
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class TrackedContentEntry method readExternal.
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
// This is a little awkward. The original version didn't have a version constant, so it wasn't possible
// to just read it from the data stream and use it to guide the deserialization process. Instead,
// we have to read the first object and determine whether it's the object version or the tracking key,
// which was the first field in the serialized data stream back in the first version of this class.
Object whatIsThis = in.readObject();
int version;
String packageType;
if (whatIsThis == null) {
// we see NumberFormatException: For input string: "null" in parseInt. It might be because we forget
// to persist the trackingKey for some reason. In this case, we just ignore it and continues
version = 1;
trackingKey = null;
packageType = PKG_TYPE_MAVEN;
} else if (whatIsThis instanceof TrackingKey) {
version = 1;
trackingKey = (TrackingKey) whatIsThis;
packageType = PKG_TYPE_MAVEN;
} else {
version = Integer.parseInt(String.valueOf(whatIsThis));
trackingKey = (TrackingKey) in.readObject();
packageType = (String) in.readObject();
}
// TODO: We should make future versioning / deserialization decisions based on the version we read / infer above
if (version > VERSION) {
throw new IOException("This class is of an older version: " + VERSION + " vs. the version read from the data stream: " + version + ". Cannot deserialize.");
}
final String storeKeyName = (String) in.readObject();
final StoreType storeType = StoreType.get((String) in.readObject());
final String accessChannelStr = (String) in.readObject();
accessChannel = "".equals(accessChannelStr) ? null : AccessChannel.valueOf(accessChannelStr);
if (version == 1 && accessChannel == GENERIC_PROXY) {
packageType = PKG_TYPE_GENERIC_HTTP;
}
storeKey = new StoreKey(packageType, storeType, storeKeyName);
final String pathStr = (String) in.readObject();
path = "".equals(pathStr) ? null : pathStr;
final String originUrlStr = (String) in.readObject();
originUrl = "".equals(originUrlStr) ? null : originUrlStr;
final String effectStr = (String) in.readObject();
effect = "".equals(effectStr) ? null : StoreEffect.valueOf(effectStr);
final String md5Str = (String) in.readObject();
md5 = "".equals(md5Str) ? null : md5Str;
final String sha1Str = (String) in.readObject();
sha1 = "".equals(sha1Str) ? null : sha1Str;
final String sha256Str = (String) in.readObject();
sha256 = "".equals(sha256Str) ? null : sha256Str;
size = (Long) in.readObject();
index = in.readLong();
if (version > 2) {
final Set<Long> tstamps = (Set<Long>) in.readObject();
timestamps = tstamps;
}
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class AffectedStoreRecordTest method dontRecordNullUpload.
@Test
public void dontRecordNullUpload() throws Exception {
final StoreType type = StoreType.group;
final String name = "test-group";
final AffectedStoreRecord record = new AffectedStoreRecord(new StoreKey(type, name));
record.add(null, StoreEffect.UPLOAD);
assertThat(record.getUploadedPaths(), nullValue());
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class AffectedStoreRecordTest method uniqueDownloadPaths.
@Test
public void uniqueDownloadPaths() throws Exception {
final StoreType type = StoreType.group;
final String name = "test-group";
final AffectedStoreRecord record = new AffectedStoreRecord(new StoreKey(type, name));
record.add("/path/one", StoreEffect.DOWNLOAD);
record.add("/path/one", StoreEffect.DOWNLOAD);
assertThat(record.getDownloadedPaths().size(), equalTo(1));
}
Aggregations