-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relocate H2 init SQL scripts since it's not possible to refer to them unambiguously in gemma-cli.
- Loading branch information
Showing
7 changed files
with
183 additions
and
2 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
gemma-cli/src/main/java/ubic/gemma/core/apps/AclLinterCli.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package ubic.gemma.core.apps; | ||
|
||
import gemma.gsec.acl.domain.AclObjectIdentity; | ||
import gemma.gsec.model.Securable; | ||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.commons.cli.ParseException; | ||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import ubic.gemma.core.util.AbstractCLI; | ||
import ubic.gemma.model.expression.arrayDesign.ArrayDesign; | ||
import ubic.gemma.model.expression.bioAssay.BioAssay; | ||
import ubic.gemma.model.expression.biomaterial.BioMaterial; | ||
import ubic.gemma.model.expression.experiment.*; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.List; | ||
|
||
@Component | ||
public class AclLinterCli extends AbstractCLI { | ||
|
||
@Autowired | ||
private SessionFactory sessionFactory; | ||
|
||
@Override | ||
protected void buildOptions( Options options ) { | ||
|
||
} | ||
|
||
@Override | ||
protected void processOptions( CommandLine commandLine ) throws ParseException { | ||
|
||
} | ||
|
||
@Override | ||
protected void doWork() throws Exception { | ||
Session session = sessionFactory.openSession(); | ||
try { | ||
warnEntitiesLackingObjectIdentity( session, ArrayDesign.class ); | ||
warnEntitiesLackingObjectIdentity( session, ExpressionExperiment.class ); | ||
warnEntitiesLackingObjectIdentity( session, ExpressionExperimentSubSet.class ); | ||
warnEntitiesLackingObjectIdentity( session, BioMaterial.class ); | ||
warnEntitiesLackingObjectIdentity( session, BioAssay.class ); | ||
warnEntitiesLackingObjectIdentity( session, ExperimentalDesign.class ); | ||
warnEntitiesLackingObjectIdentity( session, ExperimentalFactor.class ); | ||
warnEntitiesLackingObjectIdentity( session, FactorValue.class ); | ||
|
||
warnEntitiesWhoseParentObjectIsMissing( session, ExpressionExperimentSubSet.class, ExpressionExperiment.class ); | ||
warnEntitiesWhoseParentObjectIsMissing( session, BioAssay.class, ExpressionExperiment.class ); | ||
warnEntitiesWhoseParentObjectIsMissing( session, ExperimentalDesign.class, ExpressionExperiment.class ); | ||
warnEntitiesWhoseParentObjectIsMissing( session, ExperimentalFactor.class, ExpressionExperiment.class ); | ||
warnEntitiesWhoseParentObjectIsMissing( session, FactorValue.class, ExpressionExperiment.class ); | ||
} finally { | ||
session.close(); | ||
} | ||
} | ||
|
||
private void warnEntitiesLackingObjectIdentity( Session session, Class<? extends Securable> clazz ) { | ||
//language=HQL | ||
//noinspection unchecked | ||
List<? extends Securable> list = session | ||
.createQuery( "select e from " + clazz.getName() + " e " | ||
+ "where e.id not in ( " + "select aoi.identifier from AclObjectIdentity aoi where aoi.type = :type" + ")" ) | ||
.setParameter( "type", clazz.getName() ) | ||
.list(); | ||
for ( Securable ee : list ) { | ||
addErrorObject( ee, String.format( "Object with ID %d lacks an ACL identity of type %s", ee.getId(), clazz.getName() ) ); | ||
} | ||
} | ||
|
||
private void warnEntitiesWhoseParentObjectIsMissing( Session session, Class<? extends Securable> clazz, Class<? extends Securable> parentType ) { | ||
//noinspection unchecked | ||
List<Object[]> list = session | ||
.createQuery( "select e, aoi.parentObject from " + clazz.getName() + " e, AclObjectIdentity aoi " | ||
+ "where aoi.identifier = e.id and aoi.type = :type " | ||
+ "and aoi.parentObject is not null " | ||
+ "and aoi.parentObject.identifier not in (select p.id from " + parentType.getName() + " p)" ) | ||
.setParameter( "type", clazz.getName() ) | ||
.list(); | ||
for ( Object[] ee : list ) { | ||
Securable s = ( Securable ) ee[0]; | ||
AclObjectIdentity parentAoi = ( AclObjectIdentity ) ee[1]; | ||
addErrorObject( s, String.format( "Parent of object with ID %d does not exist; parent ACL identity is %s", s.getId(), parentAoi ) ); | ||
} | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getCommandName() { | ||
return "lintAcls"; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getShortDesc() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public GemmaCLI.CommandGroup getCommandGroup() { | ||
return GemmaCLI.CommandGroup.SYSTEM; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
gemma-cli/src/test/java/ubic/gemma/core/apps/AclLinterCliTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ubic.gemma.core.apps; | ||
|
||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import ubic.gemma.core.util.test.BaseDatabaseTest; | ||
import ubic.gemma.persistence.util.TestComponent; | ||
|
||
import static ubic.gemma.core.util.test.Assertions.assertThat; | ||
|
||
@ContextConfiguration | ||
public class AclLinterCliTest extends BaseDatabaseTest { | ||
|
||
@Configuration | ||
@TestComponent | ||
static class AclLinterCliTestContextConfiguration extends BaseDatabaseTestContextConfiguration { | ||
|
||
@Bean | ||
public AclLinterCli aclLinterCli() { | ||
return new AclLinterCli(); | ||
} | ||
} | ||
|
||
@Autowired | ||
private AclLinterCli aclLinterCli; | ||
|
||
@Test | ||
public void test() { | ||
assertThat( aclLinterCli ) | ||
.withArguments() | ||
.hasCommandName( "lintAcls" ) | ||
.succeeds(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
gemma-cli/src/test/java/ubic/gemma/core/util/test/Assertions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ubic.gemma.core.util.test; | ||
|
||
import ubic.gemma.core.util.CLI; | ||
|
||
public class Assertions { | ||
|
||
public static CliAssert assertThat( CLI cli ) { | ||
return new CliAssert( cli ); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
gemma-cli/src/test/java/ubic/gemma/core/util/test/CliAssert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ubic.gemma.core.util.test; | ||
|
||
import org.assertj.core.api.AbstractAssert; | ||
import ubic.gemma.core.util.CLI; | ||
|
||
/** | ||
* AssertJ assertions for {@link CLI}. | ||
*/ | ||
public class CliAssert extends AbstractAssert<CliAssert, CLI> { | ||
|
||
private String[] args = {}; | ||
|
||
public CliAssert( CLI cli ) { | ||
super( cli, CliAssert.class ); | ||
} | ||
|
||
public CliAssert withArguments( String... args ) { | ||
this.args = args; | ||
return myself; | ||
} | ||
|
||
public CliAssert hasCommandName( String commandName ) { | ||
objects.assertEqual( info, commandName, actual.getCommandName() ); | ||
return myself; | ||
} | ||
|
||
public void succeeds() { | ||
objects.assertEqual( info, 0, actual.executeCommand( args ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.