Skip to content

Commit

Permalink
SAK-47126 SiteArchive add tx template during archive (sakaiproject#10403
Browse files Browse the repository at this point in the history
  • Loading branch information
ern authored Apr 6, 2022
1 parent 07d1bd8 commit 1119a85
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
4 changes: 4 additions & 0 deletions common/archive-impl/impl2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
</dependencies>
<build>
<resources />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import java.util.regex.Pattern;
import java.util.regex.Matcher;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.springframework.transaction.support.TransactionTemplate;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
Expand Down Expand Up @@ -97,6 +99,8 @@ public void setContentHostingService(ContentHostingService service) {
m_contentHostingService = service;
}

@Setter private TransactionTemplate transactionTemplate;

public String archive(String siteId, String m_storagePath, String fromSystem)
{
StringBuilder results = new StringBuilder();
Expand Down Expand Up @@ -147,8 +151,16 @@ public String archive(String siteId, String m_storagePath, String fromSystem)
stack.push(root);

try {
String msg = service.archive(siteId, doc, stack, storagePath, attachments);
results.append(msg);
final String serviceName = service.getClass().getCanonicalName();
transactionTemplate.executeWithoutResult(
transactionStatus -> results
.append("<===== Start ")
.append(serviceName)
.append(" =====>\n")
.append(service.archive(siteId, doc, stack, storagePath, attachments))
.append("<===== End ")
.append(serviceName)
.append(" =====>\n"));
}
catch (Throwable t)
{
Expand All @@ -175,8 +187,7 @@ public String archive(String siteId, String m_storagePath, String fromSystem)

stack.push(root);

String msg = m_contentHostingService.archiveResources(attachments, doc, stack, storagePath);
results.append(msg);
results.append(m_contentHostingService.archiveResources(attachments, doc, stack, storagePath));

stack.pop();

Expand All @@ -197,8 +208,7 @@ public String archive(String siteId, String m_storagePath, String fromSystem)

stack.push(root);

String msg = archiveSite(theSite, doc, stack, fromSystem);
results.append(msg);
results.append(archiveSite(theSite, doc, stack, fromSystem));

stack.pop();
Xml.writeDocument(doc, m_storagePath + siteId + "-archive/site.xml");
Expand All @@ -215,8 +225,7 @@ public String archive(String siteId, String m_storagePath, String fromSystem)

stack.push(root);

msg = archiveUsers(theSite, doc, stack);
results.append(msg);
results.append(archiveUsers(theSite, doc, stack));

stack.pop();
Xml.writeDocument(doc, m_storagePath + siteId + "-archive/user.xml");
Expand Down
5 changes: 5 additions & 0 deletions common/archive-impl/impl2/src/webapp/WEB-INF/components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<property name="userDirectoryService" ref="org.sakaiproject.user.api.UserDirectoryService" />
<property name="timeService" ref="org.sakaiproject.time.api.TimeService" />
<property name="contentHostingService" ref="org.sakaiproject.content.api.ContentHostingService" />
<property name="transactionTemplate">
<bean class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="org.sakaiproject.springframework.orm.hibernate.GlobalTransactionManager"/>
</bean>
</property>
</bean>

<bean id="org_sakaiproject_archive_impl_SiteMerger"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.xml.XmlFactory;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
Expand Down Expand Up @@ -120,6 +121,7 @@ private XmlMapper createXMLMapper() {

final XmlMapper mapper = new XmlMapper(xf);
mapper.registerModules(new JavaTimeModule());
mapper.enable(SerializationFeature.INDENT_OUTPUT);
return mapper;
}
}

0 comments on commit 1119a85

Please sign in to comment.