Skip to content

Commit

Permalink
Log external link views as attachment views (#1322)
Browse files Browse the repository at this point in the history
Also show view count on link attachments that was never shown before
  • Loading branch information
abidingotter authored and PenghaiZhang committed Nov 20, 2019
1 parent 68f3715 commit 7ddc924
Show file tree
Hide file tree
Showing 18 changed files with 185 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public void setMd5sum(String md5sum) {
this.md5sum = md5sum;
}

@Override
public Item getItem() {
return item;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.tle.beans.item.attachments;

import com.tle.beans.item.IItem;
import java.util.Map;

public interface IAttachment {
Expand Down Expand Up @@ -64,4 +65,6 @@ public interface IAttachment {
void setRestricted(boolean restricted);

boolean isRestricted();

IItem<?> getItem();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,7 @@ linkresource.details.status.good=Good
linkresource.details.status.unknown=Unknown
linkresource.details.type=Type\:
linkresource.details.url=URL\:
linkresource.details.views=Views\:
links.edit=Edit custom links
links.ordering=The links can be reordered by dragging and dropping them in the desired positions. A page refresh is required to see the updated links in the menu.
list.add=Add a resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.tle.beans.Institution;
import com.tle.beans.item.Item;
import com.tle.beans.item.ItemKey;
import com.tle.beans.item.attachments.Attachment;
import com.tle.beans.item.attachments.IAttachment;
import com.tle.common.usermanagement.user.UserState;
import com.tle.common.usermanagement.user.WebAuthenticationDetails;
import java.util.Collection;
Expand Down Expand Up @@ -74,13 +74,11 @@ public interface AuditLogService {
void logContentViewed(
String category, ItemKey itemId, String contentType, String path, HttpServletRequest request);

// void logItemContentViewed(ItemKey itemId, String contentType, String path);

void logItemContentViewed(
ItemKey itemId,
String contentType,
String path,
Attachment attachment,
IAttachment attachment,
HttpServletRequest request);

void logItemPurged(Item item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.tle.beans.Institution;
import com.tle.beans.item.Item;
import com.tle.beans.item.ItemKey;
import com.tle.beans.item.attachments.Attachment;
import com.tle.beans.item.attachments.IAttachment;
import com.tle.common.institution.CurrentInstitution;
import com.tle.common.usermanagement.user.CurrentUser;
import com.tle.common.usermanagement.user.UserState;
Expand Down Expand Up @@ -180,7 +180,7 @@ public void logItemContentViewed(
ItemKey itemId,
String contentType,
String path,
Attachment attachment,
IAttachment attachment,
HttpServletRequest request) {
logContentViewed(ITEM_CATEGORY, itemId, contentType, path, request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import java.util.Map;

public class CloudAttachment implements IAttachment, Serializable {
public static final String TYPE_FILE = "file";
public static final String TYPE_URL = "url";

private CloudItem item;
private String uuid;
private String description;
private String filename;
Expand Down Expand Up @@ -174,4 +174,13 @@ public void setRestricted(boolean restricted) {
public boolean isRestricted() {
return false;
}

@Override
public CloudItem getItem() {
return item;
}

public void setItem(CloudItem item) {
this.item = item;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ private CloudItem convertCloudItemBean(CloudItemBean cib) {
new Function<CloudAttachmentBean, CloudAttachment>() {
@Override
public CloudAttachment apply(CloudAttachmentBean cab) {
return convertCloudAttachmentBean(cab);
return convertCloudAttachmentBean(cab, cloudItem);
}
})));

Expand All @@ -581,8 +581,9 @@ public CloudAttachment apply(CloudAttachmentBean cab) {
return cloudItem;
}

private CloudAttachment convertCloudAttachmentBean(CloudAttachmentBean cab) {
private CloudAttachment convertCloudAttachmentBean(CloudAttachmentBean cab, CloudItem cloudItem) {
final CloudAttachment cloudAttachment = new CloudAttachment();
cloudAttachment.setItem(cloudItem);
cloudAttachment.setType(cab.getType());
cloudAttachment.setUuid(cab.getUuid());
cloudAttachment.setDescription(cab.getDescription());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
package com.tle.web.cloud.search;

import com.dytech.devlib.PropBagEx;
import com.google.common.collect.Maps;
import com.tle.annotation.NonNullByDefault;
import com.tle.beans.item.attachments.AttachmentType;
import com.tle.beans.item.attachments.IAttachment;
import com.tle.beans.item.attachments.UnmodifiableAttachments;
import com.tle.core.cloud.beans.converted.CloudItem;
import com.tle.core.guice.Bind;
Expand All @@ -43,8 +40,6 @@
import com.tle.web.sections.standard.model.SimpleBookmark;
import com.tle.web.sections.standard.renderers.LinkRenderer;
import com.tle.web.viewable.ViewableItem;
import java.util.Collections;
import java.util.Map;
import javax.inject.Inject;

/** @author Aaron */
Expand Down Expand Up @@ -124,127 +119,4 @@ protected void setupMetadata(RenderContext context) {
new StdMetadataEntry(LABEL_MODIFIED, JQueryTimeAgo.timeAgoTag(item.getDateModified())));
}
}

@NonNullByDefault(false)
public static class CloudAttachmentDisplay implements IAttachment {
private String uuid;
private String url;
private String description;
private String thumbnail;
private Map<String, Object> data = Maps.newHashMap();
private String md5sum;
private String viewer;
private boolean preview;
private boolean restricted;

@Override
public String getUuid() {
return uuid;
}

@Override
public void setUuid(String uuid) {
this.uuid = uuid;
}

@Override
public String getUrl() {
return url;
}

@Override
public void setUrl(String url) {
this.url = url;
}

@Override
public String getDescription() {
return description;
}

@Override
public void setDescription(String description) {
this.description = description;
}

@Override
public String getThumbnail() {
return thumbnail;
}

@Override
public void setThumbnail(String thumbnail) {
this.thumbnail = thumbnail;
}

@Override
public String getMd5sum() {
return md5sum;
}

@Override
public void setMd5sum(String md5sum) {
this.md5sum = md5sum;
}

@Override
public String getViewer() {
return viewer;
}

@Override
public void setViewer(String viewer) {
this.viewer = viewer;
}

@Override
public boolean isPreview() {
return preview;
}

@Override
public void setPreview(boolean preview) {
this.preview = preview;
}

@Override
public void setData(String name, Object value) {
data.put(name, value);
}

@Override
public Object getData(String name) {
return data.get(name);
}

@Override
public Map<String, Object> getDataAttributesReadOnly() {
return Collections.unmodifiableMap(data);
}

@Override
public Map<String, Object> getDataAttributes() {
return data;
}

@Override
public void setDataAttributes(Map<String, Object> data) {
this.data = data;
}

@Override
public AttachmentType getAttachmentType() {
return AttachmentType.CUSTOM;
}

@Override
public void setRestricted(boolean restricted) {
this.restricted = restricted;
}

@Override
public boolean isRestricted() {
return restricted;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ public String getFilenameWithoutPath() {
return SectionUtils.getFilenameFromFilepath(topLevel.getFilepath());
}

@Nullable
@Override
public IAttachment getAttachment() {
return null;
}

@Override
public final int getForwardCode() {
return 302;
Expand Down Expand Up @@ -346,6 +352,12 @@ public String getFilepath() {
return viewableResource.getFilepath();
}

@Nullable
@Override
public IAttachment getAttachment() {
return viewableResource.getAttachment();
}

@Override
public ViewAuditEntry getViewAuditEntry() {
return viewableResource.getViewAuditEntry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.tle.web.viewitem;

import com.tle.beans.item.attachments.IAttachment;
import com.tle.common.Check;
import com.tle.web.sections.Bookmark;
import com.tle.web.stream.ContentStream;
Expand Down Expand Up @@ -79,6 +80,11 @@ public boolean isPathMapped() {

@Override
public boolean isRestrictedResource() {
return viewableResource.getAttachment().isRestricted();
return getAttachment().isRestricted();
}

@Override
public IAttachment getAttachment() {
return viewableResource.getAttachment();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.tle.beans.item.Item;
import com.tle.beans.item.ItemKey;
import com.tle.beans.item.attachments.Attachment;
import com.tle.beans.item.attachments.IAttachment;
import com.tle.core.auditlog.AuditLogService;
import com.tle.core.guice.Bind;
import com.tle.core.item.service.ItemService;
Expand Down Expand Up @@ -64,7 +65,7 @@ public void audit(
HttpServletRequest request,
ViewAuditEntry auditEntry,
ItemKey itemId,
Attachment attachment) {
IAttachment attachment) {
audit(request, auditEntry, itemId, () -> logViewed(itemId, attachment, auditEntry));
}

Expand Down Expand Up @@ -115,15 +116,16 @@ private String key(ItemKey itemId, ViewAuditEntry auditEntry) {
+ itemId;
}

private void logViewed(ItemKey itemId, Attachment attachment, ViewAuditEntry entry) {
private void logViewed(ItemKey itemId, IAttachment attachment, ViewAuditEntry entry) {
auditService.logItemContentViewed(
itemId,
entry.getContentType(),
entry.getPath(),
attachment,
sessionService.getAssociatedRequest());
if (attachment != null) {
itemService.incrementViews(attachment);
// This only applies to local items (and hence local attachments), not cloud ones
if (attachment != null && attachment instanceof Attachment) {
itemService.incrementViews((Attachment) attachment);
}
}

Expand Down
Loading

0 comments on commit 7ddc924

Please sign in to comment.