/** * Tries to convert the wrapped value to a roman numeral representation * This only works if the wrapped value can be converted to <tt>int</tt> and is >0 and <4000. * * @param defaultValue the value to be converted to roman numeral if the wrapped value can not be converted * @return a roman numeral representation of either the wrapped value or the defaultValue. values >=4000 and * <=0 are represented as an empty String */ public String asRomanNumeral(int defaultValue) { return RomanNumeral.toRoman(asInt(defaultValue)); }
/** * Returns the integer value for the given key. * * @param key the key used to lookup the value * @return the integer value stored in the config or 0 if an invalid value is present */ public int getInt(String key) { return get(key).asInt(0); }
@SuppressWarnings({"unchecked", "raw", "rawtypes"}) @Override protected Object transformFromDatasource(Class<? extends BaseMapper<?, ?, ?>> mapperType, Value data) { if (data.isNull()) { return null; } if (ordinal) { Object[] values = field.getType().getEnumConstants(); int index = data.asInt(0); index = Math.min(index, values.length - 1); return values[index]; } return data.asEnum((Class<Enum>) field.getType()); }
protected Extension(String type, String id, ConfigObject configObject, ConfigObject defaultConfig) { super(configObject.toConfig()); this.type = type; this.id = id; this.configObject = configObject; this.defaultConfig = defaultConfig; this.priority = get(PRIORITY).asInt(PriorityCollector.DEFAULT_PRIORITY); }
/** * Executes the query and returns the resulting items as a {@link sirius.web.controller.Page}. * Using the Parameter 'start' in the given WebContext as the effectiveStart of the result. * * @param ctx the Webcontext in which to look for the start parameter * @return the result of the query along with all facets and paging-metadata */ public Page<E> queryPage(WebContext ctx) { return this.page(ctx.get("start").asInt(1)).queryPage(); }
/** * Handles requests to /ui/log * * @param ctx the context describing the current request */ @Routed(value = "/ui/log", priority = PriorityCollector.DEFAULT_PRIORITY - 1) public void log(WebContext ctx) { int start = ctx.get("start").asInt(1) - 1; int pageSize = 50; List<APILog.Entry> entries = log.getEntries(start, pageSize + 1); boolean canPagePrev = start > 0; boolean canPageNext = entries.size() > pageSize; if (canPageNext) { entries.remove(entries.size() - 1); } ctx.respondWith() .template("templates/log.html.pasta", entries, canPagePrev, canPageNext, (start + 1) + " - " + (start + entries.size()), Math.max(1, start - pageSize + 1), start + pageSize + 1); }
int number = part.queryValue("PartNumber").asInt(0); parts.put(number, new File(getUploadDir(uploadId), String.valueOf(number))); });
@SuppressWarnings("unchecked") protected Boolean invokeHandlerForRow(Function<E, Boolean> handler, Row row) { try { E entity = (E) descriptor.make(OMA.class, alias, key -> row.hasValue(key) ? row.getValue(key) : null); if (descriptor.isVersioned()) { entity.setVersion(row.getValue(BaseMapper.VERSION).asInt(0)); } entity.fetchRow = row; return handler.apply(entity); } catch (Exception e) { throw Exceptions.handle() .to(OMA.LOG) .error(e) .withSystemErrorMessage("Cannot transform a row into an entity of type '%s' for query '%s'", descriptor.getType().getName(), qry.toString()) .handle(); } }
/** * Handles GET /bucket * * @param ctx the context describing the current request * @param bucket the bucket of which the contents should be listed */ private void listObjects(WebContext ctx, Bucket bucket) { int maxKeys = ctx.get("max-keys").asInt(1000); String marker = ctx.get("marker").asString(); String prefix = ctx.get("prefix").asString(); Response response = ctx.respondWith(); response.setHeader(HTTP_HEADER_NAME_CONTENT_TYPE, CONTENT_TYPE_XML); bucket.outputObjects(response.xml(), maxKeys, marker, prefix); }
/** * Creates a new entity for the given descriptor based on the given doc. * * @param ed the descriptor of the entity to create * @param doc the document to read the values from * @param <E> the effective type of the generated entity * @return the generated entity */ @SuppressWarnings("unchecked") public static <E extends MongoEntity> E make(EntityDescriptor ed, Doc doc) { try { E result = (E) ed.make(Mango.class, null, key -> doc.getUnderlyingObject().containsKey(key) ? doc.get(key) : null); if (ed.isVersioned()) { result.setVersion(doc.get(VERSION).asInt(0)); } return result; } catch (Exception e) { throw Exceptions.handle(Mongo.LOG, e); } }
int currentHour = Values.of(params).at(1).asInt(25); output.line("Executing daily timers for hour: " + currentHour); ts.runEveryDayTimers(currentHour);
private void createIndex(EntityDescriptor ed, MongoDatabase client, Index index) { try { Document document = new Document(); for (int i = 0; i < index.columns().length; i++) { Value setting = Value.of(index.columnSettings()[i]); document.append(index.columns()[i], setting.isNumeric() ? setting.asInt(1) : setting.asString()); } Mongo.LOG.INFO("Creating MongoDB index %s for: %s...", index.name(), ed.getRelationName()); client.getCollection(ed.getRelationName()).createIndex(document, new IndexOptions().unique(index.unique())); } catch (Exception e) { Exceptions.handle() .error(e) .to(Mongo.LOG) .withSystemErrorMessage("Failed to create index %s of %s (%s) - %s (%s)", index.name(), ed.getType().getName(), ed.getRelationName()) .handle(); } } }
if (parameters.length() > 1) { mongo.tracing = "enable".equals(parameters.at(1).asString()); mongo.traceLimit = parameters.at(2).asInt(0);
ext.get(KEY_PASSWORD).asString(); this.initialSize = ext.get(KEY_INITIAL_SIZE).isFilled() ? ext.get(KEY_INITIAL_SIZE).asInt(0) : profile.get(KEY_INITIAL_SIZE).asInt(0); this.maxActive = ext.get(KEY_MAX_ACTIVE).isFilled() ? ext.get(KEY_MAX_ACTIVE).asInt(10) : profile.get(KEY_MAX_ACTIVE).asInt(10); this.maxIdle = ext.get(KEY_MAX_IDLE).isFilled() ? ext.get(KEY_MAX_IDLE).asInt(1) : profile.get(KEY_MAX_IDLE).asInt(1); this.validationQuery = ext.get(KEY_VALIDATION_QUERY).isEmptyString() ? Formatter.create(profile.get(KEY_VALIDATION_QUERY).asString()).set(ctx).format() :