2727import org .apache .solr .common .SolrDocument ;
2828import org .apache .solr .common .SolrInputDocument ;
2929import org .dspace .authorize .AuthorizeException ;
30- import org .dspace .content .Item ;
3130import org .dspace .content .MetadataValue ;
3231import org .dspace .content .factory .ContentServiceFactory ;
3332import org .dspace .core .Context ;
@@ -43,34 +42,39 @@ public class AuthorityValue {
4342 /**
4443 * The id of the record in solr
4544 */
46- private String id ;
45+ protected String id ;
4746
4847 /**
4948 * The metadata field that this authority value is for
5049 */
51- private String field ;
50+ protected String field ;
5251
5352 /**
5453 * The text value of this authority
5554 */
56- private String value ;
55+ protected String value ;
5756
5857 /**
5958 * When this authority record has been created
6059 */
61- private Date creationDate ;
60+ protected Date creationDate ;
6261
6362 /**
6463 * If this authority has been removed
6564 */
66- private boolean deleted ;
65+ protected boolean deleted ;
6766
6867 /**
6968 * represents the last time that DSpace got updated information from its external source
7069 */
71- private Date lastModified ;
70+ protected Date lastModified ;
7271
73- private Map <String , List <String >> otherMetadataMap ;
72+ protected Map <String , List <String >> otherMetadataMap ;
73+
74+ /**
75+ * log4j logger
76+ */
77+ private static final Logger log = LogManager .getLogger ();
7478
7579 public AuthorityValue () {
7680 this .otherMetadataMap = new LinkedHashMap <>();
@@ -150,7 +154,8 @@ public void delete() {
150154 }
151155
152156 /**
153- * Generate a solr record from this instance
157+ * Generate a Solr record from this instance. The otherMetadataMap values will be iterated
158+ * and added with a label_ prefix
154159 *
155160 * @return SolrInputDocument
156161 */
@@ -176,7 +181,9 @@ public SolrInputDocument getSolrInputDocument() {
176181 }
177182
178183 /**
179- * Initialize this instance based on a solr record
184+ * Set values for this AuthorityValue based on a Solr record.
185+ * Any supplementary information saved with the label_ prefix will be added to the
186+ * otherMetadataMap with the label_ prefix stripped.
180187 *
181188 * @param document SolrDocument
182189 */
@@ -190,34 +197,33 @@ public void setValues(SolrDocument document) {
190197 // Set other metadata
191198 for (String key : document .getFieldNames ()) {
192199 if (key .startsWith ("label_" )) {
193- String gndKey = key .replace ("label_" , "" );
200+ String otherMetadataKey = key .replace ("label_" , "" );
194201 Collection <Object > values = document .getFieldValues (key );
195202 if (values != null ) {
196203 Collection <String > stringValues = (Collection <String >) (Object ) values ;
197- otherMetadataMap .put (gndKey , new ArrayList <>(stringValues ));
204+ otherMetadataMap .put (otherMetadataKey , new ArrayList <>(stringValues ));
198205 }
199206 }
200207 }
201208 }
202209
203210 /**
204- * Replace an item's DCValue with this authority
211+ * Replace an item's DCValue with this authority value and key
205212 *
206213 * @param context context
207214 * @param value metadata value
208- * @param currentItem item
209215 * @throws SQLException if database error
210216 * @throws AuthorizeException if authorization error
211217 */
212- public void updateItem (Context context , Item currentItem , MetadataValue value )
218+ public void updateItem (Context context , MetadataValue value )
213219 throws SQLException , AuthorizeException {
214220 value .setValue (getValue ());
215221 value .setAuthority (getId ());
216222 ContentServiceFactory .getInstance ().getMetadataValueService ().update (context , value , true );
217223 }
218224
219225 /**
220- * Information that can be used the choice ui.
226+ * Information that can be used with the ChoiceAuthority UI
221227 *
222228 * @return map
223229 */
@@ -229,7 +235,7 @@ public Map<String, String> choiceSelectMap() {
229235 * Build a list of ISO date formatters to parse various forms.
230236 *
231237 * <p><strong>Note:</strong> any formatter which does not parse a zone or
232- * offset must have a default zone set. See {@link stringToDate}.
238+ * offset must have a default zone set. See {@link # stringToDate}.
233239 *
234240 * @return the formatters.
235241 */
@@ -267,20 +273,39 @@ static public Date stringToDate(String date) {
267273 }
268274
269275 /**
270- * log4j logger
276+ * Set a key-value pair in the otherMetadataMap.
277+ *
278+ * @param key the key for the metadata entry
279+ * @param value the value for the metadata entry
271280 */
272- private static Logger log = LogManager .getLogger ();
281+ public void setMetadataMapEntry (String key , String value ) {
282+ List <String > values ;
283+ if (!this .otherMetadataMap .containsKey (key )) {
284+ values = new ArrayList <>();
285+ } else {
286+ values = this .otherMetadataMap .get (key );
287+ }
288+ values .add (value );
289+ this .otherMetadataMap .put (key , values );
290+ }
273291
274- @ Override
275- public String toString () {
276- return "AuthorityValue{" +
277- "id='" + id + '\'' +
278- ", field='" + field + '\'' +
279- ", value='" + value + '\'' +
280- ", creationDate=" + creationDate +
281- ", deleted=" + deleted +
282- ", lastModified=" + lastModified +
283- '}' ;
292+ /**
293+ * Retrieves the other metadata map of the AuthorityValue object.
294+ * In the solr document this is in the form of label_{dc.example.field}
295+ *
296+ * @return the other metadata map of the AuthorityValue object
297+ */
298+ public Map <String , List <String >> getOtherMetadataMap () {
299+ return otherMetadataMap ;
300+ }
301+
302+ /**
303+ * Set the other metadata map
304+ *
305+ * @param otherMetadataMap the map of fields and values
306+ */
307+ public void setOtherMetadataMap (Map <String , List <String >> otherMetadataMap ) {
308+ this .otherMetadataMap = otherMetadataMap ;
284309 }
285310
286311 /**
@@ -335,9 +360,6 @@ public boolean hasTheSameInformationAs(Object o) {
335360 if (deleted != that .deleted ) {
336361 return false ;
337362 }
338- if (field != null ? !field .equals (that .field ) : that .field != null ) {
339- return false ;
340- }
341363 if (id != null ? !id .equals (that .id ) : that .id != null ) {
342364 return false ;
343365 }
@@ -348,22 +370,15 @@ public boolean hasTheSameInformationAs(Object o) {
348370 return true ;
349371 }
350372
351- public void setMetadataMapEntry (String key , String value ) {
352- List <String > values ;
353- if (!this .otherMetadataMap .containsKey (key )) {
354- values = new ArrayList <>();
355- } else {
356- values = this .otherMetadataMap .get (key );
357- }
358- values .add (value );
359- this .otherMetadataMap .put (key , values );
360- }
361-
362- public Map <String , List <String >> getOtherMetadataMap () {
363- return otherMetadataMap ;
364- }
365-
366- public void setOtherMetadataMap (Map <String , List <String >> otherMetadataMap ) {
367- this .otherMetadataMap = otherMetadataMap ;
373+ @ Override
374+ public String toString () {
375+ return "AuthorityValue{" +
376+ "id='" + id + '\'' +
377+ ", field='" + field + '\'' +
378+ ", value='" + value + '\'' +
379+ ", creationDate=" + creationDate +
380+ ", deleted=" + deleted +
381+ ", lastModified=" + lastModified +
382+ '}' ;
368383 }
369384}
0 commit comments