public void ensureIntegrity() { super.ensureIntegrity(); if (!isProjectSet()) { repairMissingMaster(); return; } try { getProject(); } catch (EntityDoesNotExistException ex) { LOG.info("Repairing dead project reference"); repairDeadProjectReference(this.projectId); } }
public abstract class GWikipage extends AEntity implements ilarkesto.auth.ViewProtected<scrum.server.admin.User>, ilarkesto.search.Searchable, java.lang.Comparable<Wikipage> { // --- AEntity --- public final scrum.server.collaboration.WikipageDao getDao() { return wikipageDao; } protected void repairDeadDatob(ADatob datob) {} @Override public void storeProperties(Map properties) { super.storeProperties(properties); properties.put("projectId", this.projectId); properties.put("name", this.name); properties.put("text", this.text); } public int compareTo(Wikipage other) { return toString().toLowerCase().compareTo(other.toString().toLowerCase()); } private static final ilarkesto.core.logging.Log LOG = ilarkesto.core.logging.Log.get(GWikipage.class); public static final String TYPE = "wikipage"; // ----------------------------------------------------------- // - Searchable // ----------------------------------------------------------- public boolean matchesKey(String key) { if (super.matchesKey(key)) return true; if (matchesKey(getName(), key)) return true; if (matchesKey(getText(), key)) return true; return false; } // ----------------------------------------------------------- // - project // ----------------------------------------------------------- private String projectId; private transient scrum.server.project.Project projectCache; private void updateProjectCache() { projectCache = this.projectId == null ? null : (scrum.server.project.Project) projectDao.getById(this.projectId); } public final String getProjectId() { return this.projectId; } public final scrum.server.project.Project getProject() { if (projectCache == null) updateProjectCache(); return projectCache; } public final void setProject(scrum.server.project.Project project) { project = prepareProject(project); if (isProject(project)) return; this.projectId = project == null ? null : project.getId(); projectCache = project; updateLastModified(); fireModified("project=" + project); } protected scrum.server.project.Project prepareProject(scrum.server.project.Project project) { return project; } protected void repairDeadProjectReference(String entityId) { if (this.projectId == null || entityId.equals(this.projectId)) { repairMissingMaster(); } } public final boolean isProjectSet() { return this.projectId != null; } public final boolean isProject(scrum.server.project.Project project) { if (this.projectId == null && project == null) return true; return project != null && project.getId().equals(this.projectId); } protected final void updateProject(Object value) { setProject( value == null ? null : (scrum.server.project.Project) projectDao.getById((String) value)); } // ----------------------------------------------------------- // - name // ----------------------------------------------------------- private java.lang.String name; public final java.lang.String getName() { return name; } public final void setName(java.lang.String name) { name = prepareName(name); if (isName(name)) return; this.name = name; updateLastModified(); fireModified("name=" + name); } protected java.lang.String prepareName(java.lang.String name) { name = Str.removeUnreadableChars(name); return name; } public final boolean isNameSet() { return this.name != null; } public final boolean isName(java.lang.String name) { if (this.name == null && name == null) return true; return this.name != null && this.name.equals(name); } protected final void updateName(Object value) { setName((java.lang.String) value); } // ----------------------------------------------------------- // - text // ----------------------------------------------------------- private java.lang.String text; public final java.lang.String getText() { return text; } public final void setText(java.lang.String text) { text = prepareText(text); if (isText(text)) return; this.text = text; updateLastModified(); fireModified("text=" + text); } protected java.lang.String prepareText(java.lang.String text) { text = Str.removeUnreadableChars(text); return text; } public final boolean isTextSet() { return this.text != null; } public final boolean isText(java.lang.String text) { if (this.text == null && text == null) return true; return this.text != null && this.text.equals(text); } protected final void updateText(Object value) { setText((java.lang.String) value); } public void updateProperties(Map<?, ?> properties) { for (Map.Entry entry : properties.entrySet()) { String property = (String) entry.getKey(); if (property.equals("id")) continue; Object value = entry.getValue(); if (property.equals("projectId")) updateProject(value); if (property.equals("name")) updateName(value); if (property.equals("text")) updateText(value); } } protected void repairDeadReferences(String entityId) { super.repairDeadReferences(entityId); repairDeadProjectReference(entityId); } // --- ensure integrity --- public void ensureIntegrity() { super.ensureIntegrity(); if (!isProjectSet()) { repairMissingMaster(); return; } try { getProject(); } catch (EntityDoesNotExistException ex) { LOG.info("Repairing dead project reference"); repairDeadProjectReference(this.projectId); } } // ----------------------------------------------------------- // - dependencies // ----------------------------------------------------------- static scrum.server.project.ProjectDao projectDao; public static final void setProjectDao(scrum.server.project.ProjectDao projectDao) { GWikipage.projectDao = projectDao; } static scrum.server.collaboration.WikipageDao wikipageDao; public static final void setWikipageDao(scrum.server.collaboration.WikipageDao wikipageDao) { GWikipage.wikipageDao = wikipageDao; } }