MetadataSpecs { public static Specification<? extends AbstractMetadata> isType(final MetadataType type) { return new Specification<AbstractMetadata>() { @Override public Predicate toPredicate(Root<AbstractMetadata> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Path<Character> templateAttributePath = root.get(AbstractMetadata_.dataInfo).get(MetadataDataInfo_.type_JPAWorkaround); Predicate equalTemplatePredicate = cb.equal(templateAttributePath, cb.literal(type.code)); return equalTemplatePredicate; } }; } 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 testIsTemplate() throws Exception { Metadata md1 = newMetadata(_inc); md1.getDataInfo().setType(MetadataType.METADATA); md1 = _repository.save(md1); Metadata md2 = newMetadata(_inc); md2.getDataInfo().setType(MetadataType.SUB_TEMPLATE); md2 = _repository.save(md2); assertFindsCorrectMd(md1, (Specification<Metadata>)isType(MetadataType.METADATA), false); assertFindsCorrectMd(md2, (Specification<Metadata>)isType(MetadataType.SUB_TEMPLATE), false); }