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

Commit

Permalink
Switch TMXParser to ElementBuilder; Change TM metadata to use Json
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Jul 15, 2013
1 parent 4ba9c9e commit ea8891a
Show file tree
Hide file tree
Showing 13 changed files with 293 additions and 336 deletions.
26 changes: 25 additions & 1 deletion pom.xml
Expand Up @@ -36,7 +36,7 @@
<!-- This should always be the previous version of the used api version above -->
<zanata.api.compat.version>3.0.1-SNAPSHOT</zanata.api.compat.version>
<zanata.client.version>3.0.0</zanata.client.version>
<zanata.common.version>3.0.0</zanata.common.version>
<zanata.common.version>3.0.1-SNAPSHOT</zanata.common.version>

<richfaces.version>4.3.2.Final</richfaces.version>

Expand Down Expand Up @@ -485,6 +485,30 @@
<version>1.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.fedorahosted.tennera</groupId>
<artifactId>jgettext</artifactId>
<version>0.11</version>
</dependency>
<dependency>
<groupId>org.functionaljava</groupId>
<artifactId>functionaljava</artifactId>
<version>3.1</version>
</dependency>
<!--
In the server, we can use a newer version than Fedora has.
This one also has a source jar!
-->
<dependency>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
<version>1.2.5</version>
</dependency>

</dependencies>
</dependencyManagement>
Expand Down
33 changes: 33 additions & 0 deletions zanata-model/src/main/java/org/zanata/model/tm/HasTMMetadata.java
@@ -0,0 +1,33 @@
/*
* Copyright 2013, 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.
*/

package org.zanata.model.tm;

import java.util.Map;

/**
* @author Sean Flanigan <a href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
*
*/
public interface HasTMMetadata
{
Map<TMMetadataType, String> getMetadata();
}
@@ -0,0 +1,61 @@
/*
* Copyright 2013, 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.
*/

package org.zanata.model.tm;

import java.util.Map;

import org.codehaus.jackson.map.ObjectMapper;

/**
* @author Sean Flanigan <a href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
*
*/
public class TMMetadataHelper
{
private static final ObjectMapper mapper = new ObjectMapper();

public static Map<String, String> getTMXMetadata(HasTMMetadata entity)
{
String metadataString = entity.getMetadata().get(TMMetadataType.TMX14);
try
{
return mapper.readValue(metadataString, Map.class);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}

public static void setTMXMetadata(HasTMMetadata entity, Map<String, String> metadata)
{
try
{
String metadataString = mapper.writeValueAsString(metadata);
entity.getMetadata().put(TMMetadataType.TMX14, metadataString);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
}
@@ -0,0 +1,7 @@
package org.zanata.model.tm;
public enum TMMetadataType
{
TMX14;
// GETTEXT ?
}

Expand Up @@ -20,8 +20,8 @@
*/
package org.zanata.model.tm;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
Expand All @@ -31,52 +31,52 @@
import javax.persistence.Lob;
import javax.persistence.MapKeyClass;

import org.zanata.model.ModelEntityBase;
import org.zanata.util.HashUtil;

import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import org.zanata.model.ModelEntityBase;
import org.zanata.util.HashUtil;

import com.google.common.collect.Maps;

/**
* A translation unit variant.
* This is the equivalent of a translated string.
*
* @author Carlos Munoz <a href="mailto:camunoz@redhat.com">camunoz@redhat.com</a>
*/
@Entity
@EqualsAndHashCode(exclude = {"content"})
@EqualsAndHashCode(callSuper=true, exclude = {"content"})
@ToString(exclude = {"contentHash", "metadata"})
@NoArgsConstructor
@Access(AccessType.FIELD)
public class TMTransUnitVariant extends ModelEntityBase
@Data
public class TMTransUnitVariant extends ModelEntityBase implements HasTMMetadata
{
public enum TMTransUnitVariantMetadata
{
TMX_SEG;
}
private static final long serialVersionUID = 1L;

@Getter @Setter
@Column(nullable = false)
private String language;

@Getter
@Column(nullable = false)
private String content;

@Getter @Setter(AccessLevel.PROTECTED)
@Setter(AccessLevel.NONE)
@Column(name ="content_hash", nullable = false)
private String contentHash;

@Getter @Setter
/**
* Map values are Json strings containing metadata for the particular type of translation memory
*/
@ElementCollection
@MapKeyClass(TMTransUnitVariantMetadata.class)
@MapKeyClass(TMMetadataType.class)
@JoinTable(name = "TMTransUnitVariant_Metadata")
@Lob
private Map<TMTransUnitVariantMetadata, String> metadata = new HashMap<TMTransUnitVariantMetadata, String>();
private Map<TMMetadataType, String> metadata = Maps.newHashMap();

public TMTransUnitVariant(String language, String content)
{
Expand Down
Expand Up @@ -20,7 +20,6 @@
*/
package org.zanata.model.tm;

import java.util.HashMap;
import java.util.Map;
import javax.persistence.Access;
import javax.persistence.AccessType;
Expand All @@ -39,6 +38,8 @@

import org.zanata.model.ModelEntityBase;

import com.google.common.collect.Maps;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -53,12 +54,9 @@
@EqualsAndHashCode(callSuper = true, of = {"transUnitId", "sourceLanguage", "translationMemory"})
@ToString(exclude = "translationMemory")
@Access(AccessType.FIELD)
public class TMTranslationUnit extends ModelEntityBase
public class TMTranslationUnit extends ModelEntityBase implements HasTMMetadata
{
public enum TMTranslationUnitMetadata
{
DEFAULT;
}
private static final long serialVersionUID = 1L;

@Getter @Setter
@Column(name = "trans_unit_id", nullable = true)
Expand All @@ -79,12 +77,15 @@ public enum TMTranslationUnitMetadata
joinColumns = @JoinColumn(name = "trans_unit_id"),
inverseJoinColumns = @JoinColumn(name = "trans_unit_variant_id"))
@MapKey(name = "language")
private Map<String, TMTransUnitVariant> transUnitVariants = new HashMap<String, TMTransUnitVariant>();
private Map<String, TMTransUnitVariant> transUnitVariants = Maps.newHashMap();

/**
* Map values are Json strings containing metadata for the particular type of translation memory
*/
@Getter @Setter
@ElementCollection
@MapKeyClass(TMTranslationUnitMetadata.class)
@MapKeyClass(TMMetadataType.class)
@JoinTable(name = "TMTransUnit_Metadata")
@Lob
private Map<TMTranslationUnitMetadata, String> metadata = new HashMap<TMTranslationUnitMetadata, String>();
private Map<TMMetadataType, String> metadata = Maps.newHashMap();
}
22 changes: 11 additions & 11 deletions zanata-model/src/main/java/org/zanata/model/tm/TransMemory.java
Expand Up @@ -20,13 +20,10 @@
*/
package org.zanata.model.tm;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
Expand All @@ -36,8 +33,11 @@
import javax.persistence.MapKeyClass;
import javax.persistence.OneToMany;

import org.testng.collections.Sets;
import org.zanata.model.SlugEntityBase;

import com.google.common.collect.Maps;

import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -53,26 +53,26 @@
@EqualsAndHashCode(callSuper = true, of = {"name"})
@ToString(exclude = "translationUnits")
@Access(AccessType.FIELD)
public class TransMemory extends SlugEntityBase
public class TransMemory extends SlugEntityBase implements HasTMMetadata
{
public enum TransMemoryMetadata
{
DEFAULT;
}
private static final long serialVersionUID = 1L;

@Getter @Setter
@Column
private String name;

@Getter @Setter(AccessLevel.PROTECTED)
@OneToMany(cascade = CascadeType.ALL, mappedBy = "translationMemory")
private Set<TMTranslationUnit> translationUnits = new HashSet<TMTranslationUnit>();
private Set<TMTranslationUnit> translationUnits = Sets.newHashSet();

/**
* Map values are Json strings containing metadata for the particular type of translation memory
*/
@Getter @Setter
@ElementCollection
@MapKeyClass(TransMemoryMetadata.class)
@MapKeyClass(TMMetadataType.class)
@JoinTable(name = "TransMemory_Metadata")
@Lob
private Map<TransMemoryMetadata, String> metadata = new HashMap<TransMemoryMetadata, String>();
private Map<TMMetadataType, String> metadata = Maps.newHashMap();

}
6 changes: 4 additions & 2 deletions zanata-war/pom.xml
Expand Up @@ -1888,12 +1888,10 @@
<dependency>
<groupId>org.fedorahosted.tennera</groupId>
<artifactId>jgettext</artifactId>
<version>0.11</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
Expand Down Expand Up @@ -1932,6 +1930,10 @@
<groupId>xom</groupId>
<artifactId>xom</artifactId>
</dependency>
<dependency>
<groupId>org.functionaljava</groupId>
<artifactId>functionaljava</artifactId>
</dependency>
</dependencies>


Expand Down

0 comments on commit ea8891a

Please sign in to comment.