use of org.apache.commons.collections4.Predicate in project BroadleafCommerce by BroadleafCommerce.
the class MergePersistenceUnitManager method exceptionIfEntityMarkerNotFound.
/**
* Detects the presence of the {@link EntityMarkerClassTransformer} and throws an exception if this is misconfigured. If there
* are no class transformes within {@link #mergedClassTransformers} then this does nothing
*/
protected void exceptionIfEntityMarkerNotFound() {
if (CollectionUtils.isNotEmpty(mergedClassTransformers)) {
boolean foundEntityMarkerTransformer = IterableUtils.find(mergedClassTransformers, new Predicate<BroadleafClassTransformer>() {
@Override
public boolean evaluate(BroadleafClassTransformer object) {
return EntityMarkerClassTransformer.class.isAssignableFrom(object.getClass());
}
}) != null;
if (!foundEntityMarkerTransformer) {
BeanDefinition transformersBeanDef = ((BeanDefinitionRegistry) applicationContext.getAutowireCapableBeanFactory()).getBeanDefinition("blMergedClassTransformers");
String msg = "The EntityMarkerClassTransformer was not detected as registered in the the list of blMergedClassTransformers. This is" + " usually caused the blMergedClassTransformers being overridden in a different configuration. Without this transformer Broadleaf" + " is unable to validate whether or not class transformation happened as expected. This bean was registered as " + transformersBeanDef + " but it should have been detected as registerd in bl-common-applicationContext.xml. Change the definition in " + transformersBeanDef.getResourceDescription() + " to instead utilize the EarlyStageMergeBeanPostProcessor in XML or an @Merge(targetRef=\"blMergedClassTransformers\" early = true) in a Java configuration class";
throw new IllegalStateException(msg);
}
}
}
use of org.apache.commons.collections4.Predicate in project Alpha by alpha-asp.
the class StratifiedEvaluation method apply.
@Override
public // memories created here rather than re-initialize everything.
InternalProgram apply(AnalyzedProgram inputProgram) {
// Calculate a stratification and initialize the working memory.
ComponentGraph componentGraph = inputProgram.getComponentGraph();
List<ComponentGraph.SCComponent> strata = StratificationAlgorithm.calculateStratification(componentGraph);
predicateDefiningRules = inputProgram.getPredicateDefiningRules();
// Set up list of atoms which are known to be true - these will be expand by the evaluation.
Map<Predicate, Set<Instance>> knownFacts = new LinkedHashMap<>(inputProgram.getFactsByPredicate());
for (Map.Entry<Predicate, Set<Instance>> entry : knownFacts.entrySet()) {
workingMemory.initialize(entry.getKey());
workingMemory.addInstances(entry.getKey(), true, entry.getValue());
}
// Create working memories for all predicates occurring in each rule.
for (CompiledRule nonGroundRule : inputProgram.getRulesById().values()) {
for (Predicate predicate : nonGroundRule.getOccurringPredicates()) {
workingMemory.initialize(predicate);
}
}
workingMemory.reset();
// Set up literal instantiator.
literalInstantiator = new LiteralInstantiator(new WorkingMemoryBasedInstantiationStrategy(workingMemory));
// Evaluate the program part covered by the calculated stratification.
for (ComponentGraph.SCComponent currComponent : strata) {
evaluateComponent(currComponent);
}
// Build the program resulting from evaluating the stratified part.
// Add original input facts to newly derived ones.
additionalFacts.addAll(inputProgram.getFacts());
List<CompiledRule> outputRules = new ArrayList<>();
inputProgram.getRulesById().entrySet().stream().filter((entry) -> !solvedRuleIds.contains(entry.getKey())).forEach((entry) -> outputRules.add(entry.getValue()));
// NOTE: if InternalProgram requires solved rules, they should be added here.
return new InternalProgram(outputRules, additionalFacts);
}
use of org.apache.commons.collections4.Predicate in project alf.io by alfio-event.
the class EventApiController method exportLines.
private Stream<String[]> exportLines(String eventName, Principal principal, List<String> fields, Map<Integer, TicketCategory> categoriesMap, ZoneId eventZoneId) {
var username = principal.getName();
var eInvoicingEnabled = configurationManager.isItalianEInvoicingEnabled(eventManager.getEventAndOrganizationId(eventName, username));
return eventManager.findAllConfirmedTicketsForCSV(eventName, username).stream().map(trs -> {
Ticket t = trs.getTicket();
var currencyCode = t.getCurrencyCode();
TicketReservation reservation = trs.getTicketReservation();
List<String> line = new ArrayList<>();
if (fields.contains("ID")) {
line.add(t.getUuid());
}
if (fields.contains("Category")) {
line.add(categoriesMap.get(t.getCategoryId()).getName());
}
if (fields.contains("Event")) {
line.add(eventName);
}
if (fields.contains("Status")) {
line.add(t.getStatus().toString());
}
if (fields.contains("OriginalPrice")) {
line.add(MonetaryUtil.centsToUnit(t.getSrcPriceCts(), currencyCode).toString());
}
if (fields.contains("PaidPrice")) {
line.add(MonetaryUtil.centsToUnit(t.getFinalPriceCts(), currencyCode).toString());
}
if (fields.contains("Discount")) {
line.add(MonetaryUtil.centsToUnit(t.getDiscountCts(), currencyCode).toString());
}
if (fields.contains("VAT")) {
line.add(MonetaryUtil.centsToUnit(t.getVatCts(), currencyCode).toString());
}
if (fields.contains("ReservationID")) {
line.add(t.getTicketsReservationId());
}
if (fields.contains("Full Name")) {
line.add(t.getFullName());
}
if (fields.contains("First Name")) {
line.add(t.getFirstName());
}
if (fields.contains("Last Name")) {
line.add(t.getLastName());
}
if (fields.contains("E-Mail")) {
line.add(t.getEmail());
}
if (fields.contains("Locked")) {
line.add(String.valueOf(t.getLockedAssignment()));
}
if (fields.contains("Language")) {
line.add(String.valueOf(t.getUserLanguage()));
}
if (fields.contains("Confirmation")) {
line.add(reservation.getConfirmationTimestamp().withZoneSameInstant(eventZoneId).toString());
}
if (fields.contains("Billing Address")) {
line.add(reservation.getBillingAddress());
}
if (fields.contains("Country Code")) {
line.add(reservation.getVatCountryCode());
}
boolean paymentIdRequested = fields.contains("Payment ID");
boolean paymentGatewayRequested = fields.contains(PAYMENT_METHOD);
if ((paymentIdRequested || paymentGatewayRequested)) {
Optional<Transaction> transaction = trs.getTransaction();
if (paymentIdRequested) {
line.add(defaultString(transaction.map(Transaction::getPaymentId).orElse(null), transaction.map(Transaction::getTransactionId).orElse("")));
}
if (paymentGatewayRequested) {
line.add(transaction.map(tr -> tr.getPaymentProxy().name()).orElse(""));
}
}
if (eInvoicingEnabled) {
var billingDetails = trs.getBillingDetails();
var optionalInvoicingData = Optional.ofNullable(billingDetails.getInvoicingAdditionalInfo()).map(TicketReservationInvoicingAdditionalInfo::getItalianEInvoicing);
if (fields.contains(FISCAL_CODE)) {
line.add(optionalInvoicingData.map(ItalianEInvoicing::getFiscalCode).orElse(""));
}
if (fields.contains(REFERENCE_TYPE)) {
line.add(optionalInvoicingData.map(ItalianEInvoicing::getReferenceTypeAsString).orElse(""));
}
if (fields.contains("Addressee Code")) {
line.add(optionalInvoicingData.map(ItalianEInvoicing::getAddresseeCode).orElse(""));
}
if (fields.contains("PEC")) {
line.add(optionalInvoicingData.map(ItalianEInvoicing::getPec).orElse(""));
}
}
// obviously not optimized
Map<String, String> additionalValues = ticketFieldRepository.findAllValuesForTicketId(t.getId());
Predicate<String> contains = FIXED_FIELDS::contains;
fields.stream().filter(contains.negate()).filter(f -> f.startsWith(CUSTOM_FIELDS_PREFIX)).forEachOrdered(field -> {
String customFieldName = field.substring(CUSTOM_FIELDS_PREFIX.length());
line.add(additionalValues.getOrDefault(customFieldName, "").replace("\"", ""));
});
return line.toArray(new String[0]);
});
}
use of org.apache.commons.collections4.Predicate in project archiva by apache.
the class FileTypes method getFileTypePatterns.
/**
* Get the list of patterns for a specified filetype.
* You will always get a list. In this order.
* <ul>
* <li>The Configured List</li>
* <li>The Default List</li>
* <li>A single item list of <code>"**/*"</code></li>
* </ul>
*
* @param id the id to lookup.
* @return the list of patterns.
*/
public List<String> getFileTypePatterns(String id) {
Configuration config = archivaConfiguration.getConfiguration();
Predicate selectedFiletype = new FiletypeSelectionPredicate(id);
RepositoryScanningConfiguration repositoryScanningConfiguration = config.getRepositoryScanning();
if (repositoryScanningConfiguration != null) {
FileType filetype = IterableUtils.find(config.getRepositoryScanning().getFileTypes(), selectedFiletype);
if ((filetype != null) && CollectionUtils.isNotEmpty(filetype.getPatterns())) {
return filetype.getPatterns();
}
}
List<String> defaultPatterns = defaultTypeMap.get(id);
if (CollectionUtils.isEmpty(defaultPatterns)) {
return Collections.singletonList("**/*");
}
return defaultPatterns;
}
use of org.apache.commons.collections4.Predicate in project herd by FINRAOS.
the class BusinessObjectDefinitionServiceImpl method indexValidateBusinessObjectDefinitionsList.
/**
* A helper method that will validate a list of business object definitions
*
* @param businessObjectDefinitionEntityList the list of business object definitions that will be validated
*
* @return true all of the business object definitions are valid in the index
*/
private boolean indexValidateBusinessObjectDefinitionsList(final List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityList, String indexName) {
final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
Predicate<BusinessObjectDefinitionEntity> validInIndexPredicate = businessObjectDefinitionEntity -> {
// Fetch Join with .size()
businessObjectDefinitionEntity.getAttributes().size();
businessObjectDefinitionEntity.getBusinessObjectDefinitionTags().size();
businessObjectDefinitionEntity.getBusinessObjectFormats().size();
businessObjectDefinitionEntity.getColumns().size();
businessObjectDefinitionEntity.getSampleDataFiles().size();
// Convert the business object definition entity to a JSON string
final String jsonString = businessObjectDefinitionHelper.safeObjectMapperWriteValueAsString(businessObjectDefinitionEntity);
return indexFunctionsDao.isValidDocumentIndex(indexName, documentType, businessObjectDefinitionEntity.getId().toString(), jsonString);
};
boolean isValid = true;
for (BusinessObjectDefinitionEntity businessObjectDefinitionEntity : businessObjectDefinitionEntityList) {
if (!validInIndexPredicate.test(businessObjectDefinitionEntity)) {
isValid = false;
}
}
return isValid;
}
Aggregations