This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'integration/master' into activityLog
- Loading branch information
Showing
24 changed files
with
364 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
zanata-war/src/main/java/org/zanata/file/BlobPersistService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* 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.file; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.InputStream; | ||
import java.sql.Blob; | ||
import java.sql.SQLException; | ||
|
||
import javax.ws.rs.core.Response.Status; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import org.hibernate.LobHelper; | ||
import org.hibernate.Session; | ||
import org.jboss.seam.ScopeType; | ||
import org.jboss.seam.annotations.AutoCreate; | ||
import org.jboss.seam.annotations.In; | ||
import org.jboss.seam.annotations.Name; | ||
import org.jboss.seam.annotations.Scope; | ||
import org.zanata.dao.DocumentDAO; | ||
import org.zanata.exception.ChunkUploadException; | ||
import org.zanata.model.HDocument; | ||
import org.zanata.model.HDocumentUploadPart; | ||
import org.zanata.model.HRawDocument; | ||
|
||
@Name("blobPersistService") | ||
@Scope(ScopeType.STATELESS) | ||
@AutoCreate | ||
@Slf4j | ||
public class BlobPersistService implements FilePersistService, UploadPartPersistService | ||
{ | ||
|
||
@In | ||
private Session session; | ||
@In | ||
private DocumentDAO documentDAO; | ||
|
||
public HDocumentUploadPart newUploadPartFromStream(InputStream partContentStream, int contentLength) | ||
{ | ||
HDocumentUploadPart newPart = new HDocumentUploadPart(); | ||
Blob partContent = session.getLobHelper().createBlob(partContentStream, contentLength); | ||
newPart.setContent(partContent); | ||
return newPart; | ||
} | ||
|
||
public void persistRawDocumentContentFromFile(HRawDocument rawDocument, File rawFile) | ||
{ | ||
FileInputStream tempFileStream; | ||
try | ||
{ | ||
tempFileStream = new FileInputStream(rawFile); | ||
} | ||
catch (FileNotFoundException e) | ||
{ | ||
// TODO damason: throw more appropriate exception and handle in caller | ||
log.error("Failed to open stream from temp source file", e); | ||
throw new ChunkUploadException(Status.INTERNAL_SERVER_ERROR, | ||
"Error saving uploaded document on server, download in original format may fail.\n", | ||
e); | ||
} | ||
LobHelper lobHelper = documentDAO.getLobHelper(); | ||
Blob fileContents = lobHelper.createBlob(tempFileStream, (int) rawFile.length()); | ||
rawDocument.setContent(fileContents); | ||
} | ||
|
||
@Override | ||
public InputStream getRawDocumentContentAsStream(HRawDocument document) | ||
{ | ||
try | ||
{ | ||
return document.getContent().getBinaryStream(); | ||
} | ||
catch (SQLException e) | ||
{ | ||
throw new RawDocumentContentAccessException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean hasPersistedDocument(GlobalDocumentId id) | ||
{ | ||
HDocument doc = documentDAO.getByProjectIterationAndDocId(id.getProjectSlug(), | ||
id.getVersionSlug(), id.getDocId()); | ||
return doc.getRawDocument() != null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
zanata-war/src/main/java/org/zanata/file/FilePersistService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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.file; | ||
|
||
import java.io.File; | ||
import java.io.InputStream; | ||
|
||
import org.zanata.model.HRawDocument; | ||
|
||
public interface FilePersistService | ||
{ | ||
|
||
public void persistRawDocumentContentFromFile(HRawDocument rawDocument, File rawFile); | ||
|
||
// TODO damason: parsing code only needs a file URI for this. Change to return | ||
// uri when files are persisted to server. | ||
// Other implementations may need a way to specify that they are finished with the | ||
// document resource and cleanup is possible, in case temp files were generated. | ||
public InputStream getRawDocumentContentAsStream(HRawDocument document) | ||
throws RawDocumentContentAccessException; | ||
|
||
boolean hasPersistedDocument(GlobalDocumentId id); | ||
|
||
} |
20 changes: 8 additions & 12 deletions
20
zanata-war/src/main/java/org/zanata/file/GlobalDocumentId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
package org.zanata.file; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@EqualsAndHashCode | ||
public class GlobalDocumentId | ||
{ | ||
|
||
private final String projectSlug; | ||
private final String versionSlug; | ||
private final String docId; | ||
|
||
public GlobalDocumentId(String projectSlug, String versionSlug, String docId) | ||
{ | ||
this.projectSlug = projectSlug; | ||
this.versionSlug = versionSlug; | ||
this.docId = docId; | ||
} | ||
|
||
@NonNull private final String projectSlug; | ||
@NonNull private final String versionSlug; | ||
@NonNull private final String docId; | ||
} |
Oops, something went wrong.