use of org.apache.commons.lang3.StringUtils.isNoneEmpty in project Eidolons by IDemiurge.
the class UnitDataSource method getWeaponValueContainer.
private ValueContainer getWeaponValueContainer(DC_WeaponObj weapon) {
TextureRegion image;
if (weapon != null) {
image = getOrCreateR(weapon.getImagePath());
} else {
image = getOrCreateR(CELL_TYPE.WEAPON_MAIN.getSlotImagePath());
}
ValueContainer valueContainer = new ValueContainer(image);
if (weapon != null) {
List<ValueContainer> list = new ArrayList<>();
for (int i = 0; i < WEAPON_DC_INFO_PARAMS.length; i++) {
PARAMS p = WEAPON_DC_INFO_PARAMS[i];
String value = String.valueOf(weapon.getIntParam(p));
String name = p.getName();
final ValueContainer tooltipContainer = new ValueContainer(name, value);
tooltipContainer.pad(10);
list.add(tooltipContainer);
}
Tooltip tooltip = new WeaponTooltip();
tooltip.setUserObject(new WeaponToolTipDataSource() {
@Override
public List<ValueContainer> getMainParams() {
return list;
}
@Override
public List<ValueContainer> getBuffs() {
return weapon.getBuffs().stream().filter(obj -> StringUtils.isNoneEmpty(obj.getType().getProperty(G_PROPS.IMAGE))).map(AttackTooltipFactory.getObjValueContainerMapper()).collect(Collectors.toList());
}
});
valueContainer.addListener(tooltip.getController());
}
return valueContainer;
}
use of org.apache.commons.lang3.StringUtils.isNoneEmpty in project cloudbreak by hortonworks.
the class AllHostPublicDnsEntryService method getComponentLocation.
@Override
protected Map<String, List<String>> getComponentLocation(Stack stack) {
Map<String, List<String>> result = new HashMap<>();
Optional<InstanceMetaData> gateway = Optional.ofNullable(stack.getPrimaryGatewayInstance());
if (gateway.isEmpty()) {
LOGGER.info("No running gateway or all node is terminated, we skip the dns entry deletion.");
} else {
InstanceMetaData primaryGatewayInstance = gateway.get();
Map<String, List<String>> hostnamesByInstanceGroupName = stack.getNotTerminatedInstanceMetaDataSet().stream().filter(im -> StringUtils.isNoneEmpty(im.getDiscoveryFQDN()) && !im.getDiscoveryFQDN().equals(primaryGatewayInstance.getDiscoveryFQDN())).collect(groupingBy(InstanceMetaData::getInstanceGroupName, mapping(InstanceMetaData::getDiscoveryFQDN, toList())));
result.putAll(hostnamesByInstanceGroupName);
}
return result;
}
use of org.apache.commons.lang3.StringUtils.isNoneEmpty in project java-jotasync by trixon.
the class JobExecutor method run.
@Override
public void run() {
mLastRun = System.currentTimeMillis();
String dryRunIndicator = "";
if (mDryRun) {
dryRunIndicator = String.format(" (%s)", Dict.DRY_RUN.toString());
}
appendHistoryFile(getHistoryLine(mJob.getId(), Dict.STARTED.toString(), dryRunIndicator));
String s = String.format("%s %s: '%s'='%s'", Jota.nowToDateTime(), Dict.START.toString(), Dict.JOB.toString(), mJob.getName());
mOutBuffer.append(s).append("\n");
send(ProcessEvent.OUT, s);
JobExecuteSection jobExecute = mJob.getExecuteSection();
try {
String command;
// run before first task
command = jobExecute.getBeforeCommand();
if (jobExecute.isBefore() && StringUtils.isNoneEmpty(command)) {
run(command, jobExecute.isBeforeHaltOnError(), mJobExecBundle.getString("JobPanel.beforePanel.header"));
}
runTasks();
if (mNumOfFailedTasks == 0) {
// run after last task - if all ok
command = jobExecute.getAfterSuccessCommand();
if (jobExecute.isAfterSuccess() && StringUtils.isNoneEmpty(command)) {
run(command, false, mJobExecBundle.getString("JobPanel.afterSuccessPanel.header"));
}
} else {
s = String.format(Dict.TASKS_FAILED.toString(), mNumOfFailedTasks);
mOutBuffer.append(s).append("\n");
send(ProcessEvent.OUT, s);
// run after last task - if any failed
command = jobExecute.getAfterFailureCommand();
if (jobExecute.isAfterFailure() && StringUtils.isNoneEmpty(command)) {
run(command, false, mJobExecBundle.getString("JobPanel.afterFailurePanel.header"));
}
}
// run after last task
command = jobExecute.getAfterCommand();
if (jobExecute.isAfter() && StringUtils.isNoneEmpty(command)) {
run(command, false, mJobExecBundle.getString("JobPanel.afterPanel.header"));
}
Thread.sleep(500);
appendHistoryFile(getHistoryLine(mJob.getId(), Dict.DONE.toString(), dryRunIndicator));
s = String.format("%s %s: %s", Jota.nowToDateTime(), Dict.DONE.toString(), Dict.JOB.toString());
mOutBuffer.append(s).append("\n");
updateJobStatus(0);
writelogs();
send(ProcessEvent.FINISHED, s);
Xlog.timedOut(String.format(Dict.JOB_FINISHED.toString(), mJob.getName()));
} catch (InterruptedException ex) {
mCurrentProcess.destroy();
appendHistoryFile(getHistoryLine(mJob.getId(), Dict.CANCELED.toString(), dryRunIndicator));
updateJobStatus(99);
writelogs();
mServer.getClientCallbacks().stream().forEach((clientCallback) -> {
try {
clientCallback.onProcessEvent(ProcessEvent.CANCELED, mJob, null, null);
} catch (RemoteException ex1) {
// nvm Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex1);
}
});
} catch (IOException ex) {
writelogs();
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
} catch (ExecutionFailedException ex) {
// Logger.getLogger(JobExecutor.class.getName()).log(Level.SEVERE, null, ex);
// send(ProcessEvent.OUT, "before failed and will not continue");
appendHistoryFile(getHistoryLine(mJob.getId(), Dict.FAILED.toString(), dryRunIndicator));
updateJobStatus(1);
writelogs();
send(ProcessEvent.FAILED, String.format("\n\n%s", Dict.JOB_FAILED.toString()));
}
mServer.getJobExecutors().remove(mJob.getId());
}
use of org.apache.commons.lang3.StringUtils.isNoneEmpty in project mes by qcadoo.
the class GenerateMaterialRequirementCoverageListeners method createDelivery.
/**
* createOffer event handler
*
* @param view
* @param state
* @param args
*/
public void createDelivery(final ViewDefinitionState view, final ComponentState state, final String[] args) {
init();
GridComponent grid = (GridComponent) view.getComponentByReference(L_GRID);
Entity parameter = parameterService.getParameter();
Entity systemCurrency = parameter.getBelongsToField(ParameterFields.CURRENCY);
DataDefinition companyDataDefinition = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_COMPANY);
Map<Optional<Integer>, List<Entity>> groupedCoverageProducts = grid.getSelectedEntities().stream().collect(Collectors.groupingBy(e -> Optional.ofNullable(e.getIntegerField("companyId"))));
StringBuilder deliveryNumbers = new StringBuilder();
for (Map.Entry<Optional<Integer>, List<Entity>> entry : groupedCoverageProducts.entrySet()) {
String number = numberGeneratorService.generateNumber(DeliveriesConstants.PLUGIN_IDENTIFIER, DeliveriesConstants.MODEL_DELIVERY);
Entity delivery = deliveriesService.getDeliveryDD().create();
delivery.setField(NUMBER, number);
Entity currency = null;
if (entry.getKey().isPresent()) {
Entity supplier = companyDataDefinition.get(entry.getKey().get().longValue());
delivery.setField(SUPPLIER, supplier);
currency = supplier.getBelongsToField(CompanyFieldsD.CURRENCY);
}
if (currency == null) {
currency = systemCurrency;
}
delivery.setField(CURRENCY, currency);
delivery.setField(EXTERNAL_SYNCHRONIZED, true);
Entity saved = deliveriesService.getDeliveryDD().save(delivery);
if (saved.isValid()) {
deliveryNumbers.append("<br/>").append(number);
entry.getValue().forEach(coverageProduct -> {
Integer product = coverageProduct.getIntegerField("productId");
BigDecimal reserveMissingQuantity = coverageProduct.getDecimalField(CoverageProductFields.RESERVE_MISSING_QUANTITY);
BigDecimal orderedQuantity = reserveMissingQuantity.min(BigDecimal.ZERO).abs();
BigDecimal conversion = getConversion(product);
Entity orderedProduct = orderedProductDataDefinition.create();
orderedProduct.setField("delivery", saved);
orderedProduct.setField("product", product.longValue());
orderedProduct.setField("orderedQuantity", reserveMissingQuantity.min(BigDecimal.ZERO).abs());
orderedProduct.setField(OrderedProductFields.CONVERSION, conversion);
orderedProduct.setField(OrderedProductFields.ADDITIONAL_QUANTITY, orderedQuantity.multiply(conversion, numberService.getMathContext()));
orderedProductDataDefinition.save(orderedProduct);
});
}
if (parameter.getBooleanField(L_REQUIRE_SUPPLIER_IDENTIFICATION) && Objects.isNull(delivery.getBelongsToField(SUPPLIER))) {
state.addMessage("orderSupplies.materialRequirementCoverage.deliveries.requireSupplierIdentification", MessageType.INFO, false);
}
}
if (StringUtils.isNoneEmpty(deliveryNumbers.toString())) {
state.addMessage("orderSupplies.materialRequirementCoverage.deliveries.created", MessageType.SUCCESS, false, deliveryNumbers.toString());
} else {
state.addMessage("orderSupplies.materialRequirementCoverage.deliveries.notCreated", MessageType.INFO, false);
}
}
use of org.apache.commons.lang3.StringUtils.isNoneEmpty in project Eidolons by IDemiurge.
the class UnitDataSource method getArmorObj.
@Override
public ValueContainer getArmorObj() {
final DC_ArmorObj armor = unit.getArmor();
final ValueContainer container;
if (armor != null) {
container = new ValueContainer(getOrCreateR(armor.getImagePath()));
WeaponTooltip tooltip = new WeaponTooltip();
tooltip.setUserObject(new WeaponToolTipDataSource() {
@Override
public List<ValueContainer> getMainParams() {
return Arrays.stream(ARMOR_TOOLTIP).map(el -> new ValueContainer(el.getName(), armor.getStrParam(el)).pad(10)).collect(Collectors.toList());
}
@Override
public List<ValueContainer> getBuffs() {
return armor.getBuffs().stream().filter(obj -> StringUtils.isNoneEmpty(obj.getType().getProperty(G_PROPS.IMAGE))).map(AttackTooltipFactory.getObjValueContainerMapper()).collect(Collectors.toList());
}
});
container.addListener(tooltip.getController());
} else {
container = new ValueContainer(getOrCreateR(CELL_TYPE.ARMOR.getSlotImagePath()));
}
return container;
}
Aggregations