Skip to content

Commit

Permalink
SAK-49673 sitemanage. Allow import of selected tool items (sakaiproje…
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish authored Mar 18, 2024
1 parent e60bb71 commit 8d314ec
Show file tree
Hide file tree
Showing 55 changed files with 1,205 additions and 792 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.sakaiproject.authz.api.SecurityAdvisor;
import org.sakaiproject.content.api.ContentHostingService;
import org.sakaiproject.content.api.ContentResource;
import org.sakaiproject.entity.api.ContentExistsAware;
import org.sakaiproject.entity.api.ContextObserver;
import org.sakaiproject.entity.api.Edit;
import org.sakaiproject.entity.api.Entity;
Expand Down Expand Up @@ -120,8 +121,7 @@
*/
@Slf4j
public abstract class BaseAnnouncementService extends BaseMessage implements AnnouncementService, ContextObserver,
EntityTransferrer
{
EntityTransferrer, ContentExistsAware {

/** Messages, for the http access. */
protected static ResourceLoader rb = new ResourceLoader("annc-access");
Expand Down Expand Up @@ -1698,6 +1698,36 @@ public Map<String, String> transferCopyEntities(String fromContext, String toCon

return null;
}

@Override
public List<Map<String, String>> getEntityMap(String fromContext) {

// get the channel associated with this site
String oChannelRef = channelReference(fromContext, SiteService.MAIN_CONTAINER);
try {
AnnouncementChannel oChannel = (AnnouncementChannel) getChannel(oChannelRef);
return ((List<AnnouncementMessage>) oChannel.getMessages(null, true)).stream()
.map(ann -> Map.of("id", ann.getId(), "title", ann.getAnnouncementHeader().getSubject())).collect(Collectors.toList());
} catch (Exception e) {
log.warn("Failed to get channel for ref {}", e.toString());
}
return Collections.EMPTY_LIST;
}

@Override
public boolean hasContent(String siteId) {

// get the channel associated with this site
String oChannelRef = channelReference(siteId, SiteService.MAIN_CONTAINER);
try {
AnnouncementChannel oChannel = (AnnouncementChannel) getChannel(oChannelRef);
return !oChannel.getMessages(null, true).isEmpty();
} catch (Exception e) {
log.warn("Failed to get channel for ref {}", e.toString());
}

return true;
}

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ AssignmentSubmission newSubmission(String assignmentId,

AssignmentSubmission findSubmissionForGroup(String assignmentId, String groupId);

long countAssignmentsBySite(String siteId);

/**
* Count submissions for a given assignment.
* If any of the parameters are null they are not included in the query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
import org.sakaiproject.contentreview.dao.ContentReviewItem;
import org.sakaiproject.contentreview.exception.QueueException;
import org.sakaiproject.contentreview.service.ContentReviewService;
import org.sakaiproject.entity.api.ContentExistsAware;
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.EntityManager;
import org.sakaiproject.entity.api.EntityTransferrer;
Expand Down Expand Up @@ -201,7 +202,7 @@
*/
@Slf4j
@Transactional(readOnly = true)
public class AssignmentServiceImpl implements AssignmentService, EntityTransferrer, ApplicationContextAware {
public class AssignmentServiceImpl implements AssignmentService, EntityTransferrer, ContentExistsAware, ApplicationContextAware {

@Setter private AnnouncementService announcementService;
@Setter private ApplicationContext applicationContext;
Expand Down Expand Up @@ -4149,6 +4150,12 @@ public void updateEntityReferences(String toContext, Map<String, String> transve
}
}

@Override
public boolean hasContent(String siteId) {

return assignmentRepository.countAssignmentsBySite(siteId) > 0L;
}

@Override
@Transactional
public Map<String, String> transferCopyEntities(String fromContext, String toContext, List<String> ids, List<String> transferOptions) {
Expand Down Expand Up @@ -4535,6 +4542,13 @@ public Map<String, String> transferCopyEntities(String fromContext, String toCon
return transversalMap;
}

@Override
public List<Map<String, String>> getEntityMap(String fromContext) {

return getAssignmentsForContext(fromContext).stream()
.map(ass -> Map.of("id", ass.getId(), "title", ass.getTitle())).collect(Collectors.toList());
}

private String transferAttachment(String fromContext, String toContext, String oAttachmentId) {
String reference = "";
String nAttachmentId = oAttachmentId.replaceAll(fromContext, toContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ public AssignmentSubmission findSubmissionForGroup(String assignmentId, String g
.uniqueResult();
}

@Override
public long countAssignmentsBySite(String siteId) {
Criteria criteria = geCurrentSession().createCriteria(Assignment.class)
.setProjection(Projections.countDistinct("id"))
.add(Restrictions.eq("context", siteId));

return ((Number) criteria.uniqueResult()).longValue();
}

@Override
public long countAssignmentSubmissions(String assignmentId, Boolean graded, Boolean hasSubmissionDate, Boolean userSubmission, List<String> userIds) {
Criteria criteria = geCurrentSession().createCriteria(AssignmentSubmission.class)
Expand Down
4 changes: 4 additions & 0 deletions chat/chat-impl/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Properties;
import java.util.Set;
import java.util.Stack;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -39,6 +40,9 @@
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.stream.Streams;

import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -81,7 +85,6 @@ public class ChatEntityProducer implements EntityProducer, EntityTransferrer {
@Setter private SiteService siteService;
@Setter private UserDirectoryService userDirectoryService;


private static final String ARCHIVE_VERSION = "2.4"; // in case new features are added in future exports
private static final String VERSION_ATTR = "version";
private static final String CHANNEL_PROP = "channel";
Expand All @@ -92,28 +95,17 @@ public class ChatEntityProducer implements EntityProducer, EntityTransferrer {
private static final String PROPERTIES = "properties";
private static final String PROPERTY = "property";



protected void init() throws Exception {
log.info("init()");

try {
getEntityManager().registerEntityProducer(this, ChatManager.REFERENCE_ROOT);
entityManager.registerEntityProducer(this, ChatManager.REFERENCE_ROOT);
}
catch (Exception e) {
log.warn("Error registering Chat Entity Producer", e);
}
}

/**
* Destroy
*/
protected void destroy()
{
log.info("destroy()");
}


/**
* {@inheritDoc}
*/
Expand All @@ -132,13 +124,11 @@ protected String serviceName() {
}

public ChatMessage getMessage(Reference reference) throws IdUnusedException, PermissionException {
return getChatManager().getMessage(reference.getId());
//return null;
return chatManager.getMessage(reference.getId());
}

public ChatChannel getChannel(Reference reference) throws IdUnusedException, PermissionException {
return getChatManager().getChatChannel(reference.getId());
//return null;
return chatManager.getChatChannel(reference.getId());
}

/**
Expand All @@ -159,13 +149,13 @@ public String archive(String siteId, Document doc, Stack stack, String archivePa
stack.push(element);

Element chat = doc.createElement(ChatManager.CHAT);
List channelList = getChatManager().getContextChannels(siteId, true);
if (channelList != null && !channelList.isEmpty())
List<ChatChannel> channelList = chatManager.getContextChannels(siteId, true);
if (CollectionUtils.isNotEmpty(channelList))
{
Iterator channelIterator = channelList.iterator();
Iterator<ChatChannel> channelIterator = channelList.iterator();
while (channelIterator.hasNext())
{
ChatChannel channel = (ChatChannel)channelIterator.next();
ChatChannel channel = channelIterator.next();
Element channelElement = channel.toXml(doc, stack);
chat.appendChild(channelElement);
channelCount++;
Expand Down Expand Up @@ -250,7 +240,7 @@ public Entity getEntity(Reference ref)
// if this is a channel
if (ChatManager.REF_TYPE_CHANNEL.equals(ref.getSubType()))
{
rv = getChatManager().getChatChannel(ref.getReference());
rv = chatManager.getChatChannel(ref.getReference());
}

// otherwise a message
Expand Down Expand Up @@ -494,7 +484,7 @@ public void handleAccess(HttpServletRequest req, HttpServletResponse res, Refere
* {@inheritDoc}
*/
public String getLabel() {
return getChatManager().getLabel();
return chatManager.getLabel();
}


Expand Down Expand Up @@ -542,7 +532,7 @@ public String merge(String siteId, Element root, String archivePath, String from
if (channelElement.getTagName().equals(CHANNEL_PROP)) {
ChatChannel channel = ChatChannel.xmlToChatChannel(channelElement, siteId);
//save the channel
getChatManager().updateChannel(channel, false);
chatManager.updateChannel(channel, false);
}

else if (channelElement.getTagName().equals(SYNOPTIC_TOOL))
Expand Down Expand Up @@ -672,28 +662,37 @@ public boolean willArchiveMerge()
{
return true;
}

@Override
public List<Map<String, String>> getEntityMap(String fromContext) {

return chatManager.getContextChannels(fromContext, true).stream()
.map(cc -> Map.of("id", cc.getId(), "title", cc.getTitle())).collect(Collectors.toList());
}

/**
* {@inheritDoc}
*
* TODO: link the old placement id to the new placement id instead of passing null in line:
* ChatChannel newChannel = getChatManager().createNewChannel(toContext, oldChannel.getTitle(), false, false, null);
* ChatChannel newChannel = chatManager.createNewChannel(toContext, oldChannel.getTitle(), false, false, null);
*/
public Map<String, String> transferCopyEntities(String fromContext, String toContext, List<String> ids, List<String> transferOptions) {

try {
// retrieve all of the chat rooms
List channels = getChatManager().getContextChannels(fromContext, true);
if (channels != null && !channels.isEmpty()) {
for (Iterator channelIterator = channels.iterator(); channelIterator.hasNext();) {
ChatChannel oldChannel = (ChatChannel)channelIterator.next();
ChatChannel newChannel = getChatManager().createNewChannel(toContext, oldChannel.getTitle(), false, false, null);
List<ChatChannel> channels = chatManager.getContextChannels(fromContext, true);

if (CollectionUtils.isNotEmpty(ids)) {
channels = channels.stream().filter(cc -> ids.contains(cc.getId())).collect(Collectors.toList());
}

if (CollectionUtils.isNotEmpty(channels)) {
for (ChatChannel oldChannel : channels) {
ChatChannel newChannel = chatManager.createNewChannel(toContext, oldChannel.getTitle(), false, false, null);
newChannel.setDescription(oldChannel.getDescription());
newChannel.setFilterType(oldChannel.getFilterType());
newChannel.setFilterParam(oldChannel.getFilterParam());
newChannel.setPlacementDefaultChannel(oldChannel.isPlacementDefaultChannel());
try {
getChatManager().updateChannel(newChannel, false);
chatManager.updateChannel(newChannel, false);
} catch (Exception e) {
log.warn("Exception while creating channel: " + newChannel.getTitle() + ": " + e);
}
Expand All @@ -702,11 +701,21 @@ public Map<String, String> transferCopyEntities(String fromContext, String toCon

transferSynopticOptions(fromContext, toContext);
} catch (Exception any) {
log.warn(".transferCopyEntities(): exception in handling " + serviceName() + " : ", any);
log.warn(".transferCopyEntities(): exception in handling {} : {}", serviceName(), any.toString());
}

return null;
}

public Map<String, String> transferCopyEntities(String fromContext, String toContext, List<String> ids, List<String> transferOptions, boolean cleanup) {

if (cleanup) {
Streams.failableStream(chatManager.getContextChannels(toContext, true))
.forEach(chatManager::deleteChannel);
}

return transferCopyEntities(fromContext, toContext, ids, transferOptions);
}

/**
* Import the synoptic tool options from another site
Expand Down Expand Up @@ -759,36 +768,4 @@ protected void transferSynopticOptions(String fromContext, String toContext)
log.warn("transferSynopticOptions(): exception in handling " + serviceName() + " : ", e);
}
}






public Map<String, String> transferCopyEntities(String fromContext, String toContext, List<String> ids, List<String> transferOptions, boolean cleanup) {

try {
if (cleanup) {
// retrieve all of the chat rooms
List channels = getChatManager().getContextChannels(toContext, true);

if (channels != null && !channels.isEmpty()) {
for (Iterator channelIterator = channels.iterator(); channelIterator.hasNext();) {
ChatChannel oldChannel = (ChatChannel)channelIterator.next();

try {
getChatManager().deleteChannel(oldChannel);
} catch (Exception e) {
log.debug("Exception while removing chat channel: " + e);
}
}
}
}
transferCopyEntities(fromContext, toContext, ids, transferOptions);
} catch (Exception e) {
log.debug("Chat transferCopyEntities(): exception in handling " + e);
}

return null;
}
}
10 changes: 4 additions & 6 deletions chat/chat-impl/impl/src/webapp/WEB-INF/components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,10 @@
</bean>

<bean id="org.sakaiproject.chat2.model.impl.ChatEntityProducer"
class="org.sakaiproject.chat2.model.impl.ChatEntityProducer"
init-method="init"
destroy-method="destroy">
<property name="entityManager">
<ref bean="org.sakaiproject.entity.api.EntityManager"/>
</property>
class="org.sakaiproject.chat2.model.impl.ChatEntityProducer"
init-method="init">

<property name="entityManager" ref="org.sakaiproject.entity.api.EntityManager"/>
<property name="chatManager" ref="org.sakaiproject.chat2.model.ChatManager"/>
<property name="siteService" ref="org.sakaiproject.site.api.SiteService"/>
<property name="userDirectoryService" ref="org.sakaiproject.user.api.UserDirectoryService"/>
Expand Down
4 changes: 4 additions & 0 deletions conversations/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
Loading

0 comments on commit 8d314ec

Please sign in to comment.