Skip to content

Commit

Permalink
Add Dataverse Browsing Options
Browse files Browse the repository at this point in the history
..and Dataverse Type
  • Loading branch information
sekmiller committed Jul 24, 2014
1 parent 3142c2c commit 1da7658
Show file tree
Hide file tree
Showing 13 changed files with 527 additions and 162 deletions.
181 changes: 99 additions & 82 deletions src/main/java/edu/harvard/iq/dataverse/DatasetServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,33 @@ public class DatasetServiceBean {

@PersistenceContext(unitName = "VDCNet-ejbPU")
private EntityManager em;

public Dataset find(Object pk) {
return em.find(Dataset.class, pk);
}

public List<Dataset> findByOwnerId(Long ownerId) {
return findByOwnerId(ownerId, false);
}

public List<Dataset> findByOwnerId(Long ownerId, Boolean omitDeaccessioned) {
List<Dataset> retList = new ArrayList();
Query query = em.createQuery("select object(o) from Dataset as o where o.owner.id =:ownerId order by o.id");
query.setParameter("ownerId", ownerId);
return query.getResultList();
if (!omitDeaccessioned) {
return query.getResultList();
} else {
for (Object o : query.getResultList()) {
Dataset ds = (Dataset) o;
for (DatasetVersion dsv : ds.getVersions()) {
if (!dsv.isDeaccessioned()) {
retList.add(ds);
break;
}
}
}
return retList;
}
}

public List<Dataset> findAll() {
Expand Down Expand Up @@ -74,57 +92,57 @@ public Dataset findByGlobalId(String globalId) {
}
return foundDataset;
}

public String generateIdentifierSequence(String protocol, String authority) {
String identifier=null;

String identifier = null;
do {
identifier = ((Long) em.createNativeQuery("select nextval('dvobject_id_seq')").getSingleResult()).toString();

} while (!isUniqueIdentifier(identifier, protocol, authority));



return identifier;

}

/**
* Check that a studyId entered by the user is unique (not currently used for any other study in this Dataverse Network)

/**
* Check that a studyId entered by the user is unique (not currently used
* for any other study in this Dataverse Network)
*/
private boolean isUniqueIdentifier(String userIdentifier, String protocol,String authority) {
String query = "SELECT d FROM Dataset d WHERE d.identifier = '" + userIdentifier +"'";
query += " and d.protocol ='"+protocol+"'";
query += " and d.authority = '"+authority+"'";
boolean u = em.createQuery(query).getResultList().size()==0;
return u;
private boolean isUniqueIdentifier(String userIdentifier, String protocol, String authority) {
String query = "SELECT d FROM Dataset d WHERE d.identifier = '" + userIdentifier + "'";
query += " and d.protocol ='" + protocol + "'";
query += " and d.authority = '" + authority + "'";
boolean u = em.createQuery(query).getResultList().size() == 0;
return u;
}

public DatasetVersionDatasetUser getDatasetVersionDatasetUser(DatasetVersion version, DataverseUser user){
DatasetVersionDatasetUser ddu = null;

DatasetVersionDatasetUser ddu = null;
Query query = em.createQuery("select object(o) from DatasetVersionDatasetUser as o "
+ "where o.datasetversionid =:versionId and o.dataverseuserid =:userId");
query.setParameter("versionId", version.getId());
query.setParameter("userId", user.getId());
System.out.print("versionId: " + version.getId());
System.out.print("userId: " + user.getId());
System.out.print("versionId: " + version.getId());
System.out.print("userId: " + user.getId());
System.out.print(query.toString());
try {
ddu = (DatasetVersionDatasetUser) query.getSingleResult();
} catch (javax.persistence.NoResultException e) {
// DO nothing, just return null.
}
return ddu;
}
public List<DatasetLock> getDatasetLocks() {
}

public List<DatasetLock> getDatasetLocks() {
String query = "SELECT sl FROM DatasetLock sl";
return (List<DatasetLock>) em.createQuery(query).getResultList();
}

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void addDatasetLock(Long datasetId, Long userId, String info) {

Dataset dataset = em.find(Dataset.class, datasetId);
DatasetLock lock = new DatasetLock();
lock.setDataset(dataset);
Expand All @@ -139,7 +157,7 @@ public void addDatasetLock(Long datasetId, Long userId, String info) {
}
user.getDatasetLocks().add(lock);
}

dataset.setDatasetLock(lock);
em.persist(lock);
}
Expand All @@ -156,64 +174,63 @@ public void removeDatasetLock(Long datasetId) {
/*
* TODO - ?
* throw an exception if for whatever reason we can't remove the lock?
try {
*/
try {
*/
em.remove(lock);
/*
} catch (TransactionRequiredException te) {
...
} catch (IllegalArgumentException iae) {
...
}
*/
} catch (TransactionRequiredException te) {
...
} catch (IllegalArgumentException iae) {
...
}
*/
}
}

/*
public Study getStudyByGlobalId(String identifier) {
String protocol = null;
String authority = null;
String studyId = null;
int index1 = identifier.indexOf(':');
int index2 = identifier.indexOf('/');
int index3 = 0;
if (index1 == -1) {
throw new EJBException("Error parsing identifier: " + identifier + ". ':' not found in string");
} else {
protocol = identifier.substring(0, index1);
}
if (index2 == -1) {
throw new EJBException("Error parsing identifier: " + identifier + ". '/' not found in string");
public Study getStudyByGlobalId(String identifier) {
String protocol = null;
String authority = null;
String studyId = null;
int index1 = identifier.indexOf(':');
int index2 = identifier.indexOf('/');
int index3 = 0;
if (index1 == -1) {
throw new EJBException("Error parsing identifier: " + identifier + ". ':' not found in string");
} else {
protocol = identifier.substring(0, index1);
}
if (index2 == -1) {
throw new EJBException("Error parsing identifier: " + identifier + ". '/' not found in string");
} else {
authority = identifier.substring(index1 + 1, index2);
}
if (protocol.equals("doi")){
index3 = identifier.indexOf('/', index2 + 1 );
if (index3== -1){
studyId = identifier.substring(index2 + 1).toUpperCase();
} else {
authority = identifier.substring(index1 + 1, index3);
studyId = identifier.substring(index3 + 1).toUpperCase();
}
} else {
studyId = identifier.substring(index2 + 1).toUpperCase();
}
String queryStr = "SELECT s from Study s where s.studyId = :studyId and s.protocol= :protocol and s.authority= :authority";
Study study = null;
try {
Query query = em.createQuery(queryStr);
query.setParameter("studyId", studyId);
query.setParameter("protocol", protocol);
query.setParameter("authority", authority);
study = (Study) query.getSingleResult();
} catch (javax.persistence.NoResultException e) {
// DO nothing, just return null.
}
return study;
}
*/

} else {
authority = identifier.substring(index1 + 1, index2);
}
if (protocol.equals("doi")){
index3 = identifier.indexOf('/', index2 + 1 );
if (index3== -1){
studyId = identifier.substring(index2 + 1).toUpperCase();
} else {
authority = identifier.substring(index1 + 1, index3);
studyId = identifier.substring(index3 + 1).toUpperCase();
}
} else {
studyId = identifier.substring(index2 + 1).toUpperCase();
}
String queryStr = "SELECT s from Study s where s.studyId = :studyId and s.protocol= :protocol and s.authority= :authority";
Study study = null;
try {
Query query = em.createQuery(queryStr);
query.setParameter("studyId", studyId);
query.setParameter("protocol", protocol);
query.setParameter("authority", authority);
study = (Study) query.getSingleResult();
} catch (javax.persistence.NoResultException e) {
// DO nothing, just return null.
}
return study;
}
*/
}
40 changes: 38 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/Dataverse.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.NotEmpty;

/**
*
Expand All @@ -34,7 +37,9 @@
})
@Entity
public class Dataverse extends DvObjectContainer {

public enum DataverseType {
RESEARCHERS, RESEARCH_PROJECTS, JOURNALS, ORGANIZATIONS_INSTITUTIONS, TEACHING_COURSES, UNCATEGORIZED
};
private static final long serialVersionUID = 1L;

@NotBlank(message = "Please enter a name.")
Expand All @@ -53,7 +58,20 @@ public class Dataverse extends DvObjectContainer {
@NotBlank(message = "Please enter a valid email address.")
@Email(message = "Please enter a valid email address.")
private String contactEmail;

@NotNull(message = "Please select a type for your dataverse.")
@Enumerated(EnumType.STRING)
private DataverseType dataverseType;

public DataverseType getDataverseType() {
return dataverseType;
}

public void setDataverseType(DataverseType dataverseType) {
this.dataverseType = dataverseType;
}


private String affiliation;

// Note: We can't have "Remove" here, as there are role assignments that refer
Expand All @@ -70,6 +88,8 @@ public class Dataverse extends DvObjectContainer {
private boolean permissionRoot;
private boolean metadataBlockRoot;
private boolean facetRoot;
private boolean displayByType;
private boolean displayFeatured;

@OneToMany(cascade = {CascadeType.MERGE})
private List<MetadataBlock> metadataBlocks = new ArrayList();
Expand Down Expand Up @@ -106,7 +126,7 @@ public List<MetadataBlock> getMetadataBlocks(boolean returnActualDB) {
return getOwner().getMetadataBlocks();
}
}

public void setMetadataBlocks(List<MetadataBlock> metadataBlocks) {
this.metadataBlocks = metadataBlocks;
}
Expand Down Expand Up @@ -194,7 +214,23 @@ public boolean isFacetRoot() {
public void setFacetRoot(boolean facetRoot) {
this.facetRoot = facetRoot;
}

public boolean isDisplayByType() {
return displayByType;
}

public void setDisplayByType(boolean displayByType) {
this.displayByType = displayByType;
}

public boolean isDisplayFeatured() {
return displayFeatured;
}

public void setDisplayFeatured(boolean displayFeatured) {
this.displayFeatured = displayFeatured;
}

public ImageFormat getLogoFormat() {
return logoFormat;
}
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/DataverseConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package edu.harvard.iq.dataverse;

import javax.ejb.EJB;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
*
* @author skraffmiller
*/
@FacesConverter("dataverseConverter")
public class DataverseConverter implements Converter {


@EJB
DataverseServiceBean dataverseService;

@Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue) {
return dataverseService.find(new Long(submittedValue));
}

@Override
public String getAsString(FacesContext facesContext, UIComponent component, Object value) {
if (value == null || value.equals("")) {
return "";
} else {
return ((Dataverse) value).getId().toString();
}
}
}
Loading

0 comments on commit 1da7658

Please sign in to comment.