1 21 package com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.persistent; 22 23 import java.util.Date ; 24 25 import com.jaspersoft.jasperserver.api.JSException; 26 import com.jaspersoft.jasperserver.api.metadata.common.domain.Folder; 27 import com.jaspersoft.jasperserver.api.metadata.common.domain.Resource; 28 import com.jaspersoft.jasperserver.api.metadata.common.domain.impl.IdedObject; 29 import com.jaspersoft.jasperserver.api.metadata.common.service.ResourceFactory; 30 import com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.PersistentObjectResolver; 31 32 33 37 public abstract class RepoResourceBase implements IdedObject { 38 39 private long id; 40 41 private int version; 42 43 private Date creationDate; 44 45 private String name = null; 46 private String label = null; 47 private String description = null; 48 49 private RepoFolder parent; 50 51 protected RepoResourceBase() { 52 version = Resource.VERSION_NEW; 53 } 54 55 59 public long getId() { 60 return id; 61 } 62 63 public void setId(long id) { 64 this.id = id; 65 } 66 67 70 public int getVersion() { 71 return version; 72 } 73 74 public void setVersion(int version) { 75 this.version = version; 76 } 77 78 82 public String getName() 83 { 84 return name; 85 } 86 87 90 public void setName(String name) 91 { 92 this.name = name; 93 } 94 95 100 public String getLabel() 101 { 102 return label; 103 } 104 105 108 public void setLabel(String label) 109 { 110 this.label = label; 111 } 112 113 118 public String getDescription() 119 { 120 return description; 121 } 122 123 126 public void setDescription(String description) 127 { 128 this.description = description; 129 } 130 131 132 136 public RepoFolder getParent() { 137 return parent; 138 } 139 140 public void setParent(RepoFolder parent) { 141 this.parent = parent; 142 } 143 144 protected abstract Class getClientItf(); 145 146 public Object toClient(ResourceFactory resourceFactory) { 147 Class clientItf = getClientItf(); 148 Resource clientRes = resourceFactory.newResource(null, clientItf); 150 return clientRes; 151 } 152 153 public void copyFromClient(Object objIdent, PersistentObjectResolver resolver){ 154 copyFrom((Resource) objIdent); 155 } 156 157 protected void copyFrom(Resource clientRes) 158 { 159 if (!isNew() && getVersion() != clientRes.getVersion()) { 160 throw new JSException(getResourceURI() + ": the client version (" + clientRes.getVersion() + ") does not match the repository version (" + getVersion() + ")."); 161 } 162 163 setName(clientRes.getName()); 164 setLabel(clientRes.getLabel()); 165 setDescription(clientRes.getDescription()); 166 } 167 168 protected void copyTo(Resource clientRes) 169 { 170 clientRes.setVersion(getVersion()); 171 clientRes.setCreationDate(getCreationDate()); 172 clientRes.setName(getName()); 173 clientRes.setLabel(getLabel()); 174 clientRes.setDescription(getDescription()); 175 176 RepoFolder parentFolder = getParent(); 177 if (parentFolder != null) { 178 clientRes.setParentFolder(parentFolder.getURI()); 179 } 180 } 181 182 public final String getResourceURI() { 183 RepoFolder parentFolder = getParent(); 184 String uri; 185 if (parentFolder == null || parentFolder.isRoot()) { 186 uri = Folder.SEPARATOR + getName(); 187 } else { 188 uri = parentFolder.getURI() + Folder.SEPARATOR + getName(); 189 } 190 return uri; 191 } 192 193 public boolean isNew() { 194 return getVersion() == Resource.VERSION_NEW; 195 } 196 197 198 202 public Date getCreationDate() { 203 return creationDate; 204 } 205 206 public void setCreationDate(Date creationDate) { 207 this.creationDate = creationDate; 208 } 209 } 210 | Popular Tags |