@Override public Object doInHibernate(Session session) throws HibernateException, XWikiException { Query q = session.createQuery("select p from " + StringListProperty.class.getName() + " as p, BaseObject as o" + " where o.className='PhenoTips.StudyClass' and p.id=o.id"); @SuppressWarnings("unchecked") List<StringListProperty> wrongProperties = q.list(); this.logger.debug("Found {} study properties of type StringListProperty", wrongProperties.size()); for (StringListProperty oldValue : wrongProperties) { DBStringListProperty newValue = new DBStringListProperty(); newValue.setId(oldValue.getId()); newValue.setName(oldValue.getName()); newValue.setValue(oldValue.getList()); session.delete(oldValue); session.save(newValue); } return null; } }
private boolean fixList(DBStringListProperty property, DBStringListProperty extendedProperty) List<String> values = property.getList(); List<String> extendedValues = null; if (extendedProperty != null) { extendedValues = extendedProperty.getList(); property.setList(values); if (extendedValues != null) { extendedValues.remove(OBESITY); extendedProperty.setList(extendedValues);
DBStringListProperty newProperty = new DBStringListProperty(); newProperty.setId(oldProperty.getId()); newProperty.setName(oldProperty.getName()); newProperty.setList(ListClass.getListFromString(oldProperty.getValue(), ",", false));
@Override public Object doInHibernate(Session session) throws HibernateException, XWikiException { Query q = session.createQuery("select p from " + StringListProperty.class.getName() + " as p, BaseObject as o" + " where o.className=? and p.id=o.id and p.name=?"); q.setString(0, this.propertyClass.getObject().getName()).setString(1, this.propertyClass.getName()); @SuppressWarnings("unchecked") List<StringListProperty> wrongProperties = q.list(); for (StringListProperty oldValue : wrongProperties) { DBStringListProperty newValue = (DBStringListProperty) this.propertyClass.newProperty(); newValue.setId(oldValue.getId()); newValue.setName(oldValue.getName()); newValue.setValue(oldValue.getList()); session.delete(oldValue); session.save(newValue); } return null; } }
@Override public Object doInHibernate(Session session) throws HibernateException, XWikiException { Query q = session.createQuery("select p from " + DBStringListProperty.class.getName() + " as p, BaseObject as o" + " where o.className='PhenoTips.StudyClass' and p.id.id=o.id" + " and 'org.phenotips.patientSheet.field.genes' in elements(p.list)"); @SuppressWarnings("unchecked") List<DBStringListProperty> properties = q.list(); this.logger.debug("Found {} studies using the old 'genes' field", properties.size()); for (DBStringListProperty property : properties) { List<String> values = property.getList(); values.set(values.indexOf("org.phenotips.patientSheet.field.genes"), "org.phenotips.patientSheet.field.gene-variants"); values.remove("org.phenotips.patientSheet.field.rejected_genes"); session.update(property); } return null; } }
public void setDBStringListValue(String name, List value) { ListProperty property = (ListProperty) safeget(name); if (property == null) { property = new DBStringListProperty(); } property.setValue(value); safeput(name, property); }
@Override public Object doInHibernate(Session session) throws HibernateException, XWikiException { Query q = session.createQuery("select p from " + StringListProperty.class.getName() + " as p, BaseObject as o" + " where o.className=? and p.id=o.id and p.name=?"); q.setString(0, this.propertyClass.getObject().getName()).setString(1, this.propertyClass.getName()); @SuppressWarnings("unchecked") List<StringListProperty> wrongProperties = q.list(); for (StringListProperty oldValue : wrongProperties) { DBStringListProperty newValue = (DBStringListProperty) this.propertyClass.newProperty(); newValue.setId(oldValue.getId()); newValue.setName(oldValue.getName()); newValue.setValue(oldValue.getList()); session.delete(oldValue); session.save(newValue); } return null; } }
@Override public Object doInHibernate(Session session) throws HibernateException, XWikiException { Query q = session.createQuery("select p from " + DBStringListProperty.class.getName() + " as p, BaseObject as o" + " where o.className='PhenoTips.StudyClass' and p.id.id=o.id" + " and 'org.phenotips.patientSheet.field.genes' in elements(p.list)"); @SuppressWarnings("unchecked") List<DBStringListProperty> properties = q.list(); this.logger.debug("Found {} studies using the old 'genes' field", properties.size()); for (DBStringListProperty property : properties) { List<String> values = property.getList(); values.set(values.indexOf("org.phenotips.patientSheet.field.genes"), "org.phenotips.patientSheet.field.gene-variants"); values.remove("org.phenotips.patientSheet.field.rejected_genes"); session.update(property); } return null; } }
@Override public BaseProperty newProperty() { BaseProperty lprop; if (isRelationalStorage() && isMultiSelect()) { lprop = new DBStringListProperty(); } else if (isMultiSelect()) { lprop = new StringListProperty(); } else { lprop = new StringProperty(); } return lprop; }
@Override public Object doInHibernate(Session session) throws HibernateException, XWikiException { Query q = session.createQuery("select p from " + StringListProperty.class.getName() + " as p, BaseObject as o" + " where o.className='PhenoTips.StudyClass' and p.id=o.id"); @SuppressWarnings("unchecked") List<StringListProperty> wrongProperties = q.list(); this.logger.debug("Found {} study properties of type StringListProperty", wrongProperties.size()); for (StringListProperty oldValue : wrongProperties) { DBStringListProperty newValue = new DBStringListProperty(); newValue.setId(oldValue.getId()); newValue.setName(oldValue.getName()); newValue.setValue(oldValue.getList()); session.delete(oldValue); session.save(newValue); } return null; } }
private boolean fixList(DBStringListProperty property, DBStringListProperty extendedProperty) List<String> values = property.getList(); List<String> extendedValues = null; if (extendedProperty != null) { extendedValues = extendedProperty.getList(); property.setList(values); if (extendedValues != null) { extendedValues.remove(OBESITY); extendedProperty.setList(extendedValues);
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientObject = doc.getXObject(Patient.CLASS_REFERENCE); if (patientObject != null) { XWikiContext context = (XWikiContext) this.execution.getContext().getProperty("xwikicontext"); for (String field : this.fieldsToFix) { DBStringListProperty currentTermList = (DBStringListProperty) patientObject.getField(field); if (currentTermList == null) { continue; } List<String> terms = currentTermList.getList(); Set<String> correctSet = new LinkedHashSet<>(); for (String term : terms) { VocabularyTerm properTerm = this.vocabularyManager.resolveTerm(term); if (properTerm != null) { correctSet.add(properTerm.getId()); } else { correctSet.add(term); } } List<String> correctList = new LinkedList<>(); correctList.addAll(correctSet); patientObject.set(field, correctList, context); } } } }
/** * Create and add the main tag property to the provided tag object. The new property corresponds to the definition * in the tag class, but in case of an error, the default type is a relational-stored list. * * @param tagObject the target tag object * @param context the current request context * @return the created property * @see #TAG_PROPERTY */ private BaseProperty createTagProperty(BaseObject tagObject, XWikiContext context) { BaseProperty tagProperty; try { BaseClass tagClass = context.getWiki().getClass(TAG_CLASS, context); PropertyClass tagPropertyDefinition = (PropertyClass) tagClass.getField(TAG_PROPERTY); tagProperty = tagPropertyDefinition.newProperty(); } catch (XWikiException ex) { LOGGER.warn("Failed to properly create tag property for the tag object, creating a default one"); tagProperty = new DBStringListProperty(); } tagProperty.setName(TAG_PROPERTY); tagProperty.setObject(tagObject); tagObject.safeput(TAG_PROPERTY, tagProperty); return tagProperty; }
for (StringProperty oldProperty : properties) { try { DBStringListProperty newProperty = new DBStringListProperty(); newProperty.setName(oldProperty.getName()); newProperty.setId(oldProperty.getId()); newProperty.setValue(newValue);
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientObject = doc.getXObject(Patient.CLASS_REFERENCE); if (patientObject != null) { XWikiContext context = (XWikiContext) this.execution.getContext().getProperty("xwikicontext"); for (String field : this.fieldsToFix) { DBStringListProperty currentTermList = (DBStringListProperty) patientObject.getField(field); if (currentTermList == null) { continue; } List<String> terms = currentTermList.getList(); Set<String> correctSet = new LinkedHashSet<>(); for (String term : terms) { VocabularyTerm properTerm = this.vocabularyManager.resolveTerm(term); if (properTerm != null) { correctSet.add(properTerm.getId()); } else { correctSet.add(term); } } List<String> correctList = new LinkedList<>(); correctList.addAll(correctSet); patientObject.set(field, correctList, context); } } } }
for (StringProperty oldProperty : properties) { try { DBStringListProperty newProperty = new DBStringListProperty(); newProperty.setName(oldProperty.getName()); newProperty.setId(oldProperty.getId()); newProperty.setValue(newValue);
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientObject = doc.getXObject(Patient.CLASS_REFERENCE); if (patientObject != null && !StringUtils.equals("PatientTemplate", doc.getDocumentReference().getName())) { XWikiContext context = (XWikiContext) this.execution.getContext().getProperty("xwikicontext"); for (String field : this.fieldsToFix) { DBStringListProperty currentTermList = (DBStringListProperty) patientObject.getField(field); if (currentTermList == null) { continue; } List<String> terms = currentTermList.getList(); Set<String> correctSet = new LinkedHashSet<String>(); for (String term : terms) { OntologyTerm properTerm = this.ontologyManager.resolveTerm(term); if (properTerm != null) { correctSet.add(properTerm.getId()); } else { correctSet.add(term); } } List<String> correctList = new LinkedList<String>(); correctList.addAll(correctSet); patientObject.set(field, correctList, context); } } } }
for (StringProperty oldProperty : properties) { try { DBStringListProperty newProperty = new DBStringListProperty(); newProperty.setName(oldProperty.getName()); newProperty.setId(oldProperty.getId()); newProperty.setValue(newValue);