package com.dtolabs.rundeck.core.storage;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Mutable set of rundeck resource metadata.
 */
public class ResourceMetaBuilder implements CanSetResourceMeta, HasResourceMeta {
    Map<String, String> meta;

    public ResourceMetaBuilder(Map<String, String> meta) {
        if (null != meta) {
            this.meta = meta;
        }
    }

    public ResourceMetaBuilder() {
        this(new HashMap<String, String>());
    }

    @Override
    public void setMeta(Map<String, String> meta) {
        this.meta = meta;
    }

    @Override
    public void setMeta(String key, String value) {
        meta.put(key, value);
    }

    @Override
    public void setContentType(String value) {
        setMeta(ResourceUtil.RES_META_RUNDECK_CONTENT_TYPE, value);
    }

    @Override
    public void setContentLength(long length) {
        setMeta(ResourceUtil.RES_META_RUNDECK_CONTENT_LENGTH, Long.toString(length));
    }

    @Override
    public void setModificationTime(Date time) {
        setMeta(ResourceUtil.RES_META_RUNDECK_CONTENT_MODIFY_TIME, ResourceUtil.formatDate(time));
    }

    @Override
    public void setCreationTime(Date time) {
        setMeta(ResourceUtil.RES_META_RUNDECK_CONTENT_CREATION_TIME, ResourceUtil.formatDate(time));
    }

    @Override
    public Map<String,String> getResourceMeta() {
        return meta;
    }
}

@@ -825,32 +825,158 @@
  value);%0A    %7D%0A%0A
+    public String getContentType() %7B%0A        return getResourceMeta().get(ResourceUtil.RES_META_RUNDECK_CONTENT_TYPE);%0A    %7D%0A%0A
     @Override%0A  
@@ -1106,32 +1106,176 @@
 ength));%0A    %7D%0A%0A
+    public long getContentLength() %7B%0A        return Long.parseLong(getResourceMeta().get(ResourceUtil.RES_META_RUNDECK_CONTENT_LENGTH));%0A    %7D%0A%0A
     @Override%0A  
@@ -1435,162 +1435,656 @@
     
-@Override%0A    public void setCreationTime(Date time) %7B%0A        setMeta(ResourceUtil.RES_META_RUNDECK_CONTENT_CREATION_TIME, ResourceUtil.formatDate(time))
+public Date getModificationTime() %7B%0A        String s = getResourceMeta().get(ResourceUtil.RES_META_RUNDECK_CONTENT_MODIFY_TIME);%0A        if (null != s) %7B%0A            return ResourceUtil.parseDate(s, null);%0A        %7D%0A        return null;%0A    %7D%0A%0A    @Override%0A    public void setCreationTime(Date time) %7B%0A        setMeta(ResourceUtil.RES_META_RUNDECK_CONTENT_CREATION_TIME, ResourceUtil.formatDate(time));%0A    %7D%0A%0A    public Date getCreationTime() %7B%0A        String s = getResourceMeta().get(ResourceUtil.RES_META_RUNDECK_CONTENT_CREATION_TIME);%0A        if (null != s) %7B%0A            return ResourceUtil.parseDate(s, null);%0A        %7D%0A        return null
 ;%0A  
@@ -2124,16 +2124,17 @@
 %3CString,
+ 
 String%3E 

Allow read access to known metadata values