use of com.pspace.ifs.ksan.gw.data.DataPutObjectTagging in project ksan by infinistor.
the class PutObjectTagging method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_PUT_OBJECT_TAGGING_START);
String bucket = s3Parameter.getBucketName();
initBucketInfo(bucket);
S3Bucket s3Bucket = new S3Bucket();
s3Bucket.setCors(getBucketInfo().getCors());
s3Bucket.setAccess(getBucketInfo().getAccess());
s3Parameter.setBucket(s3Bucket);
GWUtils.checkCors(s3Parameter);
if (s3Parameter.isPublicAccess() && GWUtils.isIgnorePublicAcls(s3Parameter)) {
throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
}
checkGrantBucket(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_WRITE);
String object = s3Parameter.getObjectName();
DataPutObjectTagging dataPutObjectTagging = new DataPutObjectTagging(s3Parameter);
dataPutObjectTagging.extract();
String taggingCount = GWConstants.TAGGING_INIT;
String taggingXml = dataPutObjectTagging.getTaggingXml();
try {
Tagging tagging = new XmlMapper().readValue(taggingXml, Tagging.class);
// 중복 지우기 item이 10개 미만이기 때문에 for loop가 빠름
if (tagging != null) {
if (tagging.tagset != null && tagging.tagset.tags != null) {
for (Tag t : tagging.tagset.tags) {
// key, value 길이 체크
if (t.key.length() > GWConstants.TAG_KEY_MAX) {
throw new GWException(GWErrorCode.INVALID_TAG, s3Parameter);
}
if (t.value.length() > GWConstants.TAG_VALUE_MAX) {
throw new GWException(GWErrorCode.INVALID_TAG, s3Parameter);
}
}
}
if (tagging.tagset != null && tagging.tagset.tags != null) {
if (tagging.tagset.tags.size() > GWConstants.TAG_MAX_SIZE) {
throw new GWException(GWErrorCode.BAD_REQUEST, s3Parameter);
}
taggingCount = String.valueOf(tagging.tagset.tags.size());
}
}
} catch (IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
String versionId = dataPutObjectTagging.getVersionId();
Metadata objMeta = null;
if (Strings.isNullOrEmpty(versionId)) {
objMeta = open(bucket, object);
} else {
objMeta = open(bucket, object, versionId);
}
S3Metadata s3Metadata = null;
ObjectMapper objectMapper = new ObjectMapper();
try {
logger.debug(GWConstants.LOG_META, objMeta.getMeta());
s3Metadata = objectMapper.readValue(objMeta.getMeta(), S3Metadata.class);
} catch (JsonProcessingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
s3Metadata.setTaggingCount(taggingCount);
ObjectMapper jsonMapper = new ObjectMapper();
String jsonMeta = "";
try {
jsonMeta = jsonMapper.writeValueAsString(s3Metadata);
} catch (JsonProcessingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
objMeta.setMeta(jsonMeta);
objMeta.setTag(taggingXml);
updateObjectTagging(objMeta);
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Aggregations