PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/atlassian/jconnect/jira/customfields/LocationIndexer.java

https://bitbucket.org/atlassian/jiraconnect-jiraplugin/
Java | 61 lines | 41 code | 13 blank | 7 comment | 2 complexity | cdc925897ec6aeb9cd076c8b53177294 MD5 | raw file
  1. package com.atlassian.jconnect.jira.customfields;
  2. import com.atlassian.jira.issue.Issue;
  3. import com.atlassian.jira.issue.customfields.converters.DoubleConverter;
  4. import com.atlassian.jira.issue.fields.CustomField;
  5. import com.atlassian.jira.issue.index.indexers.impl.AbstractCustomFieldIndexer;
  6. import com.atlassian.jira.web.FieldVisibilityManager;
  7. import org.apache.lucene.document.Document;
  8. import org.apache.lucene.document.Field;
  9. import static com.atlassian.jira.util.dbc.Assertions.notNull;
  10. /**
  11. * Indexer for location custom field.
  12. *
  13. * @see LocationCFType
  14. */
  15. public class LocationIndexer extends AbstractCustomFieldIndexer {
  16. public static String latFieldId(String locationFieldId) {
  17. return locationFieldId + "-lat";
  18. }
  19. public static String lngFieldId(String locationFieldId) {
  20. return locationFieldId + "-lng";
  21. }
  22. private final CustomField field;
  23. private final DoubleConverter doubleConverter;
  24. public LocationIndexer(FieldVisibilityManager fieldVisibilityManager, CustomField customField,
  25. DoubleConverter doubleConverter) {
  26. super(fieldVisibilityManager, notNull("field", customField));
  27. this.field = customField;
  28. this.doubleConverter = doubleConverter;
  29. }
  30. @Override
  31. public void addDocumentFieldsSearchable(Document doc, Issue issue) {
  32. addDocumentFields(doc, issue, Field.Index.NOT_ANALYZED);
  33. }
  34. @Override
  35. public void addDocumentFieldsNotSearchable(Document doc, Issue issue) {
  36. addDocumentFields(doc, issue, Field.Index.NO);
  37. }
  38. // TODO this sucks, we should be using NumericField (as of JIRA 4.4)
  39. private void addDocumentFields(Document doc, Issue issue, Field.Index index) {
  40. Object value = field.getValue(issue);
  41. if (value != null) {
  42. // TODO we need to normalize cause those guys do not support negative numbers. hopefully NumericField does!
  43. final Location location = ((Location) value).normalize();
  44. doc.add(new Field(latFieldId(getDocumentFieldId()), doubleConverter.getStringForLucene(location.lat), Field.Store.YES, index));
  45. doc.add(new Field(lngFieldId(getDocumentFieldId()), doubleConverter.getStringForLucene(location.lng), Field.Store.YES, index));
  46. }
  47. }
  48. }