1 31 32 package org.opencms.file; 33 34 import org.opencms.main.CmsIllegalArgumentException; 35 import org.opencms.util.CmsStringUtil; 36 import org.opencms.util.CmsUUID; 37 38 import java.sql.ResultSet ; 39 import java.sql.SQLException ; 40 import java.util.List ; 41 42 53 public class CmsProject implements Cloneable , Comparable { 54 55 56 public static final int ONLINE_PROJECT_ID = 1; 57 58 59 public static final String ONLINE_PROJECT_NAME = "Online"; 60 61 62 public static final int PROJECT_STATE_INVISIBLE = 3; 63 64 65 public static final int PROJECT_STATE_UNLOCKED = 0; 66 67 68 public static final int PROJECT_TYPE_NORMAL = 0; 69 70 71 public static final int PROJECT_TYPE_TEMPORARY = 1; 72 73 74 private long m_dateCreated; 75 76 77 private String m_description; 78 79 80 private int m_flags; 81 82 83 private CmsUUID m_groupManagersId; 84 85 86 private CmsUUID m_groupUsersId; 87 88 89 private int m_id; 90 91 92 private String m_name; 93 94 95 private CmsUUID m_ownerId; 96 97 98 private int m_taskId; 99 100 101 private int m_type; 102 103 106 public CmsProject() { 107 108 } 110 111 125 public CmsProject( 126 int projectId, 127 String name, 128 String description, 129 int taskId, 130 CmsUUID ownerId, 131 CmsUUID groupId, 132 CmsUUID managerGroupId, 133 int flags, 134 long dateCreated, 135 int type) { 136 137 m_id = projectId; 138 m_name = name; 139 m_description = description; 140 m_taskId = taskId; 141 m_ownerId = ownerId; 142 m_groupUsersId = groupId; 143 m_groupManagersId = managerGroupId; 144 m_flags = flags; 145 m_type = type; 146 m_dateCreated = dateCreated; 147 } 148 149 156 public CmsProject(ResultSet res, org.opencms.db.generic.CmsSqlManager sqlManager) 157 throws SQLException { 158 159 this( 160 res.getInt(sqlManager.readQuery("C_PROJECTS_PROJECT_ID")), 161 res.getString(sqlManager.readQuery("C_PROJECTS_PROJECT_NAME")), 162 res.getString(sqlManager.readQuery("C_PROJECTS_PROJECT_DESCRIPTION")), 163 res.getInt(sqlManager.readQuery("C_PROJECTS_TASK_ID")), 164 new CmsUUID(res.getString(sqlManager.readQuery("C_PROJECTS_USER_ID"))), 165 new CmsUUID(res.getString(sqlManager.readQuery("C_PROJECTS_GROUP_ID"))), 166 new CmsUUID(res.getString(sqlManager.readQuery("C_PROJECTS_MANAGERGROUP_ID"))), 167 res.getInt(sqlManager.readQuery("C_PROJECTS_PROJECT_FLAGS")), 168 res.getLong(sqlManager.readQuery("C_PROJECTS_DATE_CREATED")), 169 res.getInt(sqlManager.readQuery("C_PROJECTS_PROJECT_TYPE"))); 170 } 171 172 180 public static boolean isInsideProject(List projectResources, CmsResource resource) { 181 182 String resourcename = resource.getRootPath(); 183 return isInsideProject(projectResources, resourcename); 184 } 185 186 194 public static boolean isInsideProject(List projectResources, String resourcename) { 195 196 for (int i = (projectResources.size() - 1); i >= 0; i--) { 197 String projectResource = (String )projectResources.get(i); 198 if (CmsResource.isFolder(projectResource)) { 199 if (resourcename.startsWith(projectResource)) { 200 return true; 202 } 203 } else { 204 if (resourcename.equals(projectResource)) { 205 return true; 207 } 208 } 209 } 210 return false; 211 } 212 213 219 public static boolean isOnlineProject(int projectId) { 220 221 return projectId == CmsProject.ONLINE_PROJECT_ID; 222 } 223 224 229 public Object clone() { 230 231 return new CmsProject( 232 m_id, 233 m_name, 234 m_description, 235 m_taskId, 236 m_ownerId, 237 m_groupUsersId, 238 m_groupManagersId, 239 m_flags, 240 m_dateCreated, 241 m_type); 242 } 243 244 250 public int compareTo(Object o) { 251 252 if (o == this) { 253 return 0; 254 } 255 256 if (o instanceof CmsProject) { 257 try { 258 return m_name.compareTo(((CmsProject)o).getName()); 260 } catch (Exception e) { 261 } 263 } 264 return 0; 265 } 266 267 270 public boolean equals(Object obj) { 271 272 if (obj == this) { 273 return true; 274 } 275 if (obj instanceof CmsProject) { 276 return ((CmsProject)obj).m_id == m_id; 277 } 278 return false; 279 } 280 281 286 public long getDateCreated() { 287 288 return m_dateCreated; 289 } 290 291 296 public String getDescription() { 297 298 return m_description; 299 } 300 301 306 public int getFlags() { 307 308 return m_flags; 309 } 310 311 316 public CmsUUID getGroupId() { 317 318 return m_groupUsersId; 319 } 320 321 326 public int getId() { 327 328 return m_id; 329 } 330 331 336 public CmsUUID getManagerGroupId() { 337 338 return m_groupManagersId; 339 } 340 341 346 public String getName() { 347 348 return m_name; 349 } 350 351 356 public CmsUUID getOwnerId() { 357 358 return m_ownerId; 359 } 360 361 366 public int getTaskId() { 367 368 return m_taskId; 369 } 370 371 376 public int getType() { 377 378 return m_type; 379 } 380 381 384 public int hashCode() { 385 386 if (m_name != null) { 387 return m_name.hashCode(); 388 } 389 return 0; 390 } 391 392 399 public boolean isDeleteAfterPublishing() { 400 401 return m_type == CmsProject.PROJECT_TYPE_TEMPORARY; 402 } 403 404 409 public boolean isOnlineProject() { 410 411 return isOnlineProject(m_id); 412 } 413 414 419 public void setDeleteAfterPublishing(boolean deleteAfterPublishing) { 420 421 m_type = deleteAfterPublishing ? CmsProject.PROJECT_TYPE_TEMPORARY : CmsProject.PROJECT_TYPE_NORMAL; 422 } 423 424 429 public void setDescription(String description) { 430 431 m_description = description; 432 } 433 434 439 public void setFlags(int flags) { 440 441 m_flags = flags; 442 } 443 444 449 public void setGroupId(CmsUUID id) { 450 451 CmsUUID.checkId(id, false); 452 m_groupUsersId = id; 453 } 454 455 460 public void setManagerGroupId(CmsUUID id) { 461 462 CmsUUID.checkId(id, false); 463 m_groupManagersId = id; 464 } 465 466 471 public void setName(String name) { 472 473 if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) { 474 throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_PROJECTNAME_VALIDATION_0)); 475 } 476 m_name = name; 477 } 478 479 482 public String toString() { 483 484 StringBuffer result = new StringBuffer (); 485 result.append("[Project]:"); 486 result.append(m_name); 487 result.append(" , Id="); 488 result.append(m_id); 489 result.append(" :"); 490 result.append(m_description); 491 return result.toString(); 492 } 493 494 499 void setType(int id) { 500 501 m_type = id; 502 } 503 } 504 | Popular Tags |