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

Commit

Permalink
Add entityType, sourceType, entityId and automatedEntry to HTextFlowT…
Browse files Browse the repository at this point in the history
…arget and HTextFlowTargetHistory
  • Loading branch information
Alex Eng committed Jun 25, 2015
1 parent ae9cd70 commit dbb4efb
Show file tree
Hide file tree
Showing 14 changed files with 481 additions and 15 deletions.
6 changes: 3 additions & 3 deletions zanata-model/src/main/java/org/zanata/model/Activity.java
Expand Up @@ -100,9 +100,9 @@ public class Activity extends ModelEntityBase implements Serializable {
public Activity(HPerson actor, IsEntityWithType context,
IsEntityWithType target, ActivityType activityType, int wordCount) {
this.actor = actor;
this.contextType = context.getEntityType();
this.contextType = context.getType();
this.contextId = context.getId();
this.lastTargetType = target.getEntityType();
this.lastTargetType = target.getType();
this.lastTargetId = target.getId();
this.activityType = activityType;
this.wordCount = wordCount;
Expand All @@ -113,7 +113,7 @@ public void updateActivity(Date currentTime, IsEntityWithType target,
this.endOffsetMillis = currentTime.getTime() - approxTime.getTime();
this.wordCount += wordCount;
this.eventCount++;
this.lastTargetType = target.getEntityType();
this.lastTargetType = target.getType();
this.lastTargetId = target.getId();
}

Expand Down
2 changes: 1 addition & 1 deletion zanata-model/src/main/java/org/zanata/model/HDocument.java
Expand Up @@ -303,7 +303,7 @@ public HRawDocument getRawDocument() {

@Override
@Transient
public EntityType getEntityType() {
public EntityType getType() {
return EntityType.HDocument;
}

Expand Down
Expand Up @@ -164,7 +164,7 @@ public Iterator<DocumentWithId> iterator() {

@Override
@Transient
public EntityType getEntityType() {
public EntityType getType() {
return EntityType.HProjectIteration;
}

Expand Down
33 changes: 32 additions & 1 deletion zanata-model/src/main/java/org/zanata/model/HTextFlowTarget.java
Expand Up @@ -32,6 +32,8 @@
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
Expand All @@ -53,6 +55,8 @@
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NaturalId;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.AnalyzerDiscriminator;
import org.hibernate.search.annotations.Field;
Expand All @@ -69,6 +73,8 @@
import org.zanata.hibernate.search.StringListBridge;
import org.zanata.hibernate.search.TextContainerAnalyzerDiscriminator;
import org.zanata.model.type.EntityType;
import org.zanata.model.type.TranslationEntityType;
import org.zanata.model.type.TranslationSourceType;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
Expand All @@ -85,6 +91,7 @@
@Entity
@EntityListeners({ HTextFlowTarget.EntityListener.class })
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@TypeDef(name = "sourceType", typeClass = TranslationSourceType.class)
@Indexed
@Setter
@NoArgsConstructor
Expand Down Expand Up @@ -121,6 +128,20 @@ public class HTextFlowTarget extends ModelEntityBase implements HasContents,
@Getter
private String revisionComment;

@Getter
private TranslationEntityType entityType;

@Getter
private Long entityId;

@Getter
@Type(type = "sourceType")
private TranslationSourceType sourceType;

@Getter
@Setter(AccessLevel.PRIVATE)
private Boolean automatedEntry;

private boolean revisionCommentSet = false;

// Only for internal use (persistence transient)
Expand Down Expand Up @@ -425,7 +446,7 @@ protected boolean logPersistence() {

@Override
@Transient
public EntityType getEntityType() {
public EntityType getType() {
return EntityType.HTexFlowTarget;
}

Expand All @@ -434,7 +455,17 @@ public static class EntityListener {
private void preUpdate(HTextFlowTarget tft) {
// insert history if this has changed from its initial state
if (tft.initialState != null && tft.initialState.hasChanged(tft)) {
if (tft.initialState.getSourceType() == null) {
tft.initialState.setSourceType(TranslationSourceType.UNKNOWN);
}
tft.initialState.setAutomatedEntry(tft.initialState
.getSourceType().isAutomatedEntry());

tft.getHistory().put(tft.oldVersionNum, tft.initialState);
if (tft.getSourceType() == null) {
tft.setSourceType(TranslationSourceType.UNKNOWN);
}
tft.setAutomatedEntry(tft.getSourceType().isAutomatedEntry());
if (!tft.isRevisionCommentSet()) {
tft.setRevisionComment(null);
}
Expand Down
Expand Up @@ -37,13 +37,17 @@
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.AccessType;
import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.IndexColumn;
import org.hibernate.annotations.NaturalId;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.zanata.common.ContentState;
import org.zanata.model.type.TranslationEntityType;
import org.zanata.model.type.TranslationSourceType;

import com.google.common.base.Objects;
import lombok.Getter;
Expand Down Expand Up @@ -76,6 +80,7 @@
name = HTextFlowTargetHistory.QUERY_MATCHING_HISTORY + 6,
query = "select count(*) from HTextFlowTargetHistory t where t.textFlowTarget = :tft and size(t.contents) = :contentCount "
+ "and contents[0] = :content0 and contents[1] = :content1 and contents[2] = :content2 and contents[3] = :content3 and contents[4] = :content4 and contents[5] = :content5") })
@TypeDef(name = "sourceType", typeClass = TranslationSourceType.class)
public class HTextFlowTargetHistory extends HTextContainer implements
Serializable, ITextFlowTargetHistory {
static final String QUERY_MATCHING_HISTORY =
Expand Down Expand Up @@ -107,6 +112,24 @@ public static String getQueryNameMatchingHistory(int size) {

private HPerson reviewer;

@Getter
@Setter
@NotNull
private TranslationEntityType entityType;

@Getter
@Setter
private Long entityId;

@Getter
@Setter
@Type(type = "sourceType")
private TranslationSourceType sourceType;

@Getter
@Setter
private Boolean automatedEntry;

@Getter
@Setter
private String revisionComment;
Expand All @@ -125,7 +148,10 @@ public HTextFlowTargetHistory(HTextFlowTarget target) {
this.reviewer = target.getReviewer();
this.setContents(target.getContents());
this.revisionComment = target.getRevisionComment();

this.automatedEntry = target.getAutomatedEntry();
this.sourceType = target.getSourceType();
this.entityId = target.getEntityId();
this.entityType = target.getEntityType();
}

@Id
Expand Down
Expand Up @@ -28,5 +28,5 @@
public interface IsEntityWithType {
Long getId();

EntityType getEntityType();
EntityType getType();
}
@@ -0,0 +1,40 @@
/*
* Copyright 2015, 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.type;

import lombok.Getter;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/
public enum TranslationEntityType {
TMX("Translation memory"),
TFT("HTextFlowTarget"),
MT("Machine translation");

@Getter
private final String desc;

private TranslationEntityType(String desc) {
this.desc = desc;
}
}
@@ -0,0 +1,95 @@
/*
* Copyright 2015, 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.type;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;

import com.google.common.collect.Lists;
import lombok.Getter;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/
public enum TranslationSourceType {
COPY_TRANS("CT"),
COPY_VERSION("CV"),
MERGE_VERSION("MV"),
TM_MERGE("TM"),
GWT_EDITOR_ENTRY("GWT"),
JS_EDITOR_ENTRY("JS"),
API_UPLOAD("API"),
WEB_UPLOAD("WEB"),
MACHINE_TRANS("MT"),
UNKNOWN("UNK");

public static final Collection<TranslationSourceType> AUTOMATED_ENTRIES;

static {
AUTOMATED_ENTRIES = Collections.unmodifiableCollection(new HashSet(
Arrays.asList(TranslationSourceType.COPY_TRANS,
TranslationSourceType.COPY_VERSION,
TranslationSourceType.MERGE_VERSION,
TranslationSourceType.TM_MERGE)));
}

@Getter
private final String abbr;

private TranslationSourceType(String abbr) {
this.abbr = abbr;
}

public static TranslationSourceType getValueOf(String abbr) {
switch (abbr) {
case "CT":
return TranslationSourceType.COPY_TRANS;
case "CV":
return TranslationSourceType.COPY_VERSION;
case "MV":
return TranslationSourceType.MERGE_VERSION;
case "TM":
return TranslationSourceType.TM_MERGE;
case "GWT":
return TranslationSourceType.GWT_EDITOR_ENTRY;
case "JS":
return TranslationSourceType.JS_EDITOR_ENTRY;
case "API":
return TranslationSourceType.API_UPLOAD;
case "WEB":
return TranslationSourceType.WEB_UPLOAD;
case "MT":
return TranslationSourceType.MACHINE_TRANS;
case "UNKNOWN":
return TranslationSourceType.UNKNOWN;
default:
throw new IllegalArgumentException(String.valueOf(abbr));
}
}

public boolean isAutomatedEntry() {
return AUTOMATED_ENTRIES.contains(this);
}
}
@@ -0,0 +1,68 @@
/*
* Copyright 2015, 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.type;

import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect;
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
import org.hibernate.type.DiscriminatorType;
import org.hibernate.type.StringType;
import org.zanata.common.EntityStatus;


public class TranslationSourceTypeType extends AbstractSingleColumnStandardBasicType<TranslationSourceType>
implements DiscriminatorType<TranslationSourceType> {

public TranslationSourceTypeType() {
super(StringType.INSTANCE.getSqlTypeDescriptor(),
TranslationSourceTypeTypeDescriptor.INSTANCE);
}

@Override
public String toString(TranslationSourceType value) {
return String.valueOf((value).getAbbr());
}

@Override
public String getName() {
return "sourceType";
}

@Override
public String objectToSQLString(TranslationSourceType value, Dialect dialect)
throws Exception {
return "\'" + toString(value) + "\'";
}

public TranslationSourceType stringToObject(String xml) throws Exception {
if (xml.length() < 1) {
throw new MappingException(
"multiple or zero characters found parsing string");
}
return TranslationSourceType.getValueOf(xml);
}

public TranslationSourceType fromStringValue(String xml) {
return TranslationSourceType.getValueOf(xml);
}

}

0 comments on commit dbb4efb

Please sign in to comment.