Search in sources :

Example 1 with LifecycleConfiguration

use of com.pspace.ifs.ksan.gw.format.LifecycleConfiguration 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;
}
Also used : HashMap(java.util.HashMap) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) LifecycleConfiguration(com.pspace.ifs.ksan.gw.format.LifecycleConfiguration) GWException(com.pspace.ifs.ksan.gw.exception.GWException) Rule(com.pspace.ifs.ksan.gw.format.LifecycleConfiguration.Rule) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 GWException (com.pspace.ifs.ksan.gw.exception.GWException)1 LifecycleConfiguration (com.pspace.ifs.ksan.gw.format.LifecycleConfiguration)1 Rule (com.pspace.ifs.ksan.gw.format.LifecycleConfiguration.Rule)1 HashMap (java.util.HashMap)1