@Override public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { if (Patient.class.isInstance(value)) { st.setString(index, ((Patient) value).getDocument().toString()); } else { st.setNull(index, Types.VARCHAR); } }
@Override public Serializable disassemble(Object value) throws HibernateException { if (Patient.class.isInstance(value)) { return ((Patient) value).getDocument().toString(); } return null; }
/** * Returns the JSON representation of the audit event. * * @return a JSON object. */ public JSONObject toJSON() { JSONObject event = new JSONObject(); event.put("user", this.user == null ? null : this.user.getId()); event.put("ip", this.ip); event.put("action", this.action); event.put("extra", this.extra); event.put("entity", this.entity == null ? null : this.entity.toString()); event.put("time", this.time == null ? null : this.time.toInstant().toString()); return event; } }
@Override public User getCurrentUser() { DocumentReference currentUser = this.bridge.getCurrentUserReference(); if (currentUser == null) { return null; } return getUser(currentUser.toString()); }
private void setMembers(DocumentReference member, XWikiDocument doc, XWikiContext context) throws XWikiException { BaseObject memberObject = doc.newXObject(GROUP_CLASS_REFERENCE, context); memberObject.setStringValue("member", member.toString()); }
private void appentPatientXML(Patient patient, StringBuilder xmlResult) { String url = XMLUtils.escapeAttributeValue(getURL(patient)); String escapedReference = XMLUtils.escapeAttributeValue(patient.getDocumentReference().toString()); String escapedDescription = XMLUtils.escapeElementContent(getDescription(patient)); xmlResult.append("<rs id=\"").append(url).append("\" "); xmlResult.append("info=\"").append(escapedReference).append("\">"); xmlResult.append(escapedDescription); xmlResult.append("</rs>"); }
private void setMembers(DocumentReference member, XWikiDocument doc, XWikiContext context) throws XWikiException { BaseObject memberObject = doc.newXObject(GROUP_CLASS_REFERENCE, context); memberObject.setStringValue("member", member.toString()); }
private XWikiDocument getMembersGroupDocument(String wikiId) throws WikiUserManagerException { // Reference to the document DocumentReference memberGroupReference = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "XWikiAllGroup"); // Get the document try { XWikiContext xcontext = xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); return xwiki.getDocument(memberGroupReference, xcontext); } catch (XWikiException e) { throw new WikiUserManagerException(String.format("Fail to load the member group document [%s].", memberGroupReference.toString()), e); } }
private void updateOwnerRights(Map<String, BaseObject> rightsObjects, Map<String, Map<String, String>> oldRights, XWikiDocument doc) { String ownerPermissions = "view,edit,delete"; DocumentReference owner = getOwner(doc); BaseObject right = rightsObjects.get(ownerPermissions); if (owner == null) { setRights(right, USERS, "XWiki.XWikiGuest"); } else if (isUser(owner)) { setRights(right, USERS, owner.toString()); } else if (isGroup(owner)) { setRights(right, GROUPS, owner.toString()); } else { for (Map.Entry<String, String> oldOwnerRights : oldRights.get(ownerPermissions).entrySet()) { setRights(right, oldOwnerRights.getKey(), oldOwnerRights.getValue()); } } }
/** * Convert a username to an XWikiUser object, taking care of proper escapes. * * @param username the username to process * @return an XWikiUser object holding the specified username */ private XWikiUser toXWikiUser(String username, XWikiContext context) { DocumentReference ref = new DocumentReference(context.getDatabase(), XWiki.SYSTEM_SPACE, username); return new XWikiUser(ref.toString()); } }
private void setRights(DocumentReference editor, XWikiDocument doc, XWikiContext context) throws XWikiException { BaseObject rights = doc.newXObject(RIGHTS_CLASS_REFERENCE, context); rights.setIntValue("allow", 1); rights.setStringValue("levels", "edit"); rights.setLargeStringValue("groups", editor.toString()); } }
/** * Sets the reference to the family document in the patient document. * * @param patientDoc to set the family reference * @param familyDoc family of the patient * @param context context * @return true if no problems, false in case of any error/sexception */ private boolean setFamilyReference(XWikiDocument patientDoc, XWikiDocument familyDoc, XWikiContext context) { try { BaseObject pointer = patientDoc.getXObject(Family.REFERENCE_CLASS_REFERENCE, true, context); pointer.set(FAMILY_REFERENCE_FIELD, familyDoc.getDocumentReference().toString(), context); return true; } catch (Exception ex) { this.logger.error("Could not add patient [{}] to family. Error setting family reference: []", patientDoc.getId(), ex); return false; } }
private void setRights(DocumentReference editor, XWikiDocument doc, XWikiContext context) throws XWikiException { BaseObject rights = doc.newXObject(RIGHTS_CLASS_REFERENCE, context); rights.setIntValue("allow", 1); rights.setStringValue("levels", "edit"); rights.setLargeStringValue("groups", editor.toString()); } }
private void deleteOldWorkspaceObject(BaseObject oldObject, XWikiDocument oldWikiDescriptor) throws DataMigrationException { // Context, XWiki XWikiContext context = getXWikiContext(); XWiki xwiki = context.getWiki(); // Delete the old object oldWikiDescriptor.removeXObject(oldObject); // Save the document try { xwiki.saveDocument(oldWikiDescriptor, "[UPGRADE] Remove the old WorkspaceManager.WorkspaceClass object.", context); } catch (XWikiException e) { throw new DataMigrationException(String.format( "Failed to save the document [%s] to remove the WorkspaceManager.WorkspaceClass object.", oldWikiDescriptor.getDocumentReference().toString()), e); } }
/** * Create a new search result from a family and permissions. * * @param family contains the details of the family found * @param requiredPermission permission to extract the URL from */ public FamilySearchResult(Family family, String requiredPermission) { this.externalId = family.getExternalId(); this.id = family.getId(); this.reference = family.getDocumentReference().toString(); this.url = family.getURL(requiredPermission); setBasicDescription(); }
/** * Create a new search result from a family and permissions. * * @param family contains the details of the family found * @param requiredPermissions permissions to extract the URL from */ public FamilySearchResult(Family family, String requiredPermissions) { this.externalId = family.getExternalId(); this.id = family.getId(); this.reference = family.getDocumentReference().toString(); this.url = family.getURL(requiredPermissions); setBasicDescription(); }
@Override public boolean checkAccess(String action, XWikiDocument doc, XWikiContext context) throws XWikiException { DocumentReference userReference = getCurrentUser(context); User user = this.userManager.getUser(userReference != null ? userReference.toString() : null, true); boolean result = this.service.hasAccess(user, actionToRight(action), doc.getDocumentReference()); if (!result && context.getUserReference() == null && !"login".equals(context.getAction())) { this.logger.debug("Redirecting unauthenticated user to login, since it have been denied [{}] on [{}].", actionToRight(action), doc.getDocumentReference()); context.getWiki().getAuthService().showLogin(context); } return result; }
@Override public boolean checkAccess(String action, XWikiDocument doc, XWikiContext context) throws XWikiException { DocumentReference userReference = getCurrentUser(context); User user = this.userManager.getUser(userReference != null ? userReference.toString() : null, true); boolean result = this.service.hasAccess(user, actionToRight(action), doc.getDocumentReference()); if (!result && context.getUserReference() == null && !"login".equals(context.getAction())) { this.logger.debug("Redirecting unauthenticated user to login, since it have been denied [{}] on [{}].", actionToRight(action), doc.getDocumentReference()); context.getWiki().getAuthService().showLogin(context); } return result; }
private boolean setPedigreeObject(Family family, Pedigree pedigree, XWikiContext context) { if (pedigree == null) { this.logger.error("Can not set NULL pedigree for family [{}]", family.getId()); return false; } BaseObject pedigreeObject = family.getXDocument().getXObject(Pedigree.CLASS_REFERENCE); pedigreeObject.set(Pedigree.IMAGE, ((pedigree == null) ? "" : pedigree.getImage(null)), context); pedigreeObject.set(Pedigree.DATA, ((pedigree == null) ? "" : pedigree.getData().toString()), context); // update proband ID every time pedigree is changed BaseObject familyClassObject = family.getXDocument().getXObject(Family.CLASS_REFERENCE); if (familyClassObject != null) { String probandId = pedigree.getProbandId(); if (!StringUtils.isEmpty(probandId)) { Patient patient = this.patientRepository.get(probandId); familyClassObject.setStringValue("proband_id", (patient == null) ? "" : patient.getDocumentReference().toString()); } else { familyClassObject.setStringValue("proband_id", ""); } } return true; }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; XWikiContext context = (XWikiContext) this.execution.getContext().getProperty("xwikicontext"); try { if (doc.getXObject(Owner.CLASS_REFERENCE) != null) { return; } BaseObject ownerObject = doc.newXObject(Owner.CLASS_REFERENCE, context); if (doc.getCreatorReference() != null) { ownerObject.setStringValue("owner", doc.getCreatorReference().toString()); } else { ownerObject.setStringValue("owner", ""); } } catch (XWikiException ex) { this.logger.error("Failed to set the initial owner for patient [{}]: {}", doc.getDocumentReference(), ex.getMessage(), ex); } } }