001/* 002 * (C) Copyright 2010-2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Olivier Grisel 018 */ 019package org.nuxeo.ecm.platform.suggestbox.service; 020 021import java.io.Serializable; 022 023/** 024 * Base class for building data transfer objects for results of requests to the SuggestionService. 025 * 026 * @author ogrisel 027 */ 028public abstract class Suggestion implements Serializable { 029 030 public static final String DATE_FORMAT_PATTERN = "yyyy-MM-dd"; 031 032 private static final long serialVersionUID = 1L; 033 034 protected final String id; 035 036 protected final String type; 037 038 protected final String label; 039 040 protected final String iconURL; 041 042 protected String description = ""; 043 044 protected boolean disabled = false; 045 046 public Suggestion(String id, String type, String label, String iconURL) { 047 this.id = id; 048 this.type = type; 049 this.label = label; 050 this.iconURL = iconURL; 051 } 052 053 /** 054 * The id of the object associated to the suggestion. 055 * 056 * @since 6.0 057 */ 058 public String getId() { 059 return id; 060 } 061 062 /** 063 * A string marker to give the type (i.e. category) of the suggested user action / intent. The type is used to 064 * broadcast the selected suggestion to the correct handler. 065 */ 066 public String getType() { 067 return type; 068 } 069 070 /** 071 * The i18n label to display to the user for this suggestion. 072 */ 073 public String getLabel() { 074 return label; 075 } 076 077 /** 078 * Relative URL path to download an icon (can represent the type of suggestion or the specific instance such as the 079 * mimetype icon of a document suggestion or the avatar icon of a user profile suggestion). 080 */ 081 public String getIconURL() { 082 return iconURL; 083 } 084 085 public String getDescription() { 086 return description; 087 } 088 089 public Suggestion withDescription(String description) { 090 this.description = description; 091 return this; 092 } 093 094 /** 095 * Disabled suggestions can be useful to display suggestions that might have been relevant if the context was 096 * slightly different (e.g. if the user was logged in instead of anonymous): the UI should not make them selectable 097 * but the description should give information to the user on how to make that suggestion enabled (e.g. by logging 098 * in). The SuggestionService will throw an exception if the user selects a disabled suggestion. 099 */ 100 public boolean getIsDisabled() { 101 return disabled; 102 } 103 104 public Suggestion disable() { 105 this.disabled = true; 106 return this; 107 } 108 109 /** 110 * @return the url to access to the object. It used by the navigation in the select2. 111 * @since 6.0 112 */ 113 public abstract String getObjectUrl(); 114 115 @Override 116 public String toString() { 117 return String.format("Suggestion(\"%s\", \"%s\", \"%s\")", type, label, iconURL); 118 } 119}