Precheck mapping conditions.

@param object the object
@param mappingConditions the mapping conditions
@param currentList the current list
@throws MtasParserException the mtas parser exception
346726
void precheckMappingConditions(MtasParserObject object,
      List<Map<String, String>> mappingConditions,
      Map<String, List<MtasParserObject>> currentList)
      throws MtasParserException {
    for (Map<String, String> mappingCondition : mappingConditions) {
      // condition existence ancestor
      if (mappingCondition.get("type")
          .equals(MtasParserMapping.PARSER_TYPE_EXISTENCE)) {
        int number = 0;
        try {
          number = Integer.parseInt(mappingCondition.get("number"));
        } catch (Exception e) {
          log.debug(e);
        }
        String type = computeTypeFromMappingSource(
            mappingCondition.get(MAPPING_VALUE_SOURCE));
        if (number != currentList.get(type).size()) {
          throw new MtasParserException(
              "condition mapping is " + number + " ancestors of " + type
                  + " (but " + currentList.get(type).size() + " found)");
        }
        // condition unknown ancestors
      } else if (mappingCondition.get("type")
          .equals(MtasParserMapping.PARSER_TYPE_UNKNOWN_ANCESTOR)) {
        int number = 0;
        try {
          number = Integer.parseInt(mappingCondition.get("number"));
        } catch (Exception e) {
          log.debug(e);
        }
        if (number != object.getUnknownAncestorNumber()) {
          throw new MtasParserException(
              "condition mapping is " + number + " unknown ancestors (but "
                  + object.getUnknownAncestorNumber() + " found)");
        }
      } else {
        MtasParserObject[] checkObjects = computeObjectFromMappingValue(object,
            mappingCondition, currentList);
        Boolean notCondition = false;
        if (mappingCondition.get("not") != null) {
          notCondition = true;
        }
        // do checks
        if (checkObjects != null) {
          checkObjectLoop: for (MtasParserObject checkObject : checkObjects) {
            MtasParserType checkType = checkObject.getType();
            // condition on name
            if (mappingCondition.get("type")
                .equals(MtasParserMapping.PARSER_TYPE_NAME)) {
              if (notCondition && mappingCondition.get(MAPPING_VALUE_CONDITION)
                  .equals(checkType.getName())) {
                throw new MtasParserException("condition NOT "
                    + mappingCondition.get(MAPPING_VALUE_CONDITION)
                    + " on name not matched (is " + checkType.getName() + ")");
              } else if (!notCondition && mappingCondition
                  .get(MAPPING_VALUE_CONDITION).equals(checkType.getName())) {
                break checkObjectLoop;
              } else if (!notCondition && !mappingCondition
                  .get(MAPPING_VALUE_CONDITION).equals(checkType.getName())) {
                throw new MtasParserException("condition "
                    + mappingCondition.get(MAPPING_VALUE_CONDITION)
                    + " on name not matched (is " + checkType.getName() + ")");
              }
              // condition on attribute
            } else if (mappingCondition.get("type")
                .equals(MtasParserMapping.PARSER_TYPE_ATTRIBUTE)) {
              String attributeCondition = mappingCondition
                  .get(MAPPING_VALUE_CONDITION);
              String namespace = mappingCondition.get(MAPPING_VALUE_NAMESPACE);
              String attributeValue;
              if(namespace==null) {
                attributeValue = checkObject.getAttribute(mappingCondition.get(MAPPING_VALUE_NAME));
              } else {
                attributeValue = checkObject.getOtherAttribute(namespace, mappingCondition.get(MAPPING_VALUE_NAME));
              }
              if ((attributeCondition == null) && (attributeValue == null)) {
                if (!notCondition) {
                  throw new MtasParserException("attribute "
                      + mappingCondition.get("name") + " not available");
                }
              } else if ((attributeCondition != null)
                  && (attributeValue == null)) {
                if (!notCondition) {
                  throw new MtasParserException(
                      "condition " + attributeCondition + " on attribute "
                          + mappingCondition.get("name")
                          + " not matched (is null)");
                }
              } else if (attributeCondition != null) {
                if (!notCondition
                    && !attributeCondition.equals(attributeValue)) {
                  throw new MtasParserException(
                      "condition " + attributeCondition + " on attribute "
                          + mappingCondition.get("name") + " not matched (is "
                          + attributeValue + ")");
                } else if (!notCondition
                    && attributeCondition.equals(attributeValue)) {
                  break checkObjectLoop;
                } else if (notCondition
                    && attributeCondition.equals(attributeValue)) {
                  throw new MtasParserException(
                      "condition NOT " + attributeCondition + " on attribute "
                          + mappingCondition.get("name") + " not matched (is "
                          + attributeValue + ")");
                }
              }
              // condition on text
            } else if (mappingCondition.get("type")
                .equals(MtasParserMapping.PARSER_TYPE_TEXT)
                && object.getType().precheckText()) {
              String textCondition = mappingCondition
                  .get(MAPPING_VALUE_CONDITION);
              String textValue = object.getText();
              if ((textCondition == null)
                  && ((textValue == null) || textValue.equals(""))) {
                if (!notCondition) {
                  throw new MtasParserException("no text available");
                }
              } else if ((textCondition != null) && (textValue == null)) {
                if (!notCondition) {
                  throw new MtasParserException("condition " + textCondition
                      + " on text not matched (is null)");
                }
              } else if (textCondition != null) {
                if (!notCondition && !textCondition.equals(textValue)) {
                  throw new MtasParserException("condition " + textCondition
                      + " on text not matched (is " + textValue + ")");
                } else if (notCondition && textCondition.equals(textValue)) {
                  throw new MtasParserException("condition NOT " + textCondition
                      + " on text not matched (is " + textValue + ")");
                }
              }
            }
          }
        } else if (!notCondition) {
          throw new MtasParserException(
              "no object found to match condition" + mappingCondition);
        }
      }
    }
  }
695664
private void initMappings() throws Exception {
        checkClient();
        // We extract indexes and mappings to manage from mappings definition
        if (mappings != null && mappings.length > 0) {
            Map<String, Collection<String>> indices = getIndexMappings(mappings);

            // Let's initialize indexes and mappings if needed
            for (String index : indices.keySet()) {
                createIndex(client.getLowLevelClient(), classpathRoot, index, forceMapping);
                if (mergeSettings) {
                    updateSettings(client.getLowLevelClient(), classpathRoot, index);
                }

                createMapping(client, classpathRoot, index, mergeMapping);
            }
        }
    }
1005894
private void checkForeignKeyMapping(List<String> errors, Config config) {
        for (Entity entity : config.getProject().getEntities().getList()) {
            for (Relation relation : entity.getRelations().getList()) {
                if (relation.isInverse() || relation.isIntermediate()) {
                    continue;
                }

                for (AttributePair attributePair : relation.getAttributePairs()) {
                    if (attributePair.getFromAttribute().getMappedType() != attributePair.getToAttribute().getMappedType()) {
                        String errorMsg = "Inconsistent types: Column " + attributePair.getFromAttribute().getFullColumnName() + "["
                                + attributePair.getFromAttribute().getJdbcType() + "] references column " + attributePair.getToAttribute().getFullColumnName()
                                + "[" + attributePair.getToAttribute().getJdbcType() + "]. " + "You should really fix your SQL schema.";
                        if (attributePair.getFromAttribute().isInCpk()) {
                            // we may get compile failure as the property is mapped (inside the cpk)
                            log.warn(errorMsg + ". To avoid this error you can force the mapped type using configuration.");
                        } else {
                            // we should not get compile failure as the property is not mapped.
                            log.warn(errorMsg);
                        }
                    }
                }
            }
        }
    }
193299
private boolean isPresentIn(String[] values, String field){
		for (String value : values)
			if(value.equalsIgnoreCase(JMapConversion.ALL) || value.equals(field))
				return true;
		
		return false;
	}
468419
@SuppressWarnings("unchecked")
    private boolean prepareMapping(String index, Map<String, Object> defaultMappings) {
        boolean success = true;

        for (Map.Entry<String, Object> stringObjectEntry : defaultMappings.entrySet()) {
            Map<String, Object> mapping = (Map<String, Object>) stringObjectEntry.getValue();
            if (mapping == null) {
                throw new RuntimeException("type mapping not defined");
            }
            PutMappingRequestBuilder putMappingRequestBuilder = client.admin().indices().preparePutMapping()
                    .setIndices(index);
            putMappingRequestBuilder.setType(stringObjectEntry.getKey());
            putMappingRequestBuilder.setSource(mapping);

            if (log.isLoggable(Level.FINE)) {
                log.fine("Elasticsearch create mapping for index '"
                        + index + " and type '" + stringObjectEntry.getKey() + "': " + mapping);
            }

            PutMappingResponse resp = putMappingRequestBuilder.execute().actionGet();

            if (resp.isAcknowledged()) {
                if (log.isLoggable(Level.FINE)) {
                    log.fine("Elasticsearch mapping for index '"
                            + index + " and type '" + stringObjectEntry.getKey() + "' was acknowledged");
                }
            } else {
                success = false;
                log.warning("Elasticsearch mapping creation was not acknowledged for index '"
                        + index + " and type '" + stringObjectEntry.getKey() + "'");
            }
        }

        return success;
    }
196870
private static <T> void checkPreconditions(final Class<T> type, final TextParser<T> parser) {
        if(type == null) {
            throw new NullPointerException("type is null.");
        }
        
        if(parser == null) {
            throw new NullPointerException("parser is null.");
        }
    }
193550
public void setValue(Object current, String key, Object value) throws ParseException, IOException {
		// if (obj != null)
		mapper.setValue(current, key, value);
	}
1278770
private static void getConditionNodes(final Node node, final Map<Node, List<String>> conditionalNodes) {
        final NamedNodeMap attributes = node.getAttributes();
        if (attributes != null) {
            final Node attr = attributes.getNamedItem("condition");

            if (attr != null) {
                final String conditionStatement = attr.getNodeValue();

                final String[] conditions = conditionStatement.split("\\s*(;|,)\\s*");

                conditionalNodes.put(node, Arrays.asList(conditions));
            }
        }

        // Check the child nodes for condition attributes
        final NodeList elements = node.getChildNodes();
        for (int i = 0; i < elements.getLength(); ++i) {
            getConditionNodes(elements.item(i), conditionalNodes);
        }
    }
245065
private void checkListMapType(Field field) {
        Class<?> cls = field.getType();
        boolean needCheckGenericType = false;
        if (List.class.isAssignableFrom(cls)) {
            // if check is list ignore check
            isList = true;
            needCheckGenericType = true;
        }
        if (Map.class.isAssignableFrom(cls)) {
            // if check is list ignore check
            isMap = true;
            needCheckGenericType = true;
        }

        if (!needCheckGenericType) {
            return;
        }

        Type type = field.getGenericType();
        if (type instanceof ParameterizedType) {
            ParameterizedType ptype = (ParameterizedType) type;

            Type[] actualTypeArguments = ptype.getActualTypeArguments();

            if (actualTypeArguments != null) {

                int length = actualTypeArguments.length;
                // validate
                if (isList) {
                    if (length != 1) {
                        throw new RuntimeException(
                                "List must use generic definiation like List<String>, please check  field name '"
                                        + field.getName() + " at class " + field.getDeclaringClass().getName());
                    }
                } else if (isMap) {
                    if (length != 2) {
                        throw new RuntimeException(
                                "Map must use generic definiation like Map<String, String>, please check  field name '"
                                        + field.getName() + " at class " + field.getDeclaringClass().getName());
                    }
                }

                Type targetType = actualTypeArguments[0];
                if (targetType instanceof Class) {
                    genericKeyType = (Class) targetType;
                }

                if (actualTypeArguments.length > 1) {
                    targetType = actualTypeArguments[1];
                    if (targetType instanceof Class) {
                        genericeValueType = (Class) targetType;
                    }
                }

            }
        }

    }
603152
private void validateRecordedMapping() {
    if (currentMapping.destinationMutators == null || currentMapping.destinationMutators.isEmpty())
      errors.missingDestination();
    // If mapping a field without a source
    else if (options.skipType == 0
        && (currentMapping.sourceAccessors == null || currentMapping.sourceAccessors.isEmpty())
        && currentMapping.destinationMutators.get(currentMapping.destinationMutators.size() - 1)
            .getPropertyType()
            .equals(PropertyType.FIELD) && options.converter == null && !options.mapFromSource
        && sourceConstant == null)
      errors.missingSource();
    else if (options.skipType == 2 && options.condition != null)
      errors.conditionalSkipWithoutSource();
  }
1326269
private Map<String, ConditionsByKey> groupConditionsByTypeAndKey(
            List<Condition> conditions) {
        Map<String, ConditionsByKey> conditionsByType = new LinkedHashMap<String, ConditionsByKey>();

        String type;
        String key;
        ConditionsByKey conditionsByKey;
        for (Condition condition : conditions) {
            type = condition.getType();
            key = condition.getConditionKey();

            if (!(conditionsByType.containsKey(type))) {
                conditionsByType.put(type, new ConditionsByKey());
            }

            conditionsByKey = conditionsByType.get(type);
            conditionsByKey.addValuesToKey(key, condition.getValues());
        }
        return conditionsByType;
    }
492429
private static void checkPreconditions(final Map<Object, Object> mapping) {
		if( mapping == null ) {
			throw new NullPointerException("mapping should not be null");
		} else if( mapping.isEmpty() ) {
			throw new IllegalArgumentException("mapping should not be empty");
		}
	}
59375
protected void checkType(Object object) {
        if (object == null) {
            throw new NullPointerException("Sequences cannot contain null, use a List instead");
        }
        if (type != null) {
            if (!type.isInstance(object)) {
                throw new IllegalArgumentException(
                        "Invalid type of argument for sequence of type: "
                                + type.getName()
                                + " cannot add object: "
                                + object);
            }
        }
    }
1072574
public final void mapExpressionList() throws RecognitionException {
		try {
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:570:5: ( mapEntry ( COMMA mapEntry )* )
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:570:7: mapEntry ( COMMA mapEntry )*
			{
			pushFollow(FOLLOW_mapEntry_in_mapExpressionList3151);
			mapEntry();
			state._fsp--;
			if (state.failed) return;
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:570:16: ( COMMA mapEntry )*
			loop62:
			while (true) {
				int alt62=2;
				int LA62_0 = input.LA(1);
				if ( (LA62_0==COMMA) ) {
					alt62=1;
				}

				switch (alt62) {
				case 1 :
					// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:570:17: COMMA mapEntry
					{
					match(input,COMMA,FOLLOW_COMMA_in_mapExpressionList3154); if (state.failed) return;
					pushFollow(FOLLOW_mapEntry_in_mapExpressionList3156);
					mapEntry();
					state._fsp--;
					if (state.failed) return;
					}
					break;

				default :
					break loop62;
				}
			}

			}

		}

		catch (RecognitionException re) {
		    throw re;
		}

		finally {
			// do for sure before leaving
		}
	}
643122
private void checkUnmappedElements(List<T> offspring,
                                       Map<T, T> mapping,
                                       int mappingStart,
                                       int mappingEnd)
    {
        for (int i = 0; i < offspring.size(); i++)
        {
            if (!isInsideMappedRegion(i, mappingStart, mappingEnd))
            {
                T mapped = offspring.get(i);
                while (mapping.containsKey(mapped))
                {
                    mapped = mapping.get(mapped);
                }
                offspring.set(i, mapped);
            }
        }
    }
1327745
public void init(final Collection<String> localSchemaNames, final Map<String, Map<String, YamlDataSourceParameter>> schemaDataSources,
                     final Map<String, RuleConfiguration> schemaRules, final boolean isUsingRegistry) {
        databaseType = JDBCDriverURLRecognizerEngine.getDatabaseType(schemaDataSources.values().iterator().next().values().iterator().next().getUrl());
        initSchemas(localSchemaNames, schemaDataSources, schemaRules, isUsingRegistry);
    }
431526
public static List<org.fcrepo.server.types.gen.Condition> convertConditionsListToGenConditionsArray(List<Condition> conditions) {
        List<org.fcrepo.server.types.gen.Condition> genConditions =
                new ArrayList<org.fcrepo.server.types.gen.Condition>();

        for (Condition condition : conditions) {
            genConditions.add(convertConditionToGenCondition(condition));
        }

        return genConditions;
    }