Skip to content

Commit

Permalink
SAK-43002 Indexed announcement results now have portal urls (sakaipro…
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish authored Jan 15, 2020
1 parent a3b9031 commit e65db6b
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Stack;
import java.util.Set;

Expand Down Expand Up @@ -133,12 +134,11 @@ public abstract class BaseAnnouncementService extends BaseMessage implements Ann
@Resource(name="org.sakaiproject.util.api.LinkMigrationHelper")
private LinkMigrationHelper linkMigrationHelper;


/**********************************************************************************************************************************************************************************************************************************************************
* Constructors, Dependencies and their setter methods
*********************************************************************************************************************************************************************************************************************************************************/




/** Dependency: NotificationService. */
protected NotificationService m_notificationService = null;
Expand Down Expand Up @@ -1809,6 +1809,7 @@ public void setSubject(String subject)

} // setSubject


/**
* Serialize the resource into XML, adding an element to the doc under the top of the stack element.
*
Expand Down Expand Up @@ -1945,4 +1946,31 @@ public Map<String, String> transferCopyEntities(String fromContext, String toCon
public void clearMessagesCache(String channelRef){
m_threadLocalManager.set(channelRef + ".msgs", null);
}

public Optional<String> getEntityUrl(Reference r, Entity.UrlType urlType) {

//Reference r = getReference(ref);
if (Entity.UrlType.PORTAL == urlType) {
if (r != null) {
String siteId = r.getContext();
Site site;
try {
site = m_siteService.getSite(siteId);
ToolConfiguration tc = site.getToolForCommonId("sakai.announcements");
if (tc != null) {
return Optional.of(m_serverConfigurationService.getPortalUrl() + "/directtool/" + tc.getId()
+ "?itemReference=" + r.getReference() + "&sakai_action=doShowmetadata");
} else {
log.error("No announcements tool in site {}", siteId);
}
} catch (IdUnusedException iue) {
log.error("Failed to get site site for id {}", siteId);
}
} else {
log.error("Failed to get reference for {}", r.getReference());
}
}

return Optional.of(super.getEntityUrl(r));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public interface Entity
/** The character used to separate names in the region address path */
static final String SEPARATOR = "/";

enum UrlType { PORTAL };

/**
* Access the URL which can be used to access the entity.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package org.sakaiproject.entity.api;

import java.util.List;
import java.util.Optional;

/**
* <p>
Expand Down Expand Up @@ -89,4 +90,8 @@ public interface EntityManager
* @return true if the reference is valid, false if not.
*/
boolean checkReference(String ref);

default Optional<String> getUrl(String ref, Entity.UrlType urlType) {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.Stack;

Expand Down Expand Up @@ -136,6 +137,10 @@ String merge(String siteId, Element root, String archivePath, String fromSiteId,
*/
String getEntityUrl(Reference ref);

default Optional<String> getEntityUrl(Reference ref, Entity.UrlType urlType) {
return Optional.of(getEntityUrl(ref));
}

/**
* Access a collection of authorization group ids for security on the for the referenced entity - the entity will belong to the service.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

import lombok.extern.slf4j.Slf4j;

import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.EntityManager;
import org.sakaiproject.entity.api.EntityProducer;
import org.sakaiproject.entity.api.Reference;
Expand Down Expand Up @@ -144,17 +146,17 @@ public void iterateEnd()
}

/** Set of EntityProducer services. */
protected ConcurrentHashMap<String, EntityProducer> m_producersIn = new ConcurrentHashMap<String, EntityProducer>();
protected ConcurrentHashMap<String, EntityProducer> m_producersIn = new ConcurrentHashMap<>();

protected ConcurrentHashMap<EntityProducer, Calls> m_performanceIn = new ConcurrentHashMap<EntityProducer, Calls>();
protected ConcurrentHashMap<EntityProducer, Calls> m_performanceIn = new ConcurrentHashMap<>();

protected ConcurrentHashMap<String, String> m_rejectRefIn = new ConcurrentHashMap<String, String>();
protected ConcurrentHashMap<String, String> m_rejectRefIn = new ConcurrentHashMap<>();

protected Map<String, EntityProducer> m_producers = new HashMap<String, EntityProducer>();
protected Map<String, EntityProducer> m_producers = new HashMap<>();

protected Map<EntityProducer, Calls> m_performance = new HashMap<EntityProducer, Calls>();
protected Map<EntityProducer, Calls> m_performance = new HashMap<>();

private Map<String, String> m_rejectRef = new HashMap<String, String>();
private Map<String, String> m_rejectRef = new HashMap<>();

private int nparse = 0;

Expand All @@ -181,7 +183,7 @@ public void init()
// resolution
m_rejectRefIn.put("library", "library");

m_rejectRef = new HashMap<String, String>(m_rejectRefIn);
m_rejectRef = new HashMap<>(m_rejectRefIn);
log.info("init()");
}
catch (Exception t)
Expand Down Expand Up @@ -231,8 +233,8 @@ public void registerEntityProducer(EntityProducer manager, String referenceRoot)
m_producersIn.put(referenceRoot, manager);
m_performanceIn.put(manager, new Calls(manager));

m_producers = new HashMap<String, EntityProducer>(m_producersIn);
m_performance = new HashMap<EntityProducer, Calls>(m_performanceIn);
m_producers = new HashMap<>(m_producersIn);
m_performance = new HashMap<>(m_performanceIn);
}

/**
Expand Down Expand Up @@ -312,6 +314,13 @@ public boolean checkReference(String ref)
return true;
}

public Optional<String> getUrl(String ref, Entity.UrlType urlType) {

Reference r = newReference(ref);
EntityProducer ep = r.getEntityProducer();
return ep.getEntityUrl(r, urlType);
}

public EntityProducer getEntityProducer(String reference, Reference target)
{
if ( log.isDebugEnabled() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.EntityManager;
import org.sakaiproject.entity.api.EntityProducer;
import org.sakaiproject.entity.api.Reference;
Expand Down Expand Up @@ -131,7 +132,7 @@ public Reader getContentReader(String reference)
return new StringReader(getContent(reference));
}

private Reference getReference(String reference)
protected Reference getReference(String reference)
{
try
{
Expand Down Expand Up @@ -350,6 +351,10 @@ public String getUrl(String reference)
return ref.getUrl();
}

public String getUrl(String ref, Entity.UrlType urlType) {
return entityManager.getUrl(ref, urlType).orElse("");
}

/**
* @{inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.elasticsearch.index.query.OrFilterBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.event.api.Event;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.search.api.EntityContentProducer;
Expand Down Expand Up @@ -207,7 +208,7 @@ protected XContentBuilder addFields(XContentBuilder contentSourceBuilder, String
return contentSourceBuilder.field(SearchService.FIELD_SITEID, ecp.getSiteId(resourceName))
.field(SearchService.FIELD_TITLE, ecp.getTitle(resourceName))
.field(SearchService.FIELD_REFERENCE, resourceName)
.field(SearchService.FIELD_URL, ecp.getUrl(resourceName))
.field(SearchService.FIELD_URL, ecp.getUrl(resourceName, Entity.UrlType.PORTAL))
//.field(SearchService.FIELD_ID, ecp.getId(resourceName))
.field(SearchService.FIELD_TOOL, ecp.getTool())
.field(SearchService.FIELD_CONTAINER, ecp.getContainer(resourceName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Iterator;
import java.util.Map;

import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.event.api.Event;
import org.sakaiproject.search.model.SearchBuilderItem;

Expand All @@ -37,7 +38,6 @@
*/
public interface EntityContentProducer
{

/**
* Should the consumer use the reader or is it OK to use a memory copy of
* the content
Expand Down Expand Up @@ -80,6 +80,10 @@ public interface EntityContentProducer
*/
String getUrl(String reference);

default String getUrl(String reference, Entity.UrlType urlType) {
return this.getUrl(reference);
}

/**
* If the reference matches this EntityContentProducer return true
*
Expand Down

0 comments on commit e65db6b

Please sign in to comment.