Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge branch 'search-replace' of github.com:zanata/zanata into upstre…
Browse files Browse the repository at this point in the history
…am/search-replace
  • Loading branch information
Patrick Huang committed Apr 12, 2012
2 parents 82caa38 + 2d5fd89 commit 8d6362e
Show file tree
Hide file tree
Showing 204 changed files with 5,148 additions and 2,799 deletions.
@@ -1,11 +1,11 @@
package org.zanata.client.commands.push;

import static org.easymock.EasyMock.*;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.notNull;

import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.ws.rs.core.Response.Status;
Expand All @@ -15,7 +15,6 @@
import org.jboss.resteasy.client.ClientResponse;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.zanata.client.commands.ConfigurableProjectCommand;
import org.zanata.client.commands.DummyResponse;
import org.zanata.client.commands.OptionsUtil;
import org.zanata.client.commands.ZanataCommand;
Expand Down
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.List;

import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -283,14 +284,46 @@ else if (inputSource.getSystemId() != null)
return messageParser;
}

private static boolean allNonEmpty(Collection<?> coll)
{
if (coll == null)
return false;
for (Object o : coll)
{
if (o == null)
return false;
}
return true;
}

private static boolean allEmpty(List<String> strings)
{
if (strings == null)
return true;
for (String s : strings)
{
if (s != null && !s.isEmpty())
return false;
}
return true;
}

static ContentState getContentState(Message message)
{
if (message.getMsgstr() == null || message.getMsgstr().isEmpty())
return ContentState.New;
else if (message.isFuzzy())
boolean fuzzy = message.isFuzzy();
if (message.isPlural() && allEmpty(message.getMsgstrPlural()))
{
fuzzy = false;
}
if (fuzzy)
{
return ContentState.NeedReview;
else
}
if ((message.getMsgstr() != null && !message.getMsgstr().isEmpty()) || allNonEmpty(message.getMsgstrPlural()))
{
return ContentState.Approved;
}
return ContentState.New;
}

static String createId(Message message)
Expand Down
Expand Up @@ -5,7 +5,6 @@

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonTypeName;
Expand Down
Expand Up @@ -21,8 +21,6 @@

package org.zanata.rest.service;

import java.io.InputStream;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
Expand Down
@@ -1,9 +1,8 @@
package org.zanata.rest.dto.resource;

import static org.testng.Assert.*;
import static org.testng.Assert.assertEquals;

import java.io.IOException;
import java.util.Arrays;

import javax.xml.bind.JAXBException;

Expand Down
Expand Up @@ -3,6 +3,7 @@
import java.security.MessageDigest;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;

public class HashUtil
{
Expand All @@ -20,5 +21,9 @@ public static String generateHash(String key)
throw new RuntimeException(exc);
}
}


public static String md5Hex(String message)
{
return DigestUtils.md5Hex(message);
}
}
@@ -1,5 +1,8 @@
package org.zanata.util;

import java.util.ArrayList;
import java.util.List;

/**
* ShortStrings are meant for use in logging. They don't incur the cost of
* shortening until toString() is called. This means they hold on to the entire
Expand Down Expand Up @@ -34,4 +37,18 @@ public static String shorten(String s)
return s.substring(0, MAX_LENGTH - ELLIPSIS.length()) + ELLIPSIS;
}

/**
* @param strings
* @return
*/
public static String shorten(List<String> strings)
{
List<String> shortStrings = new ArrayList<String>(strings.size());
for (String s : strings)
{
shortStrings.add(shorten(s));
}
return shortStrings.toString();
}

}
32 changes: 27 additions & 5 deletions server/zanata-model/src/main/java/org/zanata/model/HTextFlow.java
Expand Up @@ -24,7 +24,6 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -47,7 +46,6 @@
import javax.persistence.PostPersist;
import javax.persistence.PostUpdate;
import javax.persistence.PreUpdate;
import javax.persistence.Transient;

import org.hibernate.annotations.AccessType;
import org.hibernate.annotations.BatchSize;
Expand Down Expand Up @@ -118,7 +116,7 @@ public class HTextFlow extends HTextContainer implements Serializable, ITextFlow

private Map<HLocale, HTextFlowTarget> targets;

public Map<Integer, HTextFlowHistory> history;
private Map<Integer, HTextFlowHistory> history;

private HSimpleComment comment;

Expand All @@ -135,6 +133,9 @@ public class HTextFlow extends HTextContainer implements Serializable, ITextFlow

// Only for internal use (persistence transient)
private HTextFlowHistory initialState;

// Only for internal use (persistence transient)
private boolean lazyRelationsCopied = false;

public HTextFlow()
{
Expand Down Expand Up @@ -273,14 +274,18 @@ public void setComment(HSimpleComment comment)
@NotEmpty
@Type(type = "text")
@AccessType("field")
@CollectionOfElements
@CollectionOfElements(fetch = FetchType.EAGER)
@JoinTable(name = "HTextFlowContent",
joinColumns = @JoinColumn(name = "text_flow_id")
)
@IndexColumn(name = "pos", nullable = false)
@Column(name = "content", nullable = false)
public List<String> getContents()
{
// Copy lazily loaded relations to the history object as this cannot be done
// in the entity callbacks
copyLazyLoadedRelationsToHistory();

if( contents == null )
{
contents = new ArrayList<String>();
Expand All @@ -290,9 +295,13 @@ public List<String> getContents()

public void setContents(List<String> contents)
{
// Copy lazily loaded relations to the history object as this cannot be done
// in the entity callbacks
copyLazyLoadedRelationsToHistory();

if (!equal(this.contents, contents))
{
this.contents = contents;
this.contents = new ArrayList<String>(contents);
updateWordCount();
updateContentHash();
}
Expand Down Expand Up @@ -423,6 +432,19 @@ private void updateInternalHistory()
{
this.oldRevision = this.revision;
this.initialState = new HTextFlowHistory(this);
this.lazyRelationsCopied = false;
}

/**
* Copies all lazy loaded relations to the history object.
*/
private void copyLazyLoadedRelationsToHistory()
{
if( this.initialState != null && this.initialState.getContents() == null && !this.lazyRelationsCopied )
{
this.initialState.setContents( this.contents );
this.lazyRelationsCopied = true;
}
}

/**
Expand Down
Expand Up @@ -64,8 +64,10 @@ public HTextFlowHistory()
public HTextFlowHistory(HTextFlow textFlow)
{
this.revision = textFlow.getRevision();
this.contents = new ArrayList<String>(textFlow.getContents());
this.textFlow = textFlow;
// This cannot be done at this point due to an issue with hibernate in which a listener cannot access
// loading collections
//this.setContents(textFlow.getContents());
}

@Id
Expand Down Expand Up @@ -95,7 +97,7 @@ public void setRevision(Integer revision)

// TODO PERF @NaturalId(mutable=false) for better criteria caching
@NaturalId
@ManyToOne(fetch = FetchType.EAGER)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "tf_id")
public HTextFlow getTextFlow()
{
Expand All @@ -110,7 +112,7 @@ public void setTextFlow(HTextFlow textFlow)
@NotEmpty
@Type(type = "text")
@AccessType("field")
@CollectionOfElements
@CollectionOfElements(fetch = FetchType.EAGER)
@JoinTable(name = "HTextFlowContentHistory",
joinColumns = @JoinColumn(name = "text_flow_history_id")
)
Expand All @@ -124,7 +126,7 @@ public List<String> getContents()

public void setContents(List<String> contents)
{
this.contents = contents;
this.contents = new ArrayList<String>(contents);
}

@Override
Expand Down
Expand Up @@ -118,6 +118,9 @@ public class HTextFlowTarget extends ModelEntityBase implements HasContents, Has
// Only for internal use (persistence transient)
private HTextFlowTargetHistory initialState;

// Only for internal use (persistence transient)
private boolean lazyRelationsCopied = false;


public HTextFlowTarget()
{
Expand Down Expand Up @@ -251,14 +254,18 @@ public void setContent( String content )
@Override
@Type(type = "text")
@AccessType("field")
@CollectionOfElements
@CollectionOfElements(fetch = FetchType.EAGER)
@JoinTable(name = "HTextFlowTargetContent",
joinColumns = @JoinColumn(name = "text_flow_target_id")
)
@IndexColumn(name = "pos", nullable = false)
@Column(name = "content", nullable = false)
public List<String> getContents()
{
// Copy lazily loaded relations to the history object as this cannot be done
// in the entity callbacks
copyLazyLoadedRelationsToHistory();

if( contents == null )
{
contents = new ArrayList<String>();
Expand All @@ -268,7 +275,11 @@ public List<String> getContents()

public void setContents(List<String> contents)
{
this.contents = contents;
// Copy lazily loaded relations to the history object as this cannot be done
// in the entity callbacks
copyLazyLoadedRelationsToHistory();

this.contents = new ArrayList<String>(contents);
}

public void setContents(String ... contents)
Expand Down Expand Up @@ -323,6 +334,19 @@ private void updateInternalHistory()
{
this.oldVersionNum = this.getVersionNum();
this.initialState = new HTextFlowTargetHistory(this);
this.lazyRelationsCopied = false;
}

/**
* Copies all lazy loaded relations to the history object.
*/
private void copyLazyLoadedRelationsToHistory()
{
if( this.initialState != null && this.initialState.getContents() == null && !this.lazyRelationsCopied )
{
this.initialState.setContents( this.contents );
this.lazyRelationsCopied = true;
}
}

/**
Expand Down

0 comments on commit 8d6362e

Please sign in to comment.