aDoc.getStep());
aDoc.setDid(new StringBuffer(path).append(".%").append(
Document.suformat).toString()); // Document reference
- path = new StringBuffer(year).append("/").append(path).append("/")
- .append(step.getPath())
+ StringBuffer pathBuf = new StringBuffer(year).append("/").append(path)
+ .append("/").append(step.getPath())
// File path relative to the repository vault
- .append(filename).append(".")
- .append(aDoc.getFile().getFormat()) // File name and extension
- .toString();
- aDoc.getFile().changePath(path);
+ .append(filename);
+ if (!FileNaming.asis.equals(getProjectSettings().getFileNamingScheme())) {
+ // Use format as extension if file naming strategy is not "asis".
+ pathBuf.append(".").append(aDoc.getFile().getFormat()); // File name and extension
+ }
+ aDoc.getFile().changePath(pathBuf.toString());
owner = getStudyDAO().merge(owner);
}
import java.io.FileWriter;
import java.io.IOException;
import java.sql.SQLException;
+import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
steps.addAll(Arrays.asList(studySteps));
steps.addAll(Arrays.asList(scSteps));
steps.addAll(Arrays.asList(studySteps));
+ DecimalFormat tostring = new DecimalFormat(Document.suformat);
for (org.splat.som.Step step : steps) {
LOG.debug("Create a document for the step " + step.getNumber());
.get(0);
Assert.assertEquals(aStudy.getLastLocalIndex(), oldInd + 1,
"Incremented index must be saved in the database.");
+ Assert.assertEquals(addoc.getSourceFile().getName(), tostring
+ .format(aStudy.getLastLocalIndex())
+ + "_" + fname, "The generated file name is incorrect.");
}
}
ht.evict(pub);
ht.evict(pub.value());
int nbConverts = ht.find("from ConvertsRelation").size();
- int nbDocConverts = ht.find("from ConvertsRelation where owner="
+ int nbDocConverts = ht.find(
+ "from ConvertsRelation where owner="
+ pub.value().getIndex()).size();
int nbFiles = ht.find("from File").size();
-
+
ConvertsRelation rel = _publicationService.attach(pub, "py");
_studyDAO.flush();
Assert
.assertTrue(rel.isSaved(),
"Returned ConvertsRelation must be saved in the database.");
- Assert.assertEquals(ht
- .find("from ConvertsRelation where owner="
- + pub.value().getIndex()).size(), nbDocConverts + 1,
+ Assert.assertEquals(ht.find(
+ "from ConvertsRelation where owner="
+ + pub.value().getIndex()).size(),
+ nbDocConverts + 1,
"Number of created ConvertsRelations must be 1.");
- Assert.assertEquals(ht
- .find("from ConvertsRelation").size(), nbConverts + 1,
+ Assert.assertEquals(ht.find("from ConvertsRelation").size(),
+ nbConverts + 1,
"Number of created ConvertsRelations must be 1.");
Assert.assertNotNull(rel.getTo(),
"Attached File must not be null.");
Assert.assertTrue(rel.isSaved(),
"Attached File must be saved in the database.");
- Assert.assertEquals(ht
- .find("from File where rid="
- + rel.getTo().getIndex()).size(), 1,
- "Number of created File must be 1.");
- Assert.assertEquals(ht
- .find("from File").size(), nbFiles + 1,
+ Assert
+ .assertEquals(ht
+ .find(
+ "from File where rid="
+ + rel.getTo().getIndex())
+ .size(), 1, "Number of created File must be 1.");
+ Assert.assertEquals(ht.find("from File").size(), nbFiles + 1,
"Number of created Files must be 1.");
}
}
// Do test checkin
_scenarioService.checkin(scenarioId, userId, stepsToCheckin);
+ _scenarioDAO.flush();
// Check that scenario is no more marked as checked out
aScen = _scenarioDAO.get(scenarioId);
Assert.assertFalse(aScen.isCheckedout(),
private FileDTO createDownloadedFile(final long userId, final String name,
final String format) throws IOException {
// Create a file in the download directory
- String filePath = getDownloadPath(userId) + name + "." + format;
+ return createDownloadedFile(userId, name + "." + format);
+ }
+
+ /**
+ * Create a file in the user's repository downloads directory.
+ *
+ * @param userId
+ * user id
+ * @param fname
+ * file name
+ * @return created file DTO
+ * @throws IOException
+ * if file creation failed
+ */
+ private FileDTO createDownloadedFile(final long userId, final String fname)
+ throws IOException {
+ // Create a file in the download directory
+ String filePath = getDownloadPath(userId) + fname;
FileWriter fw = new FileWriter(filePath);
- fw.write("Simulation of " + name + "." + format
- + " file for checkin at " + new Date());
+ fw.write("Simulation of " + fname + " file for checkin at "
+ + new Date());
fw.close();
return new FileDTO(filePath);
}
} else {
dprop.setFormat("py");
}
+ dprop.setLocalPath(dprop.getName() + "." + dprop.getFormat());
Publication pub = createDoc(aScenario, aScStep, dprop, "med",
false);
if (usedPub != null) {
// Create another document with outdated publication
dprop.setName("document" + i++).setType(dtype).setFormat("py");
+ dprop.setLocalPath(dprop.getName() + "." + dprop.getFormat());
createDoc(aScenario, aScStep, dprop, "med", true);
}
// document<i>: document type[0] - first type used on the step
// <source-file>.brep
// <attached-file>.med
+ createDownloadedFile(aScenario.getAuthor().getIndex(), dprop
+ .getLocalPath());
Publication pub = _stepService.createDocument(aScStep, dprop);
Assert.assertNotNull(pub.getOwner(),
"The publication must be attached to the scenario.");
ht.saveOrUpdate(pub);
// Attach a file
+ createDownloadedFile(aScenario.getAuthor().getIndex(), dprop
+ .getLocalPath().substring(0,
+ dprop.getLocalPath().lastIndexOf(".") - 1),
+ attachedFileExt);
ht.save(pub.value());
ht.saveOrUpdate(_publicationService.attach(pub, attachedFileExt));