Skip to content
Snippets Groups Projects
Commit 20bfa4f0 authored by srosse's avatar srosse
Browse files

OO-4061: allow longer note

parent df4ff078
No related branches found
No related tags found
No related merge requests found
...@@ -58,6 +58,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -58,6 +58,8 @@ import org.springframework.beans.factory.annotation.Autowired;
* *
*/ */
public class NoteController extends FormBasicController implements GenericEventListener { public class NoteController extends FormBasicController implements GenericEventListener {
private static final int NOTE_MAX_LENGTH = 400000;
private Note n; private Note n;
private EventBus sec; private EventBus sec;
...@@ -129,7 +131,7 @@ public class NoteController extends FormBasicController implements GenericEventL ...@@ -129,7 +131,7 @@ public class NoteController extends FormBasicController implements GenericEventL
noteField = uifactory.addRichTextElementForStringData("noteField", null, n.getNoteText(), 20, -1, false, null, null, formLayout, ureq.getUserSession(), getWindowControl()); noteField = uifactory.addRichTextElementForStringData("noteField", null, n.getNoteText(), 20, -1, false, null, null, formLayout, ureq.getUserSession(), getWindowControl());
noteField.setEnabled(false); noteField.setEnabled(false);
noteField.setMaxLength(4000); noteField.setMaxLength(NOTE_MAX_LENGTH);
submitButton = uifactory.addFormSubmitButton("submit", formLayout); submitButton = uifactory.addFormSubmitButton("submit", formLayout);
submitButton.setVisible(false); submitButton.setVisible(false);
...@@ -147,18 +149,12 @@ public class NoteController extends FormBasicController implements GenericEventL ...@@ -147,18 +149,12 @@ public class NoteController extends FormBasicController implements GenericEventL
} }
} }
/**
* @see org.olat.core.gui.control.DefaultController#doDispose(boolean)
*/
@Override @Override
protected void doDispose() { protected void doDispose() {
sec.deregisterFor(this, OresHelper.lookupType(Note.class)); sec.deregisterFor(this, OresHelper.lookupType(Note.class));
} }
/** @Override
*
* @see org.olat.core.util.event.GenericEventListener#event(org.olat.core.gui.control.Event)
*/
public void event(Event event) { public void event(Event event) {
if (event instanceof OLATResourceableJustBeforeDeletedEvent) { if (event instanceof OLATResourceableJustBeforeDeletedEvent) {
OLATResourceableJustBeforeDeletedEvent bdev = (OLATResourceableJustBeforeDeletedEvent) event; OLATResourceableJustBeforeDeletedEvent bdev = (OLATResourceableJustBeforeDeletedEvent) event;
...@@ -173,15 +169,16 @@ public class NoteController extends FormBasicController implements GenericEventL ...@@ -173,15 +169,16 @@ public class NoteController extends FormBasicController implements GenericEventL
@Override @Override
protected boolean validateFormLogic(UserRequest ureq) { protected boolean validateFormLogic(UserRequest ureq) {
boolean allOk = super.validateFormLogic(ureq);
String text = noteField.getValue(); String text = noteField.getValue();
boolean allOk = true; noteField.clearError();
if(text.length() <= 4000) { if(text.length() > NOTE_MAX_LENGTH) {
noteField.clearError(); noteField.setErrorKey("input.toolong", new String[]{ Integer.toString(NOTE_MAX_LENGTH) });
} else { allOk &= false;
noteField.setErrorKey("input.toolong", new String[]{"4000"});
allOk = false;
} }
return allOk && super.validateFormLogic(ureq);
return allOk;
} }
@Override @Override
...@@ -197,17 +194,10 @@ public class NoteController extends FormBasicController implements GenericEventL ...@@ -197,17 +194,10 @@ public class NoteController extends FormBasicController implements GenericEventL
noteField.setEnabled(false); noteField.setEnabled(false);
} }
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formInnerEvent(org.olat.core.gui.UserRequest,
* org.olat.core.gui.components.form.flexible.FormItem,
* org.olat.core.gui.components.form.flexible.impl.FormEvent)
*/
@Override @Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) { protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
// persisting: see formOK
// If the user clicked the edit button, set the rich text input field to enabled and hide the edit button. // If the user clicked the edit button, set the rich text input field to enabled and hide the edit button.
if ((source == editButton) && (editButton.isEnabled())) { if (source == editButton && editButton.isEnabled()) {
noteField.setEnabled(true); noteField.setEnabled(true);
editButton.setVisible(false); editButton.setVisible(false);
submitButton.setVisible(true); submitButton.setVisible(true);
......
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<!-- Can't name the class user, clashes with postgres database -->
<class name="org.olat.note.NoteImpl" table="o_note">
<id name="key" column="note_id" type="long" unsaved-value="null">
<generator class="enhanced-sequence">
<param name="sequence_name">hibernate_unique_key</param>
<param name="force_table_use">true</param>
<param name="optimizer">legacy-hilo</param>
<param name="value_column">next_hi</param>
<param name="increment_size">32767</param>
<param name="initial_value">32767</param>
</generator>
</id>
<version name="version" access="field" column="version" type="int"/>
<property name="lastModified" column="lastmodified" type="timestamp" />
<property name="creationDate" column="creationdate" type="timestamp" />
<many-to-one name="owner" class="org.olat.basesecurity.IdentityImpl" outer-join="auto" cascade="none">
<column name="owner_id" not-null="false" index="owner_idx"/>
</many-to-one>
<property name="resourceTypeName" type="string">
<column name="resourcetypename" length="50" not-null="true" index="restype_idx0"/>
</property>
<property name="resourceTypeId" type="long">
<column name="resourcetypeid" not-null="true" index="resid_idx2"/>
</property>
<property name="subtype" column="sub_type" unique="false" type="string" not-null="false" length="50"/>
<property name="noteTitle" column="notetitle" unique="false" type="string" not-null="false" length="255"/>
<property name="noteText" unique="false" type="string" not-null="false">
<column name="notetext" length="16777210"/>
</property>
</class>
</hibernate-mapping>
...@@ -27,8 +27,25 @@ package org.olat.note; ...@@ -27,8 +27,25 @@ package org.olat.note;
import java.util.Date; import java.util.Date;
import org.olat.core.commons.persistence.PersistentObject; import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.olat.basesecurity.IdentityImpl;
import org.olat.core.id.CreateInfo;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
import org.olat.core.id.Persistable;
import org.olat.core.logging.AssertException; import org.olat.core.logging.AssertException;
/** /**
...@@ -37,19 +54,55 @@ import org.olat.core.logging.AssertException; ...@@ -37,19 +54,55 @@ import org.olat.core.logging.AssertException;
* *
* @author Alexander Schneider * @author Alexander Schneider
*/ */
public class NoteImpl extends PersistentObject implements Note { @Entity(name="note")
@Table(name="o_note")
@NamedQueries({
@NamedQuery(name="noteByOwner", query="select n from note as n inner join fetch n.owner as noteowner where noteowner.key=:noteowner"),
@NamedQuery(name="noteByOwnerAndResource", query="select n from note as n where n.owner.key=:ownerKey and n.resourceTypeName=:resName and n.resourceTypeId=:resId")
})
public class NoteImpl implements Note, Persistable, CreateInfo {
private static final long serialVersionUID = -403450817851666464L; private static final long serialVersionUID = -403450817851666464L;
private static final int RESOURCETYPENAME_MAXLENGTH = 50;
private static final int SUBTYPE_MAXLENGTH = 50;
private Identity owner; @Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "enhanced-sequence", parameters={
@Parameter(name="sequence_name", value="hibernate_unique_key"),
@Parameter(name="force_table_use", value="true"),
@Parameter(name="optimizer", value="legacy-hilo"),
@Parameter(name="value_column", value="next_hi"),
@Parameter(name="increment_size", value="32767"),
@Parameter(name="initial_value", value="32767")
})
@Column(name="note_id", nullable=false, unique=true, insertable=true, updatable=false)
private Long key;
@Version
private int version = 0;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="creationdate", nullable=false, insertable=true, updatable=false)
private Date creationDate;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="lastmodified", nullable=false, insertable=true, updatable=true)
private Date lastModified;
@Column(name="resourcetypename", nullable=false, insertable=true, updatable=false)
private String resourceTypeName; private String resourceTypeName;
@Column(name="resourcetypeid", nullable=false, insertable=true, updatable=false)
private Long resourceTypeId; private Long resourceTypeId;
@Column(name="sub_type", nullable=true, insertable=true, updatable=false)
private String subtype; private String subtype;
@Column(name="notetitle", nullable=true, insertable=true, updatable=true)
private String noteTitle; private String noteTitle;
@Column(name="notetext", nullable=true, insertable=true, updatable=true)
private String noteText; private String noteText;
private Date lastModified;
private static final int RESOURCETYPENAME_MAXLENGTH = 50; @OneToOne(targetEntity=IdentityImpl.class)
private static final int SUBTYPE_MAXLENGTH = 50; @JoinColumn(name="owner_id", nullable=false, insertable=true, updatable=false)
private Identity owner;
/** /**
* Default construcor * Default construcor
...@@ -58,9 +111,38 @@ public class NoteImpl extends PersistentObject implements Note { ...@@ -58,9 +111,38 @@ public class NoteImpl extends PersistentObject implements Note {
// nothing to do // nothing to do
} }
@Override
public Long getKey() {
return key;
}
public void setKey(Long key) {
this.key = key;
}
@Override
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
@Override
public Date getLastModified() {
return lastModified;
}
@Override
public void setLastModified(Date date) {
this.lastModified = date;
}
/** /**
* @return Returns the noteText. * @return Returns the noteText.
*/ */
@Override
public String getNoteText() { public String getNoteText() {
return noteText; return noteText;
} }
...@@ -68,6 +150,7 @@ public class NoteImpl extends PersistentObject implements Note { ...@@ -68,6 +150,7 @@ public class NoteImpl extends PersistentObject implements Note {
/** /**
* @param noteText The noteText to set. * @param noteText The noteText to set.
*/ */
@Override
public void setNoteText(String noteText) { public void setNoteText(String noteText) {
this.noteText = noteText; this.noteText = noteText;
} }
...@@ -75,6 +158,7 @@ public class NoteImpl extends PersistentObject implements Note { ...@@ -75,6 +158,7 @@ public class NoteImpl extends PersistentObject implements Note {
/** /**
* @return Returns the noteTitle. * @return Returns the noteTitle.
*/ */
@Override
public String getNoteTitle() { public String getNoteTitle() {
return noteTitle; return noteTitle;
} }
...@@ -82,6 +166,7 @@ public class NoteImpl extends PersistentObject implements Note { ...@@ -82,6 +166,7 @@ public class NoteImpl extends PersistentObject implements Note {
/** /**
* @param noteTitle The noteTitle to set. * @param noteTitle The noteTitle to set.
*/ */
@Override
public void setNoteTitle(String noteTitle) { public void setNoteTitle(String noteTitle) {
this.noteTitle = noteTitle; this.noteTitle = noteTitle;
} }
...@@ -89,6 +174,7 @@ public class NoteImpl extends PersistentObject implements Note { ...@@ -89,6 +174,7 @@ public class NoteImpl extends PersistentObject implements Note {
/** /**
* @return Returns the owner. * @return Returns the owner.
*/ */
@Override
public Identity getOwner() { public Identity getOwner() {
return owner; return owner;
} }
...@@ -96,6 +182,7 @@ public class NoteImpl extends PersistentObject implements Note { ...@@ -96,6 +182,7 @@ public class NoteImpl extends PersistentObject implements Note {
/** /**
* @param owner The owner to set. * @param owner The owner to set.
*/ */
@Override
public void setOwner(Identity owner) { public void setOwner(Identity owner) {
this.owner = owner; this.owner = owner;
} }
...@@ -103,6 +190,7 @@ public class NoteImpl extends PersistentObject implements Note { ...@@ -103,6 +190,7 @@ public class NoteImpl extends PersistentObject implements Note {
/** /**
* @return Returns the resourceTypeId. * @return Returns the resourceTypeId.
*/ */
@Override
public Long getResourceTypeId() { public Long getResourceTypeId() {
return resourceTypeId; return resourceTypeId;
} }
...@@ -110,6 +198,7 @@ public class NoteImpl extends PersistentObject implements Note { ...@@ -110,6 +198,7 @@ public class NoteImpl extends PersistentObject implements Note {
/** /**
* @param resourceTypeId The resourceTypeId to set. * @param resourceTypeId The resourceTypeId to set.
*/ */
@Override
public void setResourceTypeId(Long resourceTypeId) { public void setResourceTypeId(Long resourceTypeId) {
this.resourceTypeId = resourceTypeId; this.resourceTypeId = resourceTypeId;
} }
...@@ -117,6 +206,7 @@ public class NoteImpl extends PersistentObject implements Note { ...@@ -117,6 +206,7 @@ public class NoteImpl extends PersistentObject implements Note {
/** /**
* @return Returns the resourceTypeName. * @return Returns the resourceTypeName.
*/ */
@Override
public String getResourceTypeName() { public String getResourceTypeName() {
return resourceTypeName; return resourceTypeName;
} }
...@@ -124,6 +214,7 @@ public class NoteImpl extends PersistentObject implements Note { ...@@ -124,6 +214,7 @@ public class NoteImpl extends PersistentObject implements Note {
/** /**
* @param resourceTypeName The resourceTypeName to set. * @param resourceTypeName The resourceTypeName to set.
*/ */
@Override
public void setResourceTypeName(String resourceTypeName) { public void setResourceTypeName(String resourceTypeName) {
if (resourceTypeName.length() > RESOURCETYPENAME_MAXLENGTH) if (resourceTypeName.length() > RESOURCETYPENAME_MAXLENGTH)
throw new AssertException("resourcetypename in o_note too long"); throw new AssertException("resourcetypename in o_note too long");
...@@ -133,6 +224,7 @@ public class NoteImpl extends PersistentObject implements Note { ...@@ -133,6 +224,7 @@ public class NoteImpl extends PersistentObject implements Note {
/** /**
* @return Returns the subtype. * @return Returns the subtype.
*/ */
@Override
public String getSubtype() { public String getSubtype() {
return subtype; return subtype;
} }
...@@ -140,28 +232,13 @@ public class NoteImpl extends PersistentObject implements Note { ...@@ -140,28 +232,13 @@ public class NoteImpl extends PersistentObject implements Note {
/** /**
* @param subtype The subtype to set. * @param subtype The subtype to set.
*/ */
@Override
public void setSubtype(String subtype) { public void setSubtype(String subtype) {
if (subtype != null && subtype.length() > SUBTYPE_MAXLENGTH) if (subtype != null && subtype.length() > SUBTYPE_MAXLENGTH)
throw new AssertException("subtype of o_note too long"); throw new AssertException("subtype of o_note too long");
this.subtype = subtype; this.subtype = subtype;
} }
/**
*
* @see org.olat.core.id.ModifiedInfo#getLastModified()
*/
public Date getLastModified() {
return lastModified;
}
/**
*
* @see org.olat.core.id.ModifiedInfo#setLastModified(java.util.Date)
*/
public void setLastModified(Date date) {
this.lastModified = date;
}
@Override @Override
public int hashCode() { public int hashCode() {
return getKey() == null ? 2609815 : getKey().hashCode(); return getKey() == null ? 2609815 : getKey().hashCode();
...@@ -178,4 +255,9 @@ public class NoteImpl extends PersistentObject implements Note { ...@@ -178,4 +255,9 @@ public class NoteImpl extends PersistentObject implements Note {
} }
return false; return false;
} }
@Override
public boolean equalsByPersistableKey(Persistable persistable) {
return equals(persistable);
}
} }
\ No newline at end of file
...@@ -102,9 +102,8 @@ public class NoteManager implements UserDataDeletable, UserDataExportable { ...@@ -102,9 +102,8 @@ public class NoteManager implements UserDataDeletable, UserDataExportable {
* @return the note * @return the note
*/ */
private Note findNote(IdentityRef owner, String resourceTypeName, Long resourceTypeId) { private Note findNote(IdentityRef owner, String resourceTypeName, Long resourceTypeId) {
List<Note> notes = dbInstance.getCurrentEntityManager()
String query = "select n from org.olat.note.NoteImpl as n where n.owner.key=:ownerKey and n.resourceTypeName=:resName and n.resourceTypeId=:resId"; .createNamedQuery("noteByOwnerAndResource", Note.class)
List<Note> notes = dbInstance.getCurrentEntityManager().createQuery(query, Note.class)
.setParameter("ownerKey", owner.getKey()) .setParameter("ownerKey", owner.getKey())
.setParameter("resName", resourceTypeName) .setParameter("resName", resourceTypeName)
.setParameter("resId", resourceTypeId) .setParameter("resId", resourceTypeId)
...@@ -120,9 +119,8 @@ public class NoteManager implements UserDataDeletable, UserDataExportable { ...@@ -120,9 +119,8 @@ public class NoteManager implements UserDataDeletable, UserDataExportable {
* @return a list of notes belonging to the owner * @return a list of notes belonging to the owner
*/ */
public List<Note> listUserNotes(IdentityRef owner) { public List<Note> listUserNotes(IdentityRef owner) {
String query = "select n from org.olat.note.NoteImpl as n inner join fetch n.owner as noteowner where noteowner.key=:noteowner";
return dbInstance.getCurrentEntityManager() return dbInstance.getCurrentEntityManager()
.createQuery(query, Note.class). .createNamedQuery("noteByOwner", Note.class).
setParameter("noteowner", owner.getKey()) setParameter("noteowner", owner.getKey())
.getResultList(); .getResultList();
} }
......
...@@ -184,6 +184,10 @@ ...@@ -184,6 +184,10 @@
<constructor-arg index="0" value="OLAT_12.5.14" /> <constructor-arg index="0" value="OLAT_12.5.14" />
<property name="alterDbStatements" value="alter_12_5_x_to_12_5_14.sql" /> <property name="alterDbStatements" value="alter_12_5_x_to_12_5_14.sql" />
</bean> </bean>
<bean id="database_upgrade_12_5_24" class="org.olat.upgrade.DatabaseUpgrade">
<constructor-arg index="0" value="OLAT_12.5.24" />
<property name="alterDbStatements" value="alter_12_5_x_to_12_5_24.sql" />
</bean>
</list> </list>
</property> </property>
</bean> </bean>
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
<mapping-file>de/bps/olat/modules/cl/Checkpoint.hbm.xml</mapping-file> <mapping-file>de/bps/olat/modules/cl/Checkpoint.hbm.xml</mapping-file>
<mapping-file>org/olat/ims/qti/QTIResult.hbm.xml</mapping-file> <mapping-file>org/olat/ims/qti/QTIResult.hbm.xml</mapping-file>
<mapping-file>org/olat/ims/qti/QTIResultSet.hbm.xml</mapping-file> <mapping-file>org/olat/ims/qti/QTIResultSet.hbm.xml</mapping-file>
<mapping-file>org/olat/note/NoteImpl.hbm.xml</mapping-file>
<mapping-file>org/olat/commons/lifecycle/LifeCycleEntry.hbm.xml</mapping-file> <mapping-file>org/olat/commons/lifecycle/LifeCycleEntry.hbm.xml</mapping-file>
<mapping-file>org/olat/commons/coordinate/cluster/lock/LockImpl.hbm.xml</mapping-file> <mapping-file>org/olat/commons/coordinate/cluster/lock/LockImpl.hbm.xml</mapping-file>
<mapping-file>org/olat/group/area/BGAreaImpl.hbm.xml</mapping-file> <mapping-file>org/olat/group/area/BGAreaImpl.hbm.xml</mapping-file>
...@@ -122,6 +121,7 @@ ...@@ -122,6 +121,7 @@
<class>org.olat.group.model.GroupToBusinessGroup</class> <class>org.olat.group.model.GroupToBusinessGroup</class>
<class>org.olat.group.model.BusinessGroupToSearch</class> <class>org.olat.group.model.BusinessGroupToSearch</class>
<class>org.olat.group.BusinessGroupImpl</class> <class>org.olat.group.BusinessGroupImpl</class>
<class>org.olat.note.NoteImpl</class>
<class>org.olat.registration.TemporaryKeyImpl</class> <class>org.olat.registration.TemporaryKeyImpl</class>
<class>org.olat.repository.RepositoryEntry</class> <class>org.olat.repository.RepositoryEntry</class>
<class>org.olat.repository.model.RepositoryEntryToGroupRelation</class> <class>org.olat.repository.model.RepositoryEntryToGroupRelation</class>
......
alter table o_note add ( temp clob );
update o_note set temp=notetext, notetext=null;
alter table o_note drop column notetext;
alter table o_note rename column temp to notetext;
...@@ -97,4 +97,19 @@ public class NoteTest extends OlatTestCase { ...@@ -97,4 +97,19 @@ public class NoteTest extends OlatTestCase {
Assert.assertEquals("Important", reloadedNote.getNoteTitle()); Assert.assertEquals("Important", reloadedNote.getNoteTitle());
Assert.assertEquals("Cool update with new features", reloadedNote.getNoteText()); Assert.assertEquals("Cool update with new features", reloadedNote.getNoteText());
} }
@Test
public void findNote() {
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("note-2-");
OLATResource resource = JunitTestHelper.createRandomResource();
Note note = noteManager.loadNoteOrCreateInRAM(identity, resource.getResourceableTypeName(), resource.getResourceableId());
note.setNoteTitle("Very important");
note.setNoteText("Critical update with new features");
noteManager.saveNote(note);
dbInstance.commitAndCloseSession();
Note reloadedNote = noteManager.loadNoteOrCreateInRAM(identity, resource.getResourceableTypeName(), resource.getResourceableId());
Assert.assertNotNull(reloadedNote);
Assert.assertEquals(note, reloadedNote);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment