MetadataSpecs { public static Specification<? extends AbstractMetadata> hasType(final MetadataType metadataType) { return new Specification<AbstractMetadata>() { @Override public Predicate toPredicate(Root<AbstractMetadata> root, CriteriaQuery<?> query, CriteriaBuilder cb) { final Path<Character> typeChar = root.get(AbstractMetadata_.dataInfo).get(MetadataDataInfo_.type_JPAWorkaround); return cb.equal(typeChar, metadataType.code); } }; } private  MetadataSpecs(); static Specification<? extends AbstractMetadata> hasSchemaId(final String schemaId); static Specification<? extends AbstractMetadata> hasOwner(final int owner); static Specification<? extends AbstractMetadata> hasMetadataId(final int metadataId); static Specification<? extends AbstractMetadata> hasMetadataUuid(final String uuid); static Specification<? extends AbstractMetadata> hasHarvesterUuid(final String harvesterUuid); static Specification<? extends AbstractMetadata> isOwnedByUser(final int userId); static Specification<? extends AbstractMetadata> hasSource(final String sourceUuid); static Specification<? extends AbstractMetadata> isType(final MetadataType type); static Specification<? extends AbstractMetadata> isHarvested(final boolean isHarvested); static Specification<? extends AbstractMetadata> hasMetadataIdIn(final Collection<Integer> mdIds); static Specification<? extends AbstractMetadata> hasMetadataUuidIn(final Collection<String> uuids); static Specification<? extends AbstractMetadata> hasType(final MetadataType metadataType); static Specification<? extends AbstractMetadata> isOwnedByOneOfFollowingGroups(final List<Integer> groups); static Specification<? extends AbstractMetadata> hasCategory(final MetadataCategory category); static Specification<? extends AbstractMetadata> hasExtra(final String extra); static Specification<? extends AbstractMetadata> isIso19139Schema();  }
@Test public void testHasMetadataType() throws Exception { final Metadata metadata = newMetadata(_inc); metadata.getDataInfo().setType(MetadataType.METADATA); Metadata md1 = _repository.save(metadata); final Metadata metadata2 = newMetadata(_inc); metadata2.getDataInfo().setType(MetadataType.SUB_TEMPLATE); Metadata md2 = _repository.save(metadata2); final Metadata metadata3 = newMetadata(_inc); metadata3.getDataInfo().setType(MetadataType.TEMPLATE); Metadata md3 = _repository.save(metadata3); assertEquals(1, _repository.findAll((Specification<Metadata>)hasType(MetadataType.METADATA)).size()); assertEquals(1, _repository.findAll((Specification<Metadata>)hasType(MetadataType.SUB_TEMPLATE)).size()); assertEquals(1, _repository.findAll((Specification<Metadata>)hasType(MetadataType.TEMPLATE)).size()); assertEquals(md1.getId(), _repository.findOne((Specification<Metadata>)hasType(MetadataType.METADATA)).getId()); assertEquals(md2.getId(), _repository.findOne((Specification<Metadata>)hasType(MetadataType.SUB_TEMPLATE)).getId()); assertEquals(md3.getId(), _repository.findOne((Specification<Metadata>)hasType(MetadataType.TEMPLATE)).getId()); }