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

Commit

Permalink
fix(copy version): fix null pointer exception when copy version
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Apr 6, 2016
1 parent 7c8ac0a commit db545b8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 31 deletions.
10 changes: 1 addition & 9 deletions zanata-war/src/main/java/org/zanata/action/VersionHome.java
Expand Up @@ -377,16 +377,8 @@ public String createVersion() {
}

public void copyVersion() {
getInstance().setSlug(inputSlugValue);
getInstance().setStatus(EntityStatus.READONLY);

// create basic version here
HProject project = getProject();
project.addIteration(getInstance());
super.persist();

copyVersionManager.startCopyVersion(projectSlug,
copyFromVersionSlug, getInstance().getSlug());
copyFromVersionSlug, inputSlugValue);

conversationScopeMessages
.setMessage(FacesMessage.SEVERITY_INFO, msgs.
Expand Down
Expand Up @@ -21,13 +21,16 @@
import org.zanata.async.AsyncTaskResult;
import org.zanata.async.ContainsAsyncMethods;
import org.zanata.async.handle.CopyVersionTaskHandle;
import org.zanata.common.EntityStatus;
import org.zanata.dao.DocumentDAO;
import org.zanata.dao.ProjectDAO;
import org.zanata.dao.ProjectIterationDAO;
import org.zanata.dao.TextFlowDAO;
import org.zanata.dao.TextFlowTargetDAO;
import org.zanata.file.FilePersistService;
import org.zanata.model.HDocument;
import org.zanata.model.HLocale;
import org.zanata.model.HProject;
import org.zanata.model.HProjectIteration;
import org.zanata.model.HRawDocument;
import org.zanata.model.HSimpleComment;
Expand Down Expand Up @@ -72,6 +75,9 @@ public class CopyVersionServiceImpl implements CopyVersionService {
@In
private ProjectIterationDAO projectIterationDAO;

@In
private ProjectDAO projectDAO;

@In
private DocumentDAO documentDAO;

Expand Down Expand Up @@ -118,12 +124,15 @@ public void copyVersion(@Nonnull String projectSlug,
+ newVersionSlug);

// Copy of HProjectIteration
HProjectIteration newVersion =
projectIterationDAO.getBySlug(projectSlug, newVersionSlug);
HProjectIteration newVersion = new HProjectIteration();

try {
newVersion.setSlug(newVersionSlug);
newVersion.setStatus(EntityStatus.READONLY);
newVersion.setProject(version.getProject());
newVersion = copyVersionSettings(version, newVersion);
newVersion = projectIterationDAO.makePersistent(newVersion);
projectIterationDAO.flush();

// Copy of HDocument
int docSize =
Expand Down
Expand Up @@ -155,9 +155,6 @@ public void testTextFlowBatching() {
String existingVersionSlug =
existingDoc.getProjectIteration().getSlug();

createNewVersion(existingProjectSlug, existingVersionSlug,
newVersionSlug);

insertTextFlowAndTargetToDoc(existingDoc, tfCount, false);

spyService.copyVersion(existingProjectSlug, existingVersionSlug,
Expand All @@ -183,9 +180,6 @@ public void testTextFlowTargetBatching() {
String existingVersionSlug =
existingDoc.getProjectIteration().getSlug();

createNewVersion(existingProjectSlug, existingVersionSlug,
newVersionSlug);

int tftSize = insertTextFlowAndTargetToDoc(existingDoc, 1, true);

spyService.copyVersion(existingProjectSlug, existingVersionSlug,
Expand Down Expand Up @@ -245,7 +239,6 @@ public void testCopyVersion() {
String projectSlug = "sample-project";
String versionSlug = "1.0";
String newVersionSlug = "new-version";
createNewVersion(projectSlug, versionSlug, newVersionSlug);

runCopyVersion(projectSlug, versionSlug, newVersionSlug);
}
Expand All @@ -255,7 +248,6 @@ public void testCopyVersion2() {
String projectSlug = "sample-project";
String versionSlug = "2.0";
String newVersionSlug = "new-version2";
createNewVersion(projectSlug, versionSlug, newVersionSlug);

runCopyVersion(projectSlug, versionSlug, newVersionSlug);
}
Expand Down Expand Up @@ -321,18 +313,6 @@ private void runCopyVersion(String projectSlug, String versionSlug,
}
}

private HProjectIteration createNewVersion(String projectSlug,
String versionSlug, String newVersionSlug) {

HProjectIteration existingVersion =
projectIterationDAO.getBySlug(projectSlug, versionSlug);

HProjectIteration newVersion = new HProjectIteration();
newVersion.setSlug(newVersionSlug);
newVersion.setProject(existingVersion.getProject());
return projectIterationDAO.makePersistent(newVersion);
}

@Test
public void testCopyVersionSettings() {
String projectSlug = "sample-project";
Expand Down

0 comments on commit db545b8

Please sign in to comment.