Skip to content

Commit

Permalink
fix: add limit to glossary fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Feb 8, 2018
1 parent 2e4e010 commit 7efd9cb
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 8 deletions.
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.List;

import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
Expand Down Expand Up @@ -59,14 +60,17 @@ public class GlossaryEntry implements Serializable, HasMediaType {

private Long id;

@Size(max = 255)
private String pos;

@Size(max = 500)
private String description;

private List<GlossaryTerm> glossaryTerms;

private LocaleId srcLang;

@Size(max = 500)
private String sourceReference;

private QualifiedName qualifiedName;
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.Date;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
Expand Down Expand Up @@ -57,8 +58,10 @@ public class GlossaryTerm implements Serializable {
@NotNull
private LocaleId locale;

@Size(max = 500)
private String content;

@Size(max = 500)
private String comment;

private String lastModifiedBy;
Expand Down
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<!--
~ Copyright 2018, Red Hat, Inc. and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">

<changeSet id="1" author="aeng@redhat.com">
<comment>Alter HGlossaryEntry description to 500</comment>
<sql>UPDATE HGlossaryEntry SET description=SUBSTRING(description,1,500);</sql>
<modifyDataType tableName="HGlossaryEntry" columnName="description"
newDataType="varchar(500)"/>
</changeSet>

<changeSet id="2" author="aeng@redhat.com">
<comment>Alter HGlossaryEntry sourceRef to 500</comment>
<sql>UPDATE HGlossaryEntry SET sourceRef=SUBSTRING(sourceRef,1,500);</sql>
<modifyDataType tableName="HGlossaryEntry" columnName="sourceRef"
newDataType="varchar(500)"/>
</changeSet>

<changeSet id="3" author="aeng@redhat.com">
<comment>Alter HGlossaryTerm content to 500</comment>
<sql>UPDATE HGlossaryTerm SET content=SUBSTRING(content,1,500);</sql>
<modifyDataType tableName="HGlossaryTerm" columnName="content"
newDataType="varchar(500)"/>
</changeSet>

<changeSet id="4" author="aeng@redhat.com">
<comment>Alter HGlossaryTerm comment to 500</comment>
<sql>UPDATE HGlossaryTerm SET comment=SUBSTRING(comment,1,500);</sql>
<modifyDataType tableName="HGlossaryTerm" columnName="comment"
newDataType="varchar(500)"/>
</changeSet>

</databaseChangeLog>
2 changes: 2 additions & 0 deletions server/services/src/main/resources/db/db.changelog.xml
Expand Up @@ -51,6 +51,8 @@
file="changelogs/db.changelog-4.3.xml" />
<include relativeToChangelogFile="true"
file="changelogs/db.changelog-4.4.xml" />
<include relativeToChangelogFile="true"
file="changelogs/db.changelog-4.5.xml" />

<!-- NB: triggers and validations must appear after all table changes -->
<!-- If the Liquibase version is being updated, please refer to the
Expand Down
Expand Up @@ -1920,6 +1920,7 @@ exports[`Frontend Storyshots EditableText editing 1`] = `
autoFocus={false}
className="textInput"
id={undefined}
maxLength={255}
onBlur={[Function]}
onChange={undefined}
onFocus={[Function]}
Expand Down Expand Up @@ -18239,6 +18240,7 @@ exports[`Frontend Storyshots RejectionsForm Admin screen 1`] = `
autoFocus={undefined}
className="textInput"
id={undefined}
maxLength={undefined}
onBlur={undefined}
onChange={[Function]}
onFocus={[Function]}
Expand Down Expand Up @@ -18370,6 +18372,7 @@ exports[`Frontend Storyshots RejectionsForm Admin screen 1`] = `
autoFocus={undefined}
className="textInput"
id={undefined}
maxLength={undefined}
onBlur={undefined}
onChange={[Function]}
onFocus={[Function]}
Expand Down Expand Up @@ -18501,6 +18504,7 @@ exports[`Frontend Storyshots RejectionsForm Admin screen 1`] = `
autoFocus={undefined}
className="textInput"
id={undefined}
maxLength={undefined}
onBlur={undefined}
onChange={[Function]}
onFocus={[Function]}
Expand Down Expand Up @@ -18632,6 +18636,7 @@ exports[`Frontend Storyshots RejectionsForm Admin screen 1`] = `
autoFocus={undefined}
className="textInput"
id={undefined}
maxLength={undefined}
onBlur={undefined}
onChange={[Function]}
onFocus={[Function]}
Expand Down Expand Up @@ -18763,6 +18768,7 @@ exports[`Frontend Storyshots RejectionsForm Admin screen 1`] = `
autoFocus={undefined}
className="textInput"
id={undefined}
maxLength={undefined}
onBlur={undefined}
onChange={[Function]}
onFocus={[Function]}
Expand Down Expand Up @@ -18894,6 +18900,7 @@ exports[`Frontend Storyshots RejectionsForm Admin screen 1`] = `
autoFocus={undefined}
className="textInput"
id={undefined}
maxLength={undefined}
onBlur={undefined}
onChange={[Function]}
onFocus={[Function]}
Expand Down Expand Up @@ -19081,6 +19088,7 @@ exports[`Frontend Storyshots RejectionsForm editable 1`] = `
autoFocus={undefined}
className="textInput"
id={undefined}
maxLength={undefined}
onBlur={undefined}
onChange={[Function]}
onFocus={[Function]}
Expand Down Expand Up @@ -19215,6 +19223,7 @@ exports[`Frontend Storyshots RejectionsForm read only 1`] = `
autoFocus={undefined}
className="textInput"
id={undefined}
maxLength={undefined}
onBlur={undefined}
onChange={[Function]}
onFocus={[Function]}
Expand Down Expand Up @@ -24415,6 +24424,7 @@ exports[`Frontend Storyshots TextInput default 1`] = `
autoFocus={undefined}
className="textInput"
id="demo"
maxLength={100}
onBlur={undefined}
onChange={undefined}
onFocus={[Function]}
Expand Down
2 changes: 2 additions & 0 deletions server/zanata-frontend/src/app/components/TextInput/index.js
Expand Up @@ -156,6 +156,7 @@ class TextInput extends Component {
autoFocus,
editable = true,
keyboardType = 'default',
maxLength,
maxNumberOfLines,
multiline = false,
numberOfLines = 2,
Expand Down Expand Up @@ -201,6 +202,7 @@ class TextInput extends Component {
autoComplete: autoComplete && 'on',
autoFocus,
className: 'textInput',
maxLength,
onBlur: onBlur && this._onBlur,
onChange: (onChange || onChangeText) && this._onChange,
onFocus: this._onFocus,
Expand Down
2 changes: 2 additions & 0 deletions server/zanata-frontend/src/app/containers/Glossary/Entry.js
Expand Up @@ -110,6 +110,7 @@ class Entry extends Component {
title={transContent}
editable={transSelected && editable}
editing={selected}
maxLength={500}
onChange={(e) => handleTermFieldUpdate('locale', e)}
placeholder='Add a translation…'
emptyReadOnlyText='No translation'>
Expand Down Expand Up @@ -152,6 +153,7 @@ class Entry extends Component {
title={entry.pos}
editable={!transSelected && editable}
editing={selected}
maxLength={255}
onChange={(e) => handleTermFieldUpdate('pos', e)}
placeholder='Add part of speech'
emptyReadOnlyText='No part of speech'>
Expand Down
Expand Up @@ -116,7 +116,7 @@ class EntryModal extends Component {
<EditableText
editable={!transSelected}
editing
maxLength={255}
maxLength={500}
placeholder='Add a description…'
emptyReadOnlyText='No description'
onChange={(e) => handleTermFieldUpdate('description', e)}>
Expand All @@ -129,7 +129,7 @@ class EntryModal extends Component {
<EditableText
editable
editing
maxLength={255}
maxLength={500}
placeholder='Add a translation…'
emptyReadOnlyText='No translation'
onChange={(e) => handleTermFieldUpdate('locale', e)}>
Expand All @@ -142,7 +142,7 @@ class EntryModal extends Component {
<div className='modal-section'>
<label className='text-bold'>Comment</label><br />
<EditableText
maxLength={255}
maxLength={500}
editable={enableComment}
editing={enableComment}
placeholder='Add a comment…'
Expand Down
Expand Up @@ -94,7 +94,7 @@ class NewEntryModal extends Component {
editable
editing
placeholder='The new term'
maxLength={255}
maxLength={500}
onChange={this.handleContentChanged.bind(this)}>
{this.state.entry.srcTerm.content}
</EditableText>
Expand All @@ -118,7 +118,7 @@ class NewEntryModal extends Component {
editable
editing
placeholder='The definition of this term'
maxLength={255}
maxLength={500}
onChange={this.handleDescChanged.bind(this)}>
{this.state.entry.description}
</EditableText>
Expand Down
Expand Up @@ -37,6 +37,8 @@
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge;
Expand Down Expand Up @@ -72,7 +74,7 @@ public Map<HLocale, HGlossaryTerm> getGlossaryTerms() {
return glossaryTerms;
}

@javax.persistence.Lob
@Size(max = 500)
public String getSourceRef() {
return sourceRef;
}
Expand All @@ -99,10 +101,12 @@ public String getContentHash() {
return contentHash;
}

@Size(max = 255)
public String getPos() {
return pos;
}

@Size(max = 500)
public String getDescription() {
return description;
}
Expand Down
Expand Up @@ -27,6 +27,8 @@
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.hibernate.annotations.NaturalId;
import org.hibernate.search.annotations.Analyze;
Expand Down Expand Up @@ -62,13 +64,13 @@ public HGlossaryTerm(String content) {
}

@NotNull
@javax.persistence.Lob
@Size(max = 500)
@Field(analyzer = @Analyzer(impl = StandardAnalyzer.class))
public String getContent() {
return content;
}

@Column(columnDefinition = "longtext")
@Size(max = 500)
public String getComment() {
return comment;
}
Expand Down

0 comments on commit 7efd9cb

Please sign in to comment.