Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import ubic.gemma.model.genome.Taxon;

import javax.annotation.Nullable;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -105,6 +106,9 @@ public <T extends Identifiable> EntityUrl<T> entity( T entity ) {
}

public <T extends Identifiable> EntityUrl<T> entity( Class<T> entityType, Long id ) {
if ( Modifier.isAbstract( entityType.getModifiers() ) ) {
throw new UnsupportedEntityUrlException( "Cannot generate a URL for abstract entity type " + entityType.getSimpleName() + ".", entityType );
}
T entity = BeanUtils.instantiate( entityType );
if ( entity instanceof AbstractIdentifiable ) {
( ( AbstractIdentifiable ) entity ).setId( id );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ubic.gemma.persistence.util;

import org.junit.Test;
import ubic.gemma.model.blacklist.BlacklistedEntity;
import ubic.gemma.model.common.description.Characteristic;
import ubic.gemma.model.expression.arrayDesign.ArrayDesign;
import ubic.gemma.model.expression.experiment.ExpressionExperiment;
Expand Down Expand Up @@ -81,4 +82,9 @@ public void testFactorValueOntologyUrl() {
c.setValueUri( "http://purl.obolibrary.org/ont/NCBITaxon_9606" );
assertThrows( UnsupportedEntityUrlException.class, () -> entityUrlBuilder.fromHostUrl().entity( c ).ont().toUriString() );
}

@Test
public void testAbstractEntityType() {
assertThrows( UnsupportedEntityUrlException.class, () -> entityUrlBuilder.fromHostUrl().entity( BlacklistedEntity.class, 1L ) );
}
}