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

Commit

Permalink
Merge branch 'master' into documentListStatsOption
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Sep 23, 2012
2 parents f5d7113 + 0e69bbb commit 9843f16
Show file tree
Hide file tree
Showing 16 changed files with 330 additions and 60 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Expand Up @@ -292,6 +292,16 @@
<artifactId>gwt-maven-plugin</artifactId>
<version>2.4.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<formats>
<format>xml</format>
</formats>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down
12 changes: 12 additions & 0 deletions zanata-model/src/main/java/org/zanata/model/HDocument.java
Expand Up @@ -30,6 +30,7 @@
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
Expand Down Expand Up @@ -103,6 +104,8 @@ public class HDocument extends ModelEntityBase implements IDocumentHistory, Seri
private HPoHeader poHeader;
private Map<HLocale, HPoTargetHeader> poTargetHeaders;

private HRawDocument rawDocument;

public HDocument(String fullPath, ContentType contentType, HLocale locale)
{
this.contentType = contentType;
Expand Down Expand Up @@ -281,6 +284,15 @@ public Map<HLocale, HPoTargetHeader> getPoTargetHeaders()
return poTargetHeaders;
}

@OneToOne(fetch = FetchType.LAZY, optional = true)
@JoinTable(name = "HDocument_RawDocument",
joinColumns = @JoinColumn(name="documentId"),
inverseJoinColumns = @JoinColumn(name="rawDocumentId")
)
public HRawDocument getRawDocument()
{
return rawDocument;
}

@PreUpdate
public void onUpdate()
Expand Down
108 changes: 108 additions & 0 deletions zanata-model/src/main/java/org/zanata/model/HRawDocument.java
@@ -0,0 +1,108 @@
/*
* Copyright 2012, 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;

import java.io.Serializable;
import java.sql.Blob;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Lob;
import javax.persistence.OneToOne;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import org.hibernate.validator.NotEmpty;
import org.zanata.common.DocumentType;

import com.google.common.base.Objects;

@Entity
@Getter
@Setter
@NoArgsConstructor // is this necessary?
public class HRawDocument extends ModelEntityBase implements Serializable
{

private static final long serialVersionUID = 5129552589912687504L;

// TODO ensure any document deletion cascades to remove associated HRawDocument
private HDocument document;

// TODO none of these should allow null
private String contentHash;
private Blob content;
private DocumentType type;
private String uploadedBy;


@OneToOne(mappedBy = "rawDocument")
public HDocument getDocument()
{
return document;
}

public void setDocument(HDocument document)
{
if (!Objects.equal(this.document, document))
{
this.document = document;
}
}

@NotEmpty
public String getContentHash()
{
return contentHash;
}

@Lob
public Blob getContent()
{
return content;
}

@Enumerated(EnumType.STRING)
public DocumentType getType()
{
return type;
}

public String getUploadedBy()
{
return uploadedBy;
}


@Override
public String toString()
{
return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode())
+ "[id=" + id + ",versionNum=" + versionNum
+ ",contentHash=" + contentHash + "]";
}

// TODO override equals to use contentHash

}
1 change: 0 additions & 1 deletion zanata-war/pom.xml
Expand Up @@ -223,7 +223,6 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
<instrumentation>
<excludes>
Expand Down
Expand Up @@ -401,15 +401,15 @@ public void setLocaleId(String localeId)
{
this.localeId = localeId;
}

// line not found
public boolean hasOriginal(String docPath, String docName)
{
return translationFileServiceImpl.hasPersistedDocument(projectSlug, iterationSlug, docPath, docName);
}

public String extensionOf(String docName)
public String extensionOf(String docPath, String docName)
{
return "." + translationFileServiceImpl.extractExtension(docName);
return "." + translationFileServiceImpl.getFileExtension(projectSlug, iterationSlug, docPath, docName);
}

public String getDocumentNameFilter()
Expand Down
43 changes: 43 additions & 0 deletions zanata-war/src/main/java/org/zanata/dao/DocumentDAO.java
Expand Up @@ -21,6 +21,7 @@
import org.zanata.common.TranslationStats;
import org.zanata.model.HDocument;
import org.zanata.model.HProjectIteration;
import org.zanata.model.HRawDocument;
import org.zanata.model.HTextFlow;
import org.zanata.model.StatusCount;

Expand Down Expand Up @@ -348,4 +349,46 @@ public List<HDocument> getAllByProjectIteration(final String projectSlug, final
return documents;
}

/**
* Do not use this method when adding a new raw document,
* instead use {@link #addRawDocument(HDocument, HRawDocument)}
*
* @see AbstractDAOImpl#makePersistent(Object)
*/
@Override
public HDocument makePersistent(HDocument entity) {
// TODO consider how to deal with old rawDocument.
if (entity.getRawDocument() != null)
{
getSession().saveOrUpdate(entity.getRawDocument());
}
return super.makePersistent(entity);
}

/**
* Add a raw document to a document, cleanly removing any
* existing raw document associated with the document.
*
* @param doc
* @param rawDoc
* @return
*/
public HRawDocument addRawDocument(HDocument doc, HRawDocument rawDoc)
{
HRawDocument oldRawDoc = doc.getRawDocument();

if (oldRawDoc != null && !oldRawDoc.equals(rawDoc))
{
getSession().delete(oldRawDoc);
}

if (rawDoc != null)
{
getSession().saveOrUpdate(rawDoc);
}

doc.setRawDocument(rawDoc);
makePersistent(doc);
return rawDoc;
}
}

0 comments on commit 9843f16

Please sign in to comment.