Skip to content

Commit

Permalink
started fixing indexing (dv and ds only) #734
Browse files Browse the repository at this point in the history
- can't fix file indexing until dataset page works or sword auth works
  • Loading branch information
pdurbin committed Sep 8, 2014
1 parent ab64b2f commit 7a53c3c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 40 deletions.
6 changes: 3 additions & 3 deletions scripts/search/create
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ FILESDIR='data/in/files'

#rm data/in/dataverses/1
for i in `ls $DVDIR_ROOT`; do
curl -s -H "Content-type:application/json" -X POST -d @$DVDIR_ROOT/$i "http://localhost:8080/api/dvs/root?key=pete"
curl -s -H "Content-type:application/json" -X POST -d @$DVDIR_ROOT/$i "http://localhost:8080/api/dvs/root?key=$PETEKEY"
done

for i in `ls $DVDIR_BIRDS`; do
curl -s -H "Content-type:application/json" -X POST -d @$DVDIR_BIRDS/$i "http://localhost:8080/api/dvs/birds?key=pete"
curl -s -H "Content-type:application/json" -X POST -d @$DVDIR_BIRDS/$i "http://localhost:8080/api/dvs/birds?key=$PETEKEY"
done

for i in `ls $DVDIR_TREES`; do
curl -s -H "Content-type:application/json" -X POST -d @$DVDIR_TREES/$i "http://localhost:8080/api/dvs/trees?key=pete"
curl -s -H "Content-type:application/json" -X POST -d @$DVDIR_TREES/$i "http://localhost:8080/api/dvs/trees?key=$PETEKEY"
done

# 9 is "sparrows"
Expand Down
2 changes: 1 addition & 1 deletion scripts/search/tests/highlighting-setup02
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
#
# FIXME dataset01-create-new.json is using hard-coded protocol and authority values from
# DatasetPage. Related ticket: https://github.com/IQSS/dataverse/issues/757
curl -s -X POST -H "Content-type:application/json" -d @scripts/search/data/dataset01-create-new.json http://localhost:8080/api/dvs/11/datasets/?key=pete
curl -s -X POST -H "Content-type:application/json" -d @scripts/search/data/dataset01-create-new.json http://localhost:8080/api/dvs/11/datasets/?key=$PETEKEY
61 changes: 25 additions & 36 deletions src/main/java/edu/harvard/iq/dataverse/IndexServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUser;
import edu.harvard.iq.dataverse.api.SearchFields;
import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
import edu.harvard.iq.dataverse.authorization.Permission;
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
import edu.harvard.iq.dataverse.authorization.users.User;
import edu.harvard.iq.dataverse.datavariable.DataVariable;
Expand Down Expand Up @@ -191,26 +192,11 @@ public String indexDataverse(Dataverse dataverse) {
// }
// }
// this should be the more performant way... given a dataverse, figure out who has the access in question
// List<RoleAssignment> assignmentsOn = permissionService.assignmentsOn(dataverse);
// for (RoleAssignment roleAssignment : assignmentsOn) {
// if (roleAssignment.getRole().permissions().contains(Permission.Access)) {
// final DataverseUser user = roleAssignment.getUser();
// solrInputDocument.addField(SearchFields.PERMS, groupPerUserPrefix + user.getId());
// }
// }
if (dataverse.getCreator() != null) {
solrInputDocument.addField(SearchFields.PERMS, groupPerUserPrefix + dataverse.getCreator().getId());
/**
* @todo: replace this fake version of granting users access to
* dataverses with the real thing, when it's available in the app
*/
if (dataverse.getCreator().getUserName().equals("pete")) {
// figure out if cathy is around
BuiltinUser cathy = dataverseUserServiceBean.findByUserName("cathy");
if (cathy != null) {
// let cathy see all of pete's dataverses
solrInputDocument.addField(SearchFields.PERMS, groupPerUserPrefix + cathy.getId());
}
List<RoleAssignment> assignmentsOn = permissionService.assignmentsOn(dataverse);
for (RoleAssignment roleAssignment : assignmentsOn) {
if (roleAssignment.getRole().permissions().contains(Permission.Discover)) {
String userIdentifier = roleAssignment.getAssigneeIdentifier();
solrInputDocument.addField(SearchFields.PERMS, groupPerUserPrefix + userIdentifier);
}
}

Expand Down Expand Up @@ -598,20 +584,18 @@ private String addOrUpdateDataset(IndexableDataset indexableDataset) {
solrInputDocument.addField(SearchFields.PUBLICATION_STATUS, DRAFT_STRING);
}

/**
* @todo delete this line about creator
*/
BuiltinUser creator = dataset.getCreator();
if (creator != null) {
solrInputDocument.addField(SearchFields.PERMS, groupPerUserPrefix + creator.getId());
/**
* @todo: replace this fake version of granting users access to
* dataverses with the real thing, when it's available in the app
*/
if (creator.getUserName().equals("pete")) {
// figure out if cathy is around
BuiltinUser cathy = dataverseUserServiceBean.findByUserName("cathy");
if (cathy != null) {
// let cathy see all of pete's dataverses
solrInputDocument.addField(SearchFields.PERMS, groupPerUserPrefix + cathy.getId());
}
/**
* @todo DRY! Same code as for dataverses.
*/
List<RoleAssignment> assignmentsOn = permissionService.assignmentsOn(dataset);
for (RoleAssignment roleAssignment : assignmentsOn) {
if (roleAssignment.getRole().permissions().contains(Permission.Discover)) {
String userIdentifier = roleAssignment.getAssigneeIdentifier();
solrInputDocument.addField(SearchFields.PERMS, groupPerUserPrefix + userIdentifier);
}
}

Expand Down Expand Up @@ -939,13 +923,18 @@ public String indexUser(User user) {
SolrInputDocument solrInputDocument = new SolrInputDocument();

String userid = groupPerUserPrefix + user.getIdentifier();
if ( ! user.isAuthenticated() ) {
if (!user.isAuthenticated()) {
userid = publicGroupString;
}

solrInputDocument.addField(SearchFields.TYPE, "groups");
solrInputDocument.addField(SearchFields.ID, userid);
solrInputDocument.addField(SearchFields.ENTITY_ID, user.getIdentifier());
/**
* @todo is it bad to not index entity id for users, which has changed
* from Long to String, yielding NumberFormatException when indexing
* into Solr?
*/
// solrInputDocument.addField(SearchFields.ENTITY_ID, user.getIdentifier());
solrInputDocument.addField(SearchFields.NAME_SORT, user.getDisplayInfo().getTitle());
solrInputDocument.addField(SearchFields.GROUPS, userid);

Expand All @@ -966,7 +955,7 @@ public String indexUser(User user) {
return ex.toString();
}

return "indexed user " + user.getIdentifier()+ ":" + user.getDisplayInfo().getTitle();
return "indexed user " + user.getIdentifier() + ":" + user.getDisplayInfo().getTitle();
}

public List<String> findPathSegments(Dataverse dataverse, List<String> segments) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/api/SearchFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public class SearchFields {
public static final String PERMS = "perms_ss";
public static final String PUBLICATION_STATUS = "published_ss";
// Used for performance. Why hit the db if solr has the data?
/**
* @todo reconcile different with Sorl schema.xml where type is Long rather
* than String.
*/
public static final String ENTITY_ID = "entityid";
public static final String PARENT_NAME = "parentname";
public static final String PARENT_ID = "parentid";
Expand Down

0 comments on commit 7a53c3c

Please sign in to comment.