Skip to content

Commit

Permalink
new indexing rules now that we have deaccessioning #4031
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Jul 8, 2014
1 parent 429099c commit 157cf23
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 88 deletions.
318 changes: 240 additions & 78 deletions src/main/java/edu/harvard/iq/dataverse/IndexServiceBean.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ public void search(boolean onlyDataRelatedToMe) {
Long datasetVersionId = solrSearchResult.getDatasetVersionId();
if (datasetVersionId != null) {
DatasetVersion datasetVersion = datasetVersionService.find(datasetVersionId);
if (datasetVersion.isDeaccessioned()) {
solrSearchResult.setDeaccessionedState(true);
}
if (datasetVersion != null) {
String citation = datasetVersion.getCitation();
if (citation != null) {
Expand Down Expand Up @@ -856,6 +859,10 @@ public String getDRAFT() {
return IndexServiceBean.getDRAFT_STRING();
}

public String getDEACCESSIONED() {
return IndexServiceBean.getDEACCESSIONED_STRING();
}

public List<String> getFriendlyNamesFromFilterQuery(String filterQuery) {
String[] parts = filterQuery.split(":");
String key = parts[0];
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/edu/harvard/iq/dataverse/SearchServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,15 @@ public SolrQueryResponse search(DataverseUser dataverseUser, Dataverse dataverse
* @todo put all this in the constructor?
*/
List<String> states = (ArrayList<String>) solrDocument.getFieldValue(SearchFields.PUBLICATION_STATUS);
for (String state : states) {
if (state.equals(IndexServiceBean.getUNPUBLISHED_STRING())) {
solrSearchResult.setUnpublishedState(true);
} else if (state.equals(IndexServiceBean.getDRAFT_STRING())) {
solrSearchResult.setDraftState(true);
if (states != null) {
for (String state : states) {
if (state.equals(IndexServiceBean.getUNPUBLISHED_STRING())) {
solrSearchResult.setUnpublishedState(true);
} else if (state.equals(IndexServiceBean.getDRAFT_STRING())) {
solrSearchResult.setDraftState(true);
// } else if (state.equals(IndexServiceBean.getDEACCESSIONED_STRING())) {
// solrSearchResult.setDeaccessionedState(true);
}
}
}
// logger.info(id + ": " + description);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/SolrSearchResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class SolrSearchResult {
// private boolean statePublished;
private boolean unpublishedState;
private boolean draftState;
private boolean deaccessionedState;
private long datasetVersionId;

// public boolean isStatePublished() {
Expand All @@ -68,6 +69,14 @@ public boolean isDraftState() {
public void setDraftState(boolean draftState) {
this.draftState = draftState;
}

public boolean isDeaccessionedState() {
return deaccessionedState;
}

public void setDeaccessionedState(boolean deaccessionedState) {
this.deaccessionedState = deaccessionedState;
}
/**
* @todo: used? remove
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void executeImpl(CommandContext ctxt) throws CommandException {
}
FileMetadata doomedAndMerged = ctxt.em().merge(fmr);
ctxt.em().remove(doomedAndMerged);
String indexingResult = ctxt.index().removeDraftFromIndex(IndexServiceBean.solrDocIdentifierFile + doomed.getId() + "_draft");
String indexingResult = ctxt.index().removeSolrDocFromIndex(IndexServiceBean.solrDocIdentifierFile + doomed.getId() + "_draft");
return;
}
throw new IllegalCommandException("Cannot delete a released file", this);
Expand Down Expand Up @@ -128,7 +128,7 @@ protected void executeImpl(CommandContext ctxt) throws CommandException {
*
* See also https://redmine.hmdc.harvard.edu/issues/3786
*/
String indexingResult = ctxt.index().removeDraftFromIndex(IndexServiceBean.solrDocIdentifierFile + doomed.getId() + "_draft");
String indexingResult = ctxt.index().removeSolrDocFromIndex(IndexServiceBean.solrDocIdentifierFile + doomed.getId() + "_draft");
/**
* @todo check indexing result for success or failure. Really, we
* need an indexing queuing system:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected void executeImpl(CommandContext ctxt) throws CommandException {
ctxt.em().remove(managedDoomed);

//remove from index
String indexingResult = ctxt.index().removeDraftFromIndex(IndexServiceBean.solrDocIdentifierDataset + doomed.getId() + IndexServiceBean.draftSuffix);
String indexingResult = ctxt.index().removeSolrDocFromIndex(IndexServiceBean.solrDocIdentifierDataset + doomed.getId() + IndexServiceBean.draftSuffix);

ctxt.index().indexDataverse(toReIndex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class IndexableDataset extends IndexableObject {

DatasetState datasetState;
boolean filesShouldBeIndexed;

private final DatasetVersion datasetVersion;

Expand All @@ -14,11 +15,20 @@ public IndexableDataset(DatasetVersion datasetVersion) {
super.setType(IndexableObject.IndexableTypes.DATASET.getName());
if (datasetVersion.isWorkingCopy()) {
this.datasetState = DatasetState.WORKING_COPY;
} else {
this.filesShouldBeIndexed = true;
} else if (datasetVersion.isReleased()) {
this.datasetState = DatasetState.PUBLISHED;
this.filesShouldBeIndexed = true;
} else if (datasetVersion.isDeaccessioned()) {
this.datasetState = DatasetState.DEACCESSIONED;
this.filesShouldBeIndexed = false;
}
}

public boolean isFilesShouldBeIndexed() {
return filesShouldBeIndexed;
}

public DatasetVersion getDatasetVersion() {
return datasetVersion;
}
Expand All @@ -33,7 +43,7 @@ public DatasetState getDatasetState() {

public enum DatasetState {

WORKING_COPY(IndexServiceBean.draftSuffix), PUBLISHED("");
WORKING_COPY(IndexServiceBean.draftSuffix), PUBLISHED(""), DEACCESSIONED(IndexServiceBean.deaccessionedSuffix);

private String suffix;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package edu.harvard.iq.dataverse.search;

import edu.harvard.iq.dataverse.IndexServiceBean;

public abstract class IndexableObject {

private String type;
Expand All @@ -14,6 +16,9 @@ public void setType(String type) {

public enum IndexableTypes {

/**
* @todo reconcile with IndexServiceBean.solrDocIdentifierDataset et al.
*/
DATAVERSE("dataverse"), DATASET("dataset"), DATAFILE("datafile"), GROUP("group");

private String name;
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/search-include-fragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@
</h:outputLink>
<h:outputText value="#{SearchIncludeFragment.DRAFT}" styleClass="label label-warning" rendered="#{result.draftState}"/>
<h:outputText value="#{SearchIncludeFragment.UNPUBLISHED}" styleClass="label label-danger" rendered="#{result.unpublishedState}"/>
<h:outputText value="#{SearchIncludeFragment.DEACCESSIONED}" styleClass="label label-info" rendered="#{result.deaccessionedState}"/>
</div>
<!--<span class="label label-default">Default</span>-->
<div style="width:48px; float:left; margin:4px 12px 6px 0;">
Expand Down

0 comments on commit 157cf23

Please sign in to comment.