Skip to content

Commit

Permalink
SAK-40339 Added site import options for tools. (sakaiproject#6885)
Browse files Browse the repository at this point in the history
Currently, only assignments uses this.
  • Loading branch information
adrianfish authored May 8, 2019
1 parent 9623b0e commit 3de471f
Show file tree
Hide file tree
Showing 29 changed files with 1,072 additions and 1,254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
import org.sakaiproject.entity.api.EntityPropertyNotDefinedException;
import org.sakaiproject.entity.api.EntityPropertyTypeException;
import org.sakaiproject.entity.api.EntityTransferrer;
import org.sakaiproject.entity.api.EntityTransferrerRefMigrator;
import org.sakaiproject.entity.api.HttpAccess;
import org.sakaiproject.entity.api.Reference;
import org.sakaiproject.entity.api.ResourceProperties;
Expand Down Expand Up @@ -110,7 +109,7 @@
*/
@Slf4j
public abstract class BaseAnnouncementService extends BaseMessage implements AnnouncementService, ContextObserver,
EntityTransferrer, EntityTransferrerRefMigrator
EntityTransferrer
{
/** private constants definitions */
private final static String SAKAI_ANNOUNCEMENT_TOOL_ID = "sakai.announcements";
Expand Down Expand Up @@ -1123,34 +1122,25 @@ public String getLabel()
return "announcement";
}

/**********************************************************************************************************************************************************************************************************************************************************
* getSummaryFromHeader implementation
*********************************************************************************************************************************************************************************************************************************************************/
protected String getSummaryFromHeader(Message item, MessageHeader header)
{
String newText;
if ( header instanceof AnnouncementMessageHeader) {
AnnouncementMessageHeader hdr = (AnnouncementMessageHeader) header;
newText = hdr.getSubject();
} else {
newText = item.getBody();
if ( newText.length() > 50 ) newText = newText.substring(1,49);
}
newText = newText + ", " + header.getFrom().getDisplayName() + ", " + header.getDate().toStringLocalFull();
return newText;
}
protected String getSummaryFromHeader(Message item, MessageHeader header) {

String newText;
if (header instanceof AnnouncementMessageHeader) {
AnnouncementMessageHeader hdr = (AnnouncementMessageHeader) header;
newText = hdr.getSubject();
} else {
newText = item.getBody();
if (newText.length() > 50) newText = newText.substring(1, 49);
}
newText = newText + ", " + header.getFrom().getDisplayName() + ", " + header.getDate().toStringLocalFull();
return newText;
}

/**
* {@inheritDoc}
*/
public void transferCopyEntities(String fromContext, String toContext, List resourceIds)
{
transferCopyEntitiesRefMigrator(fromContext, toContext, resourceIds);
}
public Map<String, String> transferCopyEntities(String fromContext, String toContext, List<String> resourceIds, List<String> options) {

public Map<String, String> transferCopyEntitiesRefMigrator(String fromContext, String toContext, List resourceIds)
{
// Map<String, String> transversalMap = new HashMap<String, String>();
// get the channel associated with this site
String oChannelRef = channelReference(fromContext, SiteService.MAIN_CONTAINER);
AnnouncementChannel oChannel = null;
Expand Down Expand Up @@ -1911,14 +1901,8 @@ public String getSummarizableReference(String siteId, String toolIdentifier)
}
}

public void transferCopyEntities(String fromContext, String toContext, List ids, boolean cleanup)
{
transferCopyEntitiesRefMigrator(fromContext, toContext, ids, cleanup);
}
public Map<String, String> transferCopyEntities(String fromContext, String toContext, List<String> ids, List<String> options, boolean cleanup) {

public Map<String, String> transferCopyEntitiesRefMigrator(String fromContext, String toContext, List ids, boolean cleanup)
{
// Map<String, String> transversalMap = new HashMap<String, String>();
try
{
if(cleanup == true)
Expand Down Expand Up @@ -1954,7 +1938,7 @@ public Map<String, String> transferCopyEntitiesRefMigrator(String fromContext, S
{
log.debug("transferCopyEntities: End removing Announcement data");
}
transferCopyEntitiesRefMigrator(fromContext, toContext, ids);
transferCopyEntities(fromContext, toContext, ids, null);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.EntityManager;
import org.sakaiproject.entity.api.EntityTransferrer;
import org.sakaiproject.entity.api.EntityTransferrerRefMigrator;
import org.sakaiproject.entity.api.HttpAccess;
import org.sakaiproject.entity.api.Reference;
import org.sakaiproject.entity.api.ResourceProperties;
Expand Down Expand Up @@ -175,7 +174,7 @@
*/
@Slf4j
@Transactional(readOnly = true)
public class AssignmentServiceImpl implements AssignmentService, EntityTransferrer, EntityTransferrerRefMigrator, ApplicationContextAware {
public class AssignmentServiceImpl implements AssignmentService, EntityTransferrer, ApplicationContextAware {

@Setter private AnnouncementService announcementService;
@Setter private ApplicationContext applicationContext;
Expand Down Expand Up @@ -3374,21 +3373,14 @@ public void postReviewableSubmissionAttachments(AssignmentSubmission submission)
}
}

@Override
@Transactional
public void transferCopyEntities(String fromContext, String toContext, List<String> ids) {
transferCopyEntitiesRefMigrator(fromContext, toContext, ids);
}

@Override
public String[] myToolIds() {
return new String[] { "sakai.assignment", "sakai.assignment.grades" };
}

@Override
@Transactional
public void transferCopyEntities(String fromContext, String toContext, List<String> ids, boolean cleanup) {
transferCopyEntitiesRefMigrator(fromContext, toContext, ids, cleanup);
public Optional<List<String>> getTransferOptions() {
return Optional.of(Arrays.asList(new String[] { EntityTransferrer.PUBLISH_OPTION }));
}

@Override
Expand Down Expand Up @@ -3427,7 +3419,8 @@ public void updateEntityReferences(String toContext, Map<String, String> transve

@Override
@Transactional
public Map<String, String> transferCopyEntitiesRefMigrator(String fromContext, String toContext, List<String> ids) {
public Map<String, String> transferCopyEntities(String fromContext, String toContext, List<String> ids, List<String> transferOptions) {

Map<String, String> transversalMap = new HashMap<>();
Collection<Assignment> assignments = getAssignmentsForContext(fromContext);

Expand All @@ -3447,8 +3440,11 @@ public Map<String, String> transferCopyEntitiesRefMigrator(String fromContext, S
}
nAssignment.setTypeOfGrade(oAssignment.getTypeOfGrade());
nAssignment.setTypeOfSubmission(oAssignment.getTypeOfSubmission());
// when importing, refer to property to determine draft status
if (serverConfigurationService.getBoolean("import.importAsDraft", true)) {

// User supplied publish option takes precedence, then property, then source.
if (transferOptions != null && transferOptions.contains(EntityTransferrer.PUBLISH_OPTION)) {
nAssignment.setDraft(false);
} else if (serverConfigurationService.getBoolean("import.importAsDraft", true)) {
nAssignment.setDraft(true);
} else {
nAssignment.setDraft(oAssignment.getDraft());
Expand Down Expand Up @@ -3676,7 +3672,8 @@ public Map<String, String> transferCopyEntitiesRefMigrator(String fromContext, S

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

Map<String, String> transversalMap = new HashMap<>();

try {
Expand All @@ -3685,24 +3682,15 @@ public Map<String, String> transferCopyEntitiesRefMigrator(String fromContext, S
for (Assignment assignment : assignments) {
String assignmentId = assignment.getId();

// SecurityAdvisor securityAdvisor = new MySecurityAdvisor(sessionManager.getCurrentSessionUserId(),
// new ArrayList<>(Arrays.asList(SECURE_UPDATE_ASSIGNMENT, SECURE_REMOVE_ASSIGNMENT)),
// assignmentId);
try {
// advisor to allow edit and remove assignment
// securityService.pushAdvisor(securityAdvisor);

// remove this assignment with all its associated items
deleteAssignmentAndAllReferences(assignment);
} catch (Exception e) {
log.warn("Remove assignment and all references for {}, {}", assignmentId, e.getMessage());
} finally {
// remove SecurityAdvisor
// securityService.popAdvisor(securityAdvisor);
}
}
}
transversalMap.putAll(transferCopyEntitiesRefMigrator(fromContext, toContext, ids));
transversalMap.putAll(transferCopyEntities(fromContext, toContext, ids, transferOptions));
} catch (Exception e) {
log.info("End removing Assignmentt data {}", e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
* </p>
*/
@Slf4j
public abstract class BaseCalendarService implements CalendarService, DoubleStorageUser, ContextObserver, EntityTransferrer, SAXEntityReader, EntityTransferrerRefMigrator, Observer
public abstract class BaseCalendarService implements CalendarService, DoubleStorageUser, ContextObserver, EntityTransferrer, SAXEntityReader, Observer
{
/** The initial portion of a relative access point URL. */
protected String m_relativeAccessPoint = null;
Expand Down Expand Up @@ -1864,18 +1864,10 @@ else if (oldUrl.startsWith("/content/group/" + fromSiteId + "/"))
return results.toString();
}

/**
* {@inheritDoc}
*/
public void transferCopyEntities(String fromContext, String toContext, List resourceIds)
{
transferCopyEntitiesRefMigrator(fromContext, toContext, resourceIds);
}
public Map<String, String> transferCopyEntities(String fromContext, String toContext, List<String> resourceIds, List<String> options) {

public Map<String, String> transferCopyEntitiesRefMigrator(String fromContext, String toContext, List resourceIds)
{
Map<String, String> transversalMap = new HashMap<String, String>();

// get the channel associated with this site
String oCalendarRef = calendarReference(fromContext, SiteService.MAIN_CONTAINER);

Expand Down Expand Up @@ -5534,13 +5526,8 @@ public void setServices(Map<String,Object> services) {
m_services = services;
}

public void transferCopyEntities(String fromContext, String toContext, List ids, boolean cleanup)
{
transferCopyEntitiesRefMigrator(fromContext, toContext, ids, cleanup);
}

public Map<String, String> transferCopyEntitiesRefMigrator(String fromContext, String toContext, List ids, boolean cleanup)
{
public Map<String, String> transferCopyEntities(String fromContext, String toContext, List<String> ids, List<String> options, boolean cleanup)
{
Map<String, String> transversalMap = new HashMap<String, String>();
try
{
Expand Down Expand Up @@ -5576,7 +5563,7 @@ public Map<String, String> transferCopyEntitiesRefMigrator(String fromContext, S
}

}
transversalMap.putAll(transferCopyEntitiesRefMigrator(fromContext, toContext, ids));
transversalMap.putAll(transferCopyEntities(fromContext, toContext, ids, null));
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,17 +675,13 @@ public boolean willArchiveMerge()
* 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);
*/
public void transferCopyEntities(String fromContext, String toContext, List ids)
{
try
{
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())
{
Iterator channelIterator = channels.iterator();
while (channelIterator.hasNext())
{
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);
newChannel.setDescription(oldChannel.getDescription());
Expand All @@ -694,22 +690,18 @@ public void transferCopyEntities(String fromContext, String toContext, List ids)
newChannel.setPlacementDefaultChannel(oldChannel.isPlacementDefaultChannel());
try {
getChatManager().updateChannel(newChannel, false);
}
catch (Exception e)
{
} catch (Exception e) {
log.warn("Exception while creating channel: " + newChannel.getTitle() + ": " + e);
}

}
}

transferSynopticOptions(fromContext, toContext);
}

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

return null;
}

/**
Expand Down Expand Up @@ -777,42 +769,30 @@ public void setChatManager(ChatManager chatManager) {
this.chatManager = chatManager;
}

public void transferCopyEntities(String fromContext, String toContext, List ids, boolean cleanup)
{
try
{
if(cleanup == true)
{
// retrieve all of the chat rooms
List channels = getChatManager().getContextChannels(toContext, true);

if (channels != null && !channels.isEmpty())
{
Iterator channelIterator = channels.iterator();

while (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);
}

catch (Exception e)
{
log.debug("Chat transferCopyEntities(): exception in handling " + 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;
}
}
Loading

0 comments on commit 3de471f

Please sign in to comment.