001package org.kuali.ole.docstore.model.repopojo;
002
003import java.util.*;
004
005/**
006 * Base class for nodes in docstore
007 * User: Pranitha
008 * Date: 2/28/12
009 * Time: 3:02 PM
010 * To change this template use File | Settings | File Templates.
011 */
012public class DocStoreNode {
013
014    public final String UUID = "jcr:uuid";
015    public final String PRIMARY_TYPE = "jcr:primaryType";
016    public final String NODE_TYPE = "nodeType";
017    public final String MIXIN_TYPES = "jcr:mixinTypes";
018    public final String CREATED_BY = "jcr:createdBy";
019    public final String CREATED = "jcr:created";
020    public final String MIME_TYPE = "jcr:mimeType";
021    public final String CONTENT = "jcr:data";
022    public final String FILE_NODE_COUNT = "fileNodeCount";
023    private String name;
024    private String path;
025    private Map<String, Object> propertyMap = new LinkedHashMap<String, Object>();
026
027    public Map<String, Object> getPropertyMap() {
028        return propertyMap;
029    }
030
031    public void setPropertyMap(Map<String, Object> propertyMap) {
032        this.propertyMap = propertyMap;
033    }
034
035    public String getName() {
036        return name;
037    }
038
039    public void setName(String name) {
040        this.name = name;
041    }
042
043    public String getPath() {
044        return path;
045    }
046
047    public void setPath(String path) {
048        this.path = path;
049    }
050
051    public Object getProperty(String propertyName) {
052        return propertyMap.get(propertyName);
053    }
054
055    public void setProperty(String key, Object value) {
056        if (propertyMap.containsKey(key) && !key.equalsIgnoreCase("jcr:data")) {
057            List<Object> multiValue = new ArrayList<Object>();
058            multiValue.add(propertyMap.get(key));
059            multiValue.add(value);
060            propertyMap.put(key, multiValue);
061        } else {
062            propertyMap.put(key, value);
063        }
064        setPropertyMap(propertyMap);
065    }
066
067    @Override
068    public String toString() {
069        StringBuilder sb = new StringBuilder();
070        sb.append(getPath() + "\n");
071        Map<String, Object> resultMap = (Map<String, Object>) getPropertyMap();
072        if (resultMap.size() > 0) {
073            Set<String> result = resultMap.keySet();
074            for (Iterator<String> iterator1 = result.iterator(); iterator1.hasNext(); ) {
075                String key = iterator1.next();
076                Object value = resultMap.get(key);
077                if (value instanceof List) {
078                    for (int i = 0; i < ((List) value).size(); i++) {
079                        sb.append(getPath() + "/" + key + " = " + ((List) value).get(i) + "\n");
080                    }
081                } else if (value instanceof Long) {
082                    long longValue = ((Long) value).longValue();
083                    sb.append(getPath() + "/" + key + " = " + longValue + "\n");
084                } else {
085                    value = (String) resultMap.get(key);
086                    if (getPath().equalsIgnoreCase("/")) {
087                        sb.append("/" + key + " = " + value + "\n");
088                    } else {
089                        sb.append(getPath() + "/" + key + " = " + value + "\n");
090                    }
091                }
092            }
093        }
094        return sb.toString();
095    }
096}