Class<?> matchClass = objectToMatch.getClass();
ClassMetadata classMetaData = session.getSessionFactory().getClassMetadata(matchClass.getCanonicalName());
Criteria criteria = session.createCriteria(matchClass);
- boolean noMatch = makeCriteria(objectToMatch, matchStrategy, classMetaData, criteria);
+ boolean noMatch = makeCriteria(objectToMatch, matchStrategy, classMetaData, criteria, 1);
if (logger.isDebugEnabled()){logger.debug(criteria);}
//session.flush();
if (noMatch == false){
* @param matchStrategy the match strategy used
* @param classMetaData the precomputed class metadata
* @param criteria the criteria to fill
+ * @param level recursion level
* @return <code>true</code> if definitely no matching object will be found,
* <code>false</code> if nothing is known on the existence of a matching result
*/
private boolean makeCriteria(Object objectToMatch,
IMatchStrategy matchStrategy, ClassMetadata classMetaData,
- Criteria criteria) throws IllegalAccessException, MatchException {
+ Criteria criteria, int level) throws IllegalAccessException, MatchException {
Matching matching = matchStrategy.getMatching((IMatchable)objectToMatch);
boolean noMatch = false;
if (propertyType.isComponentType()){
matchComponentType(criteria, fieldMatcher, propertyName, value, matchModes);
}else{
- noMatch = matchNonComponentType(criteria, fieldMatcher, propertyName, value, matchModes, propertyType);
+ noMatch = matchNonComponentType(criteria, fieldMatcher, propertyName, value, matchModes, propertyType, level);
}
}
if (noMatch){
}
}
+ /**
+ * @param level the recursion level
+ */
private boolean matchNonComponentType(Criteria criteria,
FieldMatcher fieldMatcher,
String propertyName,
Object value,
List<MatchMode> matchModes,
- Type propertyType)
+ Type propertyType, int level)
throws HibernateException, DataAccessException, MatchException, IllegalAccessException{
boolean noMatch = false;
if (propertyType.isCollectionType()){
if (value instanceof Collection) {
//TODO fieldMatcher?
- matchCollection(criteria, propertyName, (Collection<?>)value);
+ matchCollection(criteria, propertyName, (Collection<?>)value, level);
}else if (value instanceof Map) {
//TODO map not yet handled for match
if (IMatchable.class.isAssignableFrom(matchClass)){
IMatchStrategy valueMatchStrategy = fieldMatcher.getMatchStrategy() != null? fieldMatcher.getMatchStrategy() : DefaultMatchStrategy.NewInstance(matchClass);
ClassMetadata valueClassMetaData = getSession().getSessionFactory().getClassMetadata(matchClass.getCanonicalName());
- noMatch = makeCriteria(value, valueMatchStrategy, valueClassMetaData, matchCriteria);
+ noMatch = makeCriteria(value, valueMatchStrategy, valueClassMetaData, matchCriteria, level+1);
}else{
logger.error("Class to match (" + matchClass + ") is not of type IMatchable");
throw new MatchException("Class to match (" + matchClass + ") is not of type IMatchable");
* class Person it checks that there is at least 1 person matching in
* nomenclaturalTitle, no matter at which position.
* See #9905 and #9964
+ *
+ * @param level recursion level
*/
- private void matchCollection(Criteria criteria, String propertyName, Collection<?> collection) {
+ private void matchCollection(Criteria criteria, String propertyName, Collection<?> collection, int level) {
int i = 0;
+ //this is a workaround to avoid handling TeamOrPersonBase e.g. in references.
+ //TeamOrPersonBase does not have a property 'teamMembers' and therefore an
+ //according restriction can not be added
+ if (level > 1) {
+ return;
+ }
criteria.add(Restrictions.sizeEq(propertyName, collection.size()));
// criteria.createAlias(propertyName, propertyAlias);
//In future (hibernate >5.1 JPA will allow using index joins: https://www.logicbig.com/tutorials/java-ee-tutorial/jpa/criteria-api-collection-operations.html
// Criteria subCriteria = criteria.createCriteria(propertyName+"[1]");
+
Criteria subCriteria = criteria.createCriteria(propertyName);
for (Object single : collection) {
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
import eu.etaxonomy.cdm.model.name.Rank;
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
import eu.etaxonomy.cdm.persistence.dto.ReferencingObjectDto;
import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;
+import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
import eu.etaxonomy.cdm.strategy.match.IMatchStrategyEqual;
import eu.etaxonomy.cdm.strategy.match.MatchException;
+import eu.etaxonomy.cdm.strategy.match.MatchStrategyFactory;
import eu.etaxonomy.cdm.strategy.merge.DefaultMergeStrategy;
import eu.etaxonomy.cdm.strategy.merge.IMergeStrategy;
import eu.etaxonomy.cdm.strategy.merge.MergeException;
+import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
Assert.assertEquals(0, candidateMatchResult.size());
person1.setNomenclaturalTitle("NomTitle1"); //set back
- //TODO should not match in future
Team teamDifferentOrder = Team.NewInstance();
teamDifferentOrder.addTeamMember(person2);
teamDifferentOrder.addTeamMember(person1);
//TODO improve, should be 0 in best implementation
Assert.assertEquals(1, candidateMatchResult.size());
+ //test that reference.authorTeam.* still works without throwing exceptions
+ TaxonName name = NonViralNameParserImpl.NewInstance().parseReferencedName("Abies alba Nyffeler & Eggli in Taxon 59: 232. 2010", NomenclaturalCode.ICNAFP, Rank.SPECIES());
+ Reference nomRef = name.getNomenclaturalReference();
+ IMatchStrategy referenceMatcher = MatchStrategyFactory.NewParsedReferenceInstance(nomRef);
+ List<Reference> matching = cdmGenericDao.findMatching(nomRef, referenceMatcher);
+ Assert.assertEquals("We don't expect matchings, only tested that no exceptions are thrown", 0, matching.size());
} catch (IllegalArgumentException | MatchException e) {
Assert.fail("No exception should be thrown");