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 9, 2018
1 parent 2e4e010 commit fe33ea9
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 13 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
@@ -1,6 +1,7 @@
package org.zanata.service.impl;

import com.google.common.collect.Lists;
import org.apache.lucene.queryparser.classic.ParseException;
import org.jglue.cdiunit.InRequestScope;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -15,16 +16,22 @@
import org.zanata.service.LocaleService;
import org.zanata.servlet.annotations.ContextPath;
import org.zanata.test.CdiUnitRunner;
import org.zanata.util.GlossaryUtil;
import org.zanata.util.UrlUtil;
import org.zanata.webtrans.shared.model.GlossaryDetails;
import org.zanata.webtrans.shared.model.GlossaryResultItem;
import org.zanata.webtrans.shared.model.WorkspaceId;
import org.zanata.webtrans.shared.rpc.HasSearchType;
import org.zanata.webtrans.test.GWTTestData;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
Expand All @@ -36,7 +43,7 @@ public class GlossarySearchServiceImplTest extends ZanataTest {
// code under test is migrated from there anyway.

@Inject @Any
private GlossarySearchServiceImpl glossarySearchServiceImpl;
private GlossarySearchServiceImpl service;
@Produces @Mock
private ZanataIdentity identity;
@Produces @Mock
Expand Down Expand Up @@ -66,7 +73,7 @@ private HGlossaryTerm glossaryTerm(String content, HLocale srcLocale) {

@Test
@InRequestScope
public void testLookupDetails() throws Exception {
public void testLookupDetails() {
WorkspaceId workspaceId =
GWTTestData.workspaceId(targetHLocale.getLocaleId());
ArrayList<Long> sourceIdList = Lists.newArrayList(1L);
Expand All @@ -84,7 +91,7 @@ public void testLookupDetails() throws Exception {
Lists.newArrayList(sourceTerm));


ArrayList<GlossaryDetails> result = glossarySearchServiceImpl.lookupDetails(
ArrayList<GlossaryDetails> result = service.lookupDetails(
targetHLocale.getLocaleId(), sourceIdList);

// The calling class is responsible for checking a login. Make sure this
Expand All @@ -94,4 +101,61 @@ public void testLookupDetails() throws Exception {
assertThat(result).hasSize(1);
assertThat(result.get(0).getTarget()).isEqualTo("target term");
}

@Test
@InRequestScope
public void testGlossaryUrl() {
LocaleId localeId = LocaleId.DE;
String url = service
.glossaryUrl("qualifiedName", null, localeId);
assertThat(url).contains("locale=" + localeId.getId());

String qualifiedName = "project/project1";
url = service.glossaryUrl(qualifiedName, null, localeId);
assertThat(url).contains(qualifiedName)
.contains("locale=" + localeId.getId());

String filter = "query";
url = service.glossaryUrl(qualifiedName, filter, localeId);
assertThat(url).contains(qualifiedName)
.contains("locale=" + localeId.getId())
.contains("filter=" + filter);
}

@Test
@InRequestScope
public void testSearchGlossary() throws ParseException {
LocaleId srcLocale = LocaleId.EN_US;
LocaleId transLocale = LocaleId.DE;
String searchText = "query";
HasSearchType.SearchType searchType = HasSearchType.SearchType.FUZZY;
int maxResults = 10;
String projectSlug = null;

List<Object[]> globalMatches = new ArrayList<>();
HGlossaryEntry entry = new HGlossaryEntry();
HGlossaryTerm sourceTerm1 = new HGlossaryTerm("content1");
HGlossaryTerm transTerm1 = new HGlossaryTerm("content1Trans");
sourceTerm1.setGlossaryEntry(entry);

globalMatches.add(new Object[]{new Float("100.00"), sourceTerm1});

when(glossaryDAO.getSearchResult(searchText, searchType, srcLocale,
maxResults, GlossaryUtil.GLOBAL_QUALIFIED_NAME))
.thenReturn(globalMatches);

when(glossaryDAO
.getTermByEntryAndLocale(null, transLocale, "global/default"))
.thenReturn(transTerm1);

ArrayList<GlossaryResultItem> results =
service.searchGlossary(srcLocale, transLocale, searchText,
searchType, maxResults, projectSlug);

assertThat(results).hasSize(1);
assertThat(results.get(0).getSource())
.isEqualTo(sourceTerm1.getContent());
assertThat(results.get(0).getTarget())
.isEqualTo(transTerm1.getContent());
}
}
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

0 comments on commit fe33ea9

Please sign in to comment.