use of com.pspace.ifs.ksan.gw.format.LifecycleConfiguration.Rule in project ksan by infinistor.
the class DataPutBucketLifeCycle method getLifecycleXml.
public String getLifecycleXml() throws GWException {
lifecycleXml = readXml();
XmlMapper xmlMapper = new XmlMapper();
LifecycleConfiguration lcc;
try {
lcc = xmlMapper.readValue(lifecycleXml, LifecycleConfiguration.class);
} catch (JsonMappingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
} catch (JsonProcessingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
}
Map<String, String> id = new HashMap<String, String>();
if (lcc.rules != null) {
for (Rule rl : lcc.rules) {
if (rl.id != null) {
if (rl.id.length() > 255) {
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
id.put(rl.id, rl.id);
} else {
String generatedString = UUID.randomUUID().toString().substring(24).toUpperCase();
id.put(generatedString, generatedString);
rl.id = generatedString;
}
if (rl.status != null && rl.status.compareTo(GWConstants.STATUS_ENABLED) != 0 && rl.status.compareTo(GWConstants.STATUS_DISABLED) != 0) {
logger.error("rl.status : {}", rl.status);
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
}
// date check
if (rl.expiration != null) {
if (!Strings.isNullOrEmpty(rl.expiration.date)) {
if (!rl.expiration.date.contains("T00:00:00"))
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
}
}
if (lcc.rules.size() > id.size()) {
logger.error("lcc.rules.isze : {}, id.size : {}", lcc.rules.size(), id.size());
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
}
try {
xmlMapper.setSerializationInclusion(Include.NON_EMPTY);
lifecycleXml = xmlMapper.writeValueAsString(lcc);
} catch (JsonMappingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
} catch (JsonProcessingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
}
if (!lifecycleXml.contains(GWConstants.XML_VERSION)) {
lifecycleXml = GWConstants.XML_VERSION_FULL_STANDALONE + lifecycleXml;
}
return lifecycleXml;
}
Aggregations