1 /*****************************************************************************
5 * Creation date 06.10.2012
8 *****************************************************************************/
10 package org.splat.service;
13 import java.io.FileNotFoundException;
14 import java.io.IOException;
15 import java.text.ParseException;
16 import java.util.ArrayList;
17 import java.util.Date;
18 import java.util.HashSet;
19 import java.util.Iterator;
20 import java.util.List;
22 import org.apache.log4j.Logger;
23 import org.splat.common.properties.MessageKeyEnum;
24 import org.splat.dal.bo.kernel.User;
25 import org.splat.dal.bo.som.ConvertsRelation;
26 import org.splat.dal.bo.som.Document;
27 import org.splat.dal.bo.som.DocumentType;
28 import org.splat.dal.bo.som.ProgressState;
29 import org.splat.dal.bo.som.ProjectElement;
30 import org.splat.dal.bo.som.Publication;
31 import org.splat.dal.bo.som.SimulationContext;
32 import org.splat.dal.bo.som.SimulationContextType;
33 import org.splat.dal.bo.som.Study;
34 import org.splat.dal.bo.som.Timestamp;
35 import org.splat.dal.bo.som.UsedByRelation;
36 import org.splat.dal.bo.som.ValidationCycle;
37 import org.splat.dal.bo.som.ValidationStep;
38 import org.splat.dal.dao.som.ProjectElementDAO;
39 import org.splat.dal.dao.som.PublicationDAO;
40 import org.splat.dal.dao.som.TimestampDAO;
41 import org.splat.exception.IncompatibleDataException;
42 import org.splat.exception.InvalidParameterException;
43 import org.splat.kernel.InvalidPropertyException;
44 import org.splat.kernel.MismatchException;
45 import org.splat.kernel.MissedPropertyException;
46 import org.splat.kernel.MultiplyDefinedException;
47 import org.splat.kernel.NotApplicableException;
48 import org.splat.manox.Reader;
49 import org.splat.manox.Toolbox;
50 import org.splat.service.dto.DocToCompareDTO;
51 import org.splat.service.technical.RepositoryService;
52 import org.splat.som.DocumentRights;
53 import org.splat.som.Revision;
54 import org.splat.som.Step;
55 import org.springframework.transaction.annotation.Transactional;
58 * Publication service implementation.
60 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
62 public class PublicationServiceImpl implements PublicationService {
65 * Logger for this class.
67 protected final static Logger LOG = Logger
68 .getLogger(PublicationServiceImpl.class);
71 * Injected study service.
73 private StudyService _studyService;
75 * Injected step service.
77 private StepService _stepService;
79 * Injected document service.
81 private DocumentService _documentService;
83 * Injected document type service.
85 private DocumentTypeService _documentTypeService;
87 * Injected user service.
89 private UserService _userService;
91 * Injected project element service.
93 private ProjectElementService _projectElementService;
95 * Injected simulation context service.
97 private SimulationContextService _simulationContextService;
99 * Injected publication DAO.
101 private PublicationDAO _publicationDAO;
103 * Injected timestamp DAO.
105 private TimestampDAO _timestampDAO;
107 * Injected project element DAO.
109 private ProjectElementDAO _projectElementDAO;
111 * Injected repository service.
113 private RepositoryService _repositoryService;
118 * @see org.splat.service.PublicationService#copy(org.splat.dal.bo.som.Publication, org.splat.dal.bo.som.ProjectElement)
120 public Publication copy(final Publication aPublication,
121 final ProjectElement publisher) {
122 Publication copy = new Publication();
123 copy.setValue(aPublication.value());
124 copy.setStep(aPublication.getStep()); // May not be initialized yet
125 copy.setOwner(publisher);
126 copy.setIsnew(aPublication.getIsnew());
127 if (!copy.getOwnerStudy().equals(aPublication.getOwnerStudy())) {
128 copy.setIsnew('N'); // The referenced document is not new for the given study
136 * @see org.splat.service.PublicationService#createDoc(long, org.splat.som.Step, long, long, java.lang.String, java.lang.String,
137 * org.splat.dal.bo.som.ProgressState, java.lang.String, java.lang.String, java.util.Date, java.util.List)
140 public Publication createDoc(final long ownerId, final Step step,
141 final long documentTypeId, final long userId, final String fname,
142 final String doctitle, final ProgressState docstate,
143 final String reference, final String version, final Date docDate,
144 final List<Long> docuses) throws MissedPropertyException,
145 InvalidPropertyException, MultiplyDefinedException, IOException,
146 NotApplicableException, InterruptedException, ParseException {
147 DocumentType type = getDocumentTypeService().selectType(
148 (int) documentTypeId);
149 User user = getUserService().selectUser(userId);
150 File updir = getRepositoryService().getDownloadDirectory(user);
151 File upfile = new File(updir.getPath() + "/" + fname);
152 String[] table = fname.split("\\x2E");
154 // Creation of the document
155 Document.Properties dprop = new Document.Properties();
156 dprop.setLocalPath(upfile.getPath());
159 if (reference.length() == 0) { // Importation of a foreign document
160 // TODO: Extract property of supported documents (DOCX, ODT...)
161 addoc = getStepService().createDocument(
163 dprop.setName(doctitle).setType(type).setFormat(
164 table[table.length - 1]).setAuthor(user));
165 moveFile(upfile, addoc);
167 saveAs(addoc, docstate); // May throw FileNotFound if rename was not done
168 } catch (FileNotFoundException saverror) {
170 LOG.info("Waiting for the file.");
171 upfile.renameTo(updir);
172 saveAs(addoc, docstate); // Forget it if throw again FileNotFound
174 } else { // Importation of a previously created template-based document
175 if (docDate != null) {
176 dprop.setDate(docDate);
178 addoc = getStepService().assignDocument(step,
179 dprop.setReference(reference).setName(doctitle));
180 moveFile(upfile, addoc);
182 if (version.length() > 0) {
183 saveAs(addoc, new Revision(version));
185 saveAs(addoc, docstate);
187 } catch (FileNotFoundException saverror) {
189 LOG.info("Waiting for the file.");
190 upfile.renameTo(updir);
191 if (version.length() > 0) {
192 saveAs(addoc, new Revision(version));
194 saveAs(addoc, docstate);
198 // Creation of uses relations
199 if (docuses != null) {
200 for (Long index : docuses) {
201 Document used = getDocumentService().selectDocument(index);
202 addoc.addDependency(used);
209 * Move a file into the repository as a source file of the document.
212 * the uploaded file to move
216 private void moveFile(final File upfile, final Publication addoc) {
217 File updir = addoc.getSourceFile().asFile();
218 if (LOG.isInfoEnabled()) {
219 LOG.info("Moving \"" + upfile.getAbsolutePath() + "\" to \""
220 + updir.getPath() + "\".");
222 upfile.renameTo(updir);
228 * @see org.splat.service.PublicationService#versionDocument(org.splat.som.Step, org.splat.dal.bo.kernel.User, java.lang.String, long,
229 * java.lang.String, java.lang.String, org.splat.dal.bo.som.ProgressState, java.util.Date, java.lang.String[], long[])
232 public void versionDocument(final Step step, final User user,
233 final String filename, final long docIndex, final String docver,
234 final String summary, final ProgressState state, final Date date,
235 final String[] docuses, final long[] docusedby)
236 throws MissedPropertyException, InvalidPropertyException,
237 MultiplyDefinedException, IOException, MismatchException,
238 NotApplicableException, InterruptedException {
239 File updir = getRepositoryService().getDownloadDirectory(user);
240 File upfile = new File(updir.getPath() + "/" + filename);
242 // Versioning of the document
243 Document.Properties dprop = new Document.Properties();
244 dprop.setLocalPath(upfile.getPath());
245 Publication current = step.getDocument(docIndex);
248 if ((docver.length() != 0) && // Importation of a not foreign document
252 if ((summary != null) && (summary.length() > 0)) {
253 dprop.setDescription(summary);
255 next = getStepService().versionDocument(step, current,
256 dprop.setAuthor(user));
257 moveFile(upfile, next);
260 if (docver.length() == 0) { // Importation of a foreign document
261 saveAs(next, state); // May throw FileNotFound if rename was not done
263 saveAs(next, new Revision(docver));
265 } catch (FileNotFoundException saverror) {
267 LOG.info("Waiting for the file.");
268 upfile.renameTo(updir);
271 // TODO: Remove current document details from the contents of open study
273 // Creation of uses relations
274 Publication syncronizedCurrent = _publicationDAO.get(current.getIndex());
275 updateRelations(syncronizedCurrent, next, docuses, docusedby);
279 * Update relations after creation of a new document version.
282 * the current version
286 * ids of used documents
288 * ids of documents used by the versioned one.
290 private void updateRelations(final Publication current,
291 final Publication next, final String[] docuses,
292 final long[] docusedby) {
293 if (docuses != null) {
294 for (int i = 0; i < docuses.length; i++) {
295 Long index = Long.valueOf(docuses[i].trim());
296 Document used = getDocumentService().selectDocument(index);// RKV: getPublication(index, steps);
297 next.addDependency(used);
300 // Outdating impacted document
301 HashSet<Long> compatible = new HashSet<Long>();
302 if (docusedby != null) {
303 for (int i = 0; i < docusedby.length; i++) {
304 compatible.add(docusedby[i]);
307 for (Publication using : current.getRelations(UsedByRelation.class)) {
308 if (!compatible.contains(using.getIndex())) {
315 * protected Publication getPublication(int index, List<Step> steps) { for (Iterator<Step> i = steps.iterator(); i.hasNext();) { List<Publication>
316 * published = i.next().getAllDocuments(); for (Iterator<Publication> j = published.iterator(); j.hasNext();) { Publication found =
317 * j.next(); // In a given study step, if (found.value().getIndex() == index) return found; // there is only one publication of a given
318 * document } } return null; }
323 * @see org.splat.service.PublicationService#approve(org.splat.dal.bo.som.Publication, java.util.Date)
326 public Timestamp approve(final Publication aPublication, final Date adate) {
327 Timestamp res = null;
328 if (!(aPublication.isOutdated() || (aPublication.value()
329 .getProgressState() != ProgressState.inCHECK))) {
330 DocumentType type = aPublication.value().getType();
331 Study owner = aPublication.getOwnerStudy();
332 ValidationCycle cycle = getStudyService().getValidationCycleOf(
334 User approver = cycle.getActor(ValidationStep.APPROVAL);
335 Timestamp stamp = new Timestamp(ValidationStep.APPROVAL,
336 aPublication.value(), approver, adate);
337 getTimestampDAO().create(stamp);
339 if (getDocumentService().promote(aPublication.value(), stamp)) {
341 // if (getDocumentService().isStudyResult(type)
342 // && owner.getProgressState() == ProgressState.inCHECK) {
343 // getStudyService().promote(owner);
347 return res; // Hoping that promotion of the study succeeded
353 * @see org.splat.service.PublicationService#demote(org.splat.dal.bo.som.Publication)
356 public boolean demote(final Publication aPublication) {
358 DocumentType type = aPublication.value().getType();
359 Study owner = aPublication.getOwnerStudy();
361 if (aPublication.value().getProgressState() == ProgressState.inCHECK) {
362 ValidationCycle cycle = getStudyService().getValidationCycleOf(
364 if (cycle.enables(ValidationStep.REVIEW)) {
365 res = getDocumentService().demote(aPublication.value());
367 res = getDocumentService().demote(aPublication.value());
369 getDocumentService().demote(aPublication.value());
372 } else if (aPublication.value().getProgressState() == ProgressState.inDRAFT) {
373 res = getDocumentService().demote(aPublication.value());
375 // if (res && getDocumentService().isStudyResult(type)
376 // && owner.getProgressState() != ProgressState.inWORK) {
377 // getStudyService().demote(owner);
385 * @see org.splat.service.PublicationService#invalidate(org.splat.dal.bo.som.Publication)
388 public boolean invalidate(final Publication aPublication) {
390 if ((aPublication.value().getProgressState() == ProgressState.inCHECK)) {
391 DocumentType type = aPublication.value().getType();
392 Study owner = aPublication.getOwnerStudy();
394 ValidationCycle cycle = getStudyService().getValidationCycleOf(
396 // Check if the validation cycle allows the review step
397 if (cycle.enables(ValidationStep.REVIEW)) {
398 // if (getDocumentService().demote(aPublication.value())
399 // && getDocumentService().isStudyResult(type)
400 // && owner.getProgressState() == ProgressState.inCHECK) {
401 // getStudyService().demote(owner);
404 } else { // If the validation cycle has no inDraft step
405 res = demote(aPublication);
414 * @see org.splat.service.PublicationService#promote(org.splat.dal.bo.som.Publication, java.util.Date)
417 public Timestamp promote(final Publication aPublication, final Date pdate) {
418 Timestamp res = null;
419 if ((!aPublication.isOutdated())
420 && (aPublication.value().getProgressState() == ProgressState.inWORK)) {
421 DocumentType type = aPublication.value().getType();
422 Study owner = aPublication.getOwnerStudy();
423 ValidationCycle cycle = getStudyService().getValidationCycleOf(
425 User promoter = cycle.getActor(ValidationStep.PROMOTION);
426 if (promoter == null) {
427 promoter = getInvolvedStep(aPublication).getActor();
429 if (promoter == null) {
430 promoter = owner.getAuthor();
432 Timestamp stamp = new Timestamp(ValidationStep.PROMOTION,
433 aPublication.value(), promoter, pdate);
434 getTimestampDAO().create(stamp);
436 if (getDocumentService().promote(aPublication.value(), stamp)) {
438 if (!cycle.enables(ValidationStep.REVIEW)) {
439 getDocumentService().promote(aPublication.value(), null);
441 // if (getDocumentService().isStudyResult(type)
442 // && owner.getProgressState() == ProgressState.inWORK) {
443 // getStudyService().promote(owner);
447 return res; // Hoping that promotion of the study succeeded
453 * @see org.splat.service.PublicationService#review(org.splat.dal.bo.som.Publication, java.util.Date)
456 public Timestamp review(final Publication aPublication, final Date rdate) {
457 Timestamp res = null;
458 if (!aPublication.isOutdated()
459 && !(aPublication.value().getProgressState() != ProgressState.inDRAFT)) {
461 DocumentType type = aPublication.value().getType();
462 Study owner = aPublication.getOwnerStudy();
463 ValidationCycle cycle = getStudyService().getValidationCycleOf(
465 User reviewer = cycle.getActor(ValidationStep.REVIEW);
466 Timestamp stamp = new Timestamp(ValidationStep.REVIEW, aPublication
467 .value(), reviewer, rdate);
468 getTimestampDAO().create(stamp);
470 if (getDocumentService().promote(aPublication.value(), stamp)) {
472 // if (getDocumentService().isStudyResult(type)
473 // && owner.getProgressState() == ProgressState.inDRAFT) {
474 // getStudyService().promote(owner);
478 return res; // Hoping that promotion of the study succeeded
484 * @see org.splat.service.PublicationService#saveAs(org.splat.dal.bo.som.Publication, org.splat.som.Revision)
489 public void saveAs(final Publication aPublication, final Revision newvers)
490 throws FileNotFoundException, NotApplicableException {
491 if (aPublication.value().isUndefined()) {
492 throw new NotApplicableException(
493 "Cannot save a Publication object refering an undefined Document");
495 if (!aPublication.value().getSourceFile().exists()) {
496 throw new FileNotFoundException();
499 getPublicationDAO().create(aPublication); // Must be done before updating the study in order to fix this final (rid-based) hascode
500 getDocumentService().updateAs(aPublication.value(), newvers); // May change the branch name of given revision
501 updateOwner(aPublication);
507 * @see org.splat.service.PublicationService#saveAs(org.splat.dal.bo.som.Publication, org.splat.dal.bo.som.ProgressState)
510 public void saveAs(final Publication aPublication, final ProgressState state)
511 throws FileNotFoundException, NotApplicableException {
512 if (aPublication.value().isUndefined()) {
513 throw new NotApplicableException(
514 "Cannot save a Publication object refering an undefined Document");
516 if (!aPublication.value().getSourceFile().exists()) {
517 throw new FileNotFoundException(aPublication.value()
518 .getSourceFile().asFile().getAbsolutePath());
521 if (state == ProgressState.inWORK || state == ProgressState.EXTERN) {
522 getPublicationDAO().create(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
524 getDocumentService().updateAs(aPublication.value(), state);
526 // Check that the state is applicable for the validation cycle
527 DocumentType mytype = aPublication.value().getType();
528 Study owner = aPublication.getOwnerStudy();
529 ValidationCycle cycle = getStudyService().getValidationCycleOf(
531 boolean review = cycle.enables(ValidationStep.REVIEW);
532 if (!(state == ProgressState.inDRAFT && review)
533 && !(state == ProgressState.inCHECK && !review)) {
534 throw new NotApplicableException(MessageKeyEnum.DCT_000003
535 .toString(), state.toString());
537 getPublicationDAO().create(aPublication); // Must be done before updating the study in order to fix this final (rid-based)
539 getDocumentService().updateAs(aPublication.value(),
540 ProgressState.inWORK);
542 promote(aPublication, aPublication.value()
543 .getLastModificationDate()); // Promotes to the appropriate state in accordance to the validation cycle
545 updateOwner(aPublication);
549 * Update an owner of the publication.
551 * @param aPublication
552 * the document publication
555 private void updateOwner(final Publication aPublication) {
556 Step step = getInvolvedStep(aPublication);
558 // Update of involved step
559 Document previous = aPublication.value().getPreviousVersion();
560 if (previous != null) {
561 Publication oldoc = step.getDocument(previous.getIndex());
562 getStepService().remove(step, oldoc); // Decrements the configuration tag count of document
564 getStepService().add(step, aPublication); // Increments the configuration tag count of document
566 // Import the document properties and update of the study
567 forwardProperties(aPublication, aPublication.value().getSourceFile()
569 getProjectElementDAO().merge(aPublication.getOwner());
573 * Propagate simulation contexts from the given config file to the publication's owner (study or step).
575 * @param aPublication
576 * the document publication
582 private void forwardProperties(final Publication aPublication,
583 final java.io.File from, final Step to) {
584 Reader tool = Toolbox.getReader(from);
585 if (tool != null) { // Properties extractor available for this type of document
586 SimulationContextType.Properties sprop = new SimulationContextType.Properties()
587 .setStep(to.getStep()).setProgressState(
588 ProgressState.APPROVED);
589 List<SimulationContextType> contype = getSimulationContextService()
590 .selectTypesWhere(sprop);
591 if (!contype.isEmpty()) { // There is an approved property type configured at this step
593 SimulationContext.Properties cprop = new SimulationContext.Properties();
594 List<SimulationContext> context = to.getAllSimulationContexts();
596 context = new ArrayList<SimulationContext>(context.size());
597 context.addAll(to.getAllSimulationContexts());
598 cprop.disableCheck();
599 for (Iterator<SimulationContextType> i = contype.iterator(); i
601 SimulationContextType property = i.next();
602 boolean isFound = false;
603 for (Iterator<SimulationContext> j = context.iterator(); j
605 SimulationContext existing = j.next();
606 isFound = existing.getType().equals(property);
608 // Forget this property as it is already set
614 String value = tool.extractProperty(property
617 continue; // Property not defined into the document
620 cprop.setType(property).setValue(value);
621 if (aPublication.getOwner() instanceof Study) {
622 getStudyService().addProjectContext(
623 (Study) aPublication.getOwner(), cprop); // Re-indexes knowledges and the study
626 .addSimulationContext(to, cprop); // Re-indexes knowledges only
628 } catch (Exception e) {
638 * Returns the study Step into which the document version referenced by this publication has been published.
640 * @param aPublication
641 * the document publication
642 * @return the study step where the document is published
644 public Step getInvolvedStep(final Publication aPublication) {
645 if (aPublication.getStep() == null) {
646 Step[] step = getProjectElementService().getSteps(
647 aPublication.getOwner());
648 for (int i = 0; i < step.length; i++) {
649 aPublication.setStep(step[i]); // The involved step necessarily exists
650 if (aPublication.value().isInto(aPublication.getStep())) {
655 return aPublication.getStep();
659 * Undo the out-date operation.
661 * @param aPublication
663 * @return true if the acceptance succeeds
665 * @see DocumentRights#canAccept()
668 public boolean actualize(final Publication aPublication) {
669 boolean res = aPublication.isOutdated();
671 aPublication.setIsnew('Y');
672 getPublicationDAO().update(aPublication);
678 * Out-dates this publication and recursively all publications using this one. Typically, a publication is out-dated when modifying a
679 * document to which it depends.
681 * @param aPublication
684 * @see #getProgressState()
687 public void outdate(final Publication aPublication) {
688 if (aPublication.isOutdated()) {
692 List<Publication> relist = aPublication
693 .getRelations(UsedByRelation.class);
694 for (Iterator<Publication> i = relist.iterator(); i.hasNext();) {
697 aPublication.setIsnew('O');
698 getPublicationDAO().update(aPublication);
702 * Create "Converts" relation for the given document publication and format.
704 * @param aPublication
705 * the document publication
708 * @return the created "Converts" relation
711 public ConvertsRelation attach(final Publication aPublication,
712 final String format) {
713 return getDocumentService().attach(aPublication.value(), format);
717 * Create "Converts" relation for the given document publication, format and description.
719 * @param aPublication
720 * the document publication
724 * the description of the relation
725 * @return the created "Converts" relation
728 public ConvertsRelation attach(final Publication aPublication,
729 final String format, final String description) {
730 return getDocumentService().attach(aPublication.value(), format,
735 * Rename the published document.
737 * @param aPublication
738 * the publication of the document
740 * the new document title
741 * @throws InvalidPropertyException
742 * if the new title is empty
744 public void rename(final Publication aPublication, final String title)
745 throws InvalidPropertyException {
746 getDocumentService().rename(aPublication.value(), title);
752 * @see org.splat.service.PublicationService#getDocToCompareDTO(long)
754 @Transactional(readOnly = true)
756 public DocToCompareDTO getDocToCompareDTO(final long publicationId)
757 throws InvalidParameterException {
758 DocToCompareDTO res = new DocToCompareDTO();
759 Publication pub = _publicationDAO.get(Long.valueOf(publicationId));
761 throw new InvalidParameterException("id", String
762 .valueOf(publicationId));
765 res.setDocumentTitle(pub.value().getTitle());
766 res.setPathToFile(pub.value().getFile().asFile().getAbsolutePath());
767 res.setScenarioTitle(pub.getOwner().getTitle());
768 res.setStudyTitle(pub.getOwnerStudy().getTitle());
773 * Get the projectElementService.
775 * @return the projectElementService
777 public ProjectElementService getProjectElementService() {
778 return _projectElementService;
782 * Set the projectElementService.
784 * @param projectElementService
785 * the projectElementService to set
787 public void setProjectElementService(
788 final ProjectElementService projectElementService) {
789 _projectElementService = projectElementService;
793 * Get the simulationContextService.
795 * @return the simulationContextService
797 public SimulationContextService getSimulationContextService() {
798 return _simulationContextService;
802 * Set the simulationContextService.
804 * @param simulationContextService
805 * the simulationContextService to set
807 public void setSimulationContextService(
808 final SimulationContextService simulationContextService) {
809 _simulationContextService = simulationContextService;
813 * Get the studyService.
815 * @return the studyService
817 public StudyService getStudyService() {
818 return _studyService;
822 * Set the studyService.
824 * @param studyService
825 * the studyService to set
827 public void setStudyService(final StudyService studyService) {
828 _studyService = studyService;
832 * Get the stepService.
834 * @return the stepService
836 public StepService getStepService() {
841 * Set the stepService.
844 * the stepService to set
846 public void setStepService(final StepService stepService) {
847 _stepService = stepService;
851 * Get the documentService.
853 * @return the documentService
855 public DocumentService getDocumentService() {
856 return _documentService;
860 * Set the documentService.
862 * @param documentService
863 * the documentService to set
865 public void setDocumentService(final DocumentService documentService) {
866 _documentService = documentService;
870 * Get the publicationDAO.
872 * @return the publicationDAO
874 public PublicationDAO getPublicationDAO() {
875 return _publicationDAO;
879 * Set the publicationDAO.
881 * @param publicationDAO
882 * the publicationDAO to set
884 public void setPublicationDAO(final PublicationDAO publicationDAO) {
885 _publicationDAO = publicationDAO;
889 * Get the projectElementDAO.
891 * @return the projectElementDAO
893 public ProjectElementDAO getProjectElementDAO() {
894 return _projectElementDAO;
898 * Set the projectElementDAO.
900 * @param projectElementDAO
901 * the projectElementDAO to set
903 public void setProjectElementDAO(final ProjectElementDAO projectElementDAO) {
904 _projectElementDAO = projectElementDAO;
908 * Get the repositoryService.
910 * @return the repositoryService
912 public RepositoryService getRepositoryService() {
913 return _repositoryService;
917 * Set the repositoryService.
919 * @param repositoryService
920 * the repositoryService to set
922 public void setRepositoryService(final RepositoryService repositoryService) {
923 _repositoryService = repositoryService;
927 * Get the timestampDAO.
929 * @return the timestampDAO
931 public TimestampDAO getTimestampDAO() {
932 return _timestampDAO;
936 * Set the timestampDAO.
938 * @param timestampDAO
939 * the timestampDAO to set
941 public void setTimestampDAO(final TimestampDAO timestampDAO) {
942 _timestampDAO = timestampDAO;
946 * Get the documentTypeService.
948 * @return the documentTypeService
950 public DocumentTypeService getDocumentTypeService() {
951 return _documentTypeService;
955 * Set the documentTypeService.
957 * @param documentTypeService
958 * the documentTypeService to set
960 public void setDocumentTypeService(
961 final DocumentTypeService documentTypeService) {
962 _documentTypeService = documentTypeService;
966 * Get the userService.
968 * @return the userService
970 public UserService getUserService() {
975 * Set the userService.
978 * the userService to set
980 public void setUserService(final UserService userService) {
981 _userService = userService;
987 * @see org.splat.service.PublicationService#replace(long, java.io.File)
991 public boolean replace(final Publication pub, final File newFile,
992 final Date modifTime) throws IncompatibleDataException {
993 if (!(ProgressState.EXTERN.equals(pub.getProgressState()) || ProgressState.inWORK
994 .equals(pub.getProgressState()))) {
995 throw new IncompatibleDataException(MessageKeyEnum.DCT_000004
998 Document doc = getDocumentService().selectDocument(
999 pub.value().getIndex());
1000 if (LOG.isInfoEnabled()) {
1001 LOG.info("Moving \"" + newFile.getName() + "\" to \""
1002 + doc.getSourceFile().asFile().getAbsolutePath() + "\".");
1004 // Save a temporary copy of the original file as <old file name>.backup
1005 String oldFilePath = doc.getSourceFile().asFile().getAbsolutePath();
1006 File oldFile = new File(oldFilePath);
1007 File backupFile = new File(oldFilePath + ".backup");
1008 oldFile.renameTo(backupFile);
1009 boolean res = newFile.renameTo(oldFile);
1011 // Delete the temporary copy of the old file
1012 // if the new one is moved into the repository.
1013 backupFile.delete();
1014 // Update the document modification date.
1015 doc.setLastModificationDate(modifTime);
1016 // Update presentation data
1017 pub.value().setLastModificationDate(modifTime);
1019 // Restore the original file if replacing is failed
1020 backupFile.renameTo(oldFile);