class InfraActiveRequestsRepositoryImpl implements InfraActiveRequestsRepositoryCustom {

    @Override
    public List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive(
            final Map<String, List<String>> orchestrationMap) {


        final List<Predicate> predicates = new LinkedList<>();
        final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
        final CriteriaQuery<InfraActiveRequests> crit = cb.createQuery(InfraActiveRequests.class);
        final Root<InfraActiveRequests> tableRoot = crit.from(InfraActiveRequests.class);
        for (final Map.Entry<String, List<String>> entry : orchestrationMap.entrySet()) {
            String mapKey = entry.getKey();
            if ("serviceInstanceId".equalsIgnoreCase(mapKey)) {
                mapKey = "serviceInstanceId";
            } else if ("serviceInstanceName".equalsIgnoreCase(mapKey)) {
                mapKey = "serviceInstanceName";
            } else if ("vnfInstanceId".equalsIgnoreCase(mapKey)) {
                mapKey = "vnfId";
            } else if ("pnfName".equalsIgnoreCase(mapKey)) {
                mapKey = "pnfName";
            } else if ("vnfInstanceName".equalsIgnoreCase(mapKey)) {
                mapKey = "vnfName";
            } else if ("vfModuleInstanceId".equalsIgnoreCase(mapKey)) {
                mapKey = "vfModuleId";
            } else if ("vfModuleInstanceName".equalsIgnoreCase(mapKey)) {
                mapKey = "vfModuleName";
            } else if ("volumeGroupInstanceId".equalsIgnoreCase(mapKey)) {
                mapKey = "volumeGroupId";
            } else if ("volumeGroupInstanceName".equalsIgnoreCase(mapKey)) {
                mapKey = "volumeGroupName";
            } else if ("networkInstanceId".equalsIgnoreCase(mapKey)) {
                mapKey = "networkId";
            } else if ("networkInstanceName".equalsIgnoreCase(mapKey)) {
                mapKey = "networkName";
            } else if (mapKey.equalsIgnoreCase("configurationInstanceId")) {
                mapKey = "configurationId";
            } else if (mapKey.equalsIgnoreCase("configurationInstanceName")) {
                mapKey = "configurationName";
            } else if ("lcpCloudRegionId".equalsIgnoreCase(mapKey)) {
                mapKey = "cloudRegion";
            } else if ("tenantId".equalsIgnoreCase(mapKey)) {
                mapKey = "tenantId";
            } else if ("modelType".equalsIgnoreCase(mapKey)) {
                mapKey = "requestScope";
            } else if ("requestorId".equalsIgnoreCase(mapKey)) {
                mapKey = "requestorId";
            } else if ("requestExecutionDate".equalsIgnoreCase(mapKey)) {
                mapKey = "startTime";
            }

            final String operator = entry.getValue().get(0);
            final String propertyValue = entry.getValue().get(1);
            if ("startTime".equals(mapKey)) {
                final SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy");
                try {
                    final Date thisDate = format.parse(propertyValue);
                    final Timestamp minTime = new Timestamp(thisDate.getTime());
                    Timestamp maxTime = new Timestamp(thisDate.getTime() + TimeUnit.DAYS.toMillis(1));

                    if ("DOES_NOT_EQUAL".equalsIgnoreCase(operator)) {
                        predicates.add(cb.or(cb.lessThan(tableRoot.get(mapKey), minTime),
                                cb.greaterThanOrEqualTo(tableRoot.get(mapKey), maxTime)));
                    } else if ("BETWEEN_DATES".equalsIgnoreCase(operator)) {
                        Date endDate = format.parse(entry.getValue().get(2));
                        maxTime = new Timestamp(endDate.getTime());
                        predicates.add(cb.between(tableRoot.get(mapKey), minTime, maxTime));
                    } else {
                        predicates.add(cb.between(tableRoot.get(mapKey), minTime, maxTime));
                    }
                } catch (final Exception e) {
                    logger.debug("Exception in getOrchestrationFiltersFromInfraActive(): {}", e.getMessage(), e);
                    return null;
                }
            } else if ("DOES_NOT_EQUAL".equalsIgnoreCase(operator)) {
                predicates.add(cb.notEqual(tableRoot.get(mapKey), propertyValue));
            } else {
                predicates.add(cb.equal(tableRoot.get(mapKey), propertyValue));
            }

        }

        final Order order = cb.asc(tableRoot.get(START_TIME));

        return executeInfraQuery(crit, predicates, order);
    }

}