private static byte[] parseHexString(final String s) { if (!isValid(s)) { throw new IllegalArgumentException("invalid hexadecimal representation of an ObjectId: [" + s + "]"); } byte[] b = new byte[OBJECT_ID_LENGTH]; for (int i = 0; i < b.length; i++) { b[i] = (byte) Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16); } return b; }
@Signature public static boolean isValid(String hexString) { return ObjectId.isValid(hexString); } }
private Document parseUpdateKey(String updateKey, Map doc) { Document retVal; if (updateKey.equals("_id") && ObjectId.isValid(((String) doc.get(updateKey)))) { retVal = new Document("_id", new ObjectId((String) doc.get(updateKey))); } else if (updateKey.contains(",")) { String[] parts = updateKey.split(",[\\s]*"); retVal = new Document(); for (String part : parts) { retVal.append(part, doc.get(part)); } } else { retVal = new Document(updateKey, doc.get(updateKey)); } return retVal; }
@Override public boolean check(Environment env, Memory value, boolean nullable, String staticClassName) { return value.instanceOf(WrapObjectId.class) || ObjectId.isValid(value.toString()); }
@Override public Input find(String id) throws NotFoundException { if (!ObjectId.isValid(id)) { throw new NotFoundException("Input id <" + id + "> is invalid!"); } final DBObject o = get(org.graylog2.inputs.InputImpl.class, id); if (o == null) { throw new NotFoundException("Input <" + id + "> not found!"); } return new org.graylog2.inputs.InputImpl((ObjectId) o.get(InputImpl.FIELD_ID), o.toMap()); }
if (ObjectId.isValid(id.toString())) { return new ObjectId(id.toString());
protected Object convert(Path<?> property, Constant<?> constant) { if (isReference(property)) { return asReference(constant.getConstant()); } else if (isId(property)) { if (isReference(property.getMetadata().getParent())) { return asReferenceKey(property.getMetadata().getParent().getType(), constant.getConstant()); } else if (constant.getType().equals(String.class) && isImplicitObjectIdConversion()) { String id = (String) constant.getConstant(); return ObjectId.isValid(id) ? new ObjectId(id) : id; } } return visit(constant, null); }
protected Object convert(Path<?> property, Constant<?> constant) { if (isReference(property)) { return asReference(constant.getConstant()); } else if (isId(property)) { if (isReference(property.getMetadata().getParent())) { return asReferenceKey(property.getMetadata().getParent().getType(), constant.getConstant()); } else if (constant.getType().equals(String.class) && isImplicitObjectIdConversion()) { String id = (String) constant.getConstant(); return ObjectId.isValid(id) ? new ObjectId(id) : id; } } return visit(constant, null); }
/** * Converts the given raw id value into either {@link ObjectId} or {@link String}. * * @param id * @return */ @Nullable public Object convertId(@Nullable Object id) { if (id == null) { return null; } if (id instanceof String) { return ObjectId.isValid(id.toString()) ? conversionService.convert(id, ObjectId.class) : id; } try { return conversionService.canConvert(id.getClass(), ObjectId.class) ? conversionService.convert(id, ObjectId.class) : delegateConvertToMongoType(id, null); } catch (ConversionException o_O) { return delegateConvertToMongoType(id, null); } }
protected Object convert(Path<?> property, Constant<?> constant) { if (isReference(property)) { return asReference(constant.getConstant()); } else if (isId(property)) { if (isReference(property.getMetadata().getParent())) { return asReferenceKey(property.getMetadata().getParent().getType(), constant.getConstant()); } else if (constant.getType().equals(String.class) && isImplicitObjectIdConversion()) { String id = (String) constant.getConstant(); return ObjectId.isValid(id) ? new ObjectId(id) : id; } } return visit(constant, null); }
public void setId(String id) { E.illegalArgumentIf(!ObjectId.isValid(id), "Invalid Object Id: %s", id); this.id = Long.valueOf(id); }
public static String babbleToMongod( String b ){ if ( ! isValid( b ) ) throw new IllegalArgumentException( "invalid object id: " + b ); StringBuilder buf = new StringBuilder( 24 ); for ( int i=7; i>=0; i-- ) buf.append( _pos( b , i ) ); for ( int i=11; i>=8; i-- ) buf.append( _pos( b , i ) ); return buf.toString(); }
private static BsonValue getIdAsStringOrObjectId(String id) { if (ObjectId.isValid(id)) { return getIdAsObjectId(id); } return new BsonString(id); }
private static BsonObjectId getIdAsObjectId(String id) throws IllegalArgumentException { if (!ObjectId.isValid(id)) { throw new IllegalArgumentException("The id is not a valid ObjectId " + id); } return new BsonObjectId(new ObjectId(id)); }
/** * * @param etag * @return */ private static ObjectId getEtagAsObjectId(String etag) { if (etag == null) { return null; } if (ObjectId.isValid(etag)) { return new ObjectId(etag); } else { return new ObjectId(); } }
@Override public void addCondition(Criteria criteria, FilterCondition filter, CriteriaHolder criteriaHolder) { /* Validate only strings */ this.validate(criteriaHolder, filter.getValue(), filter.isNegative(), INCORRECT_FILTER_PARAMETERS); if (!ObjectId.isValid(filter.getValue())) { criteria.regex("(?i).*" + Pattern.quote(filter.getValue()) + ".*"); } else { criteria.regex(".*" + filter.getValue() + ".*"); } }
@Override public Input find(String id) throws NotFoundException { if (!ObjectId.isValid(id)) { throw new NotFoundException("Input id <" + id + "> is invalid!"); } final DBObject o = get(org.graylog2.inputs.InputImpl.class, id); if (o == null) { throw new NotFoundException("Input <" + id + "> not found!"); } return new org.graylog2.inputs.InputImpl((ObjectId) o.get("_id"), o.toMap()); }
@Override public void addCondition(Criteria criteria, FilterCondition filter, CriteriaHolder criteriaHolder) { /* Validate only numbers & dates */ this.validate(criteriaHolder, filter.getValue(), filter.isNegative(), INCORRECT_FILTER_PARAMETERS); Object valueToFind = ObjectId.isValid(filter.getValue()) ? new ObjectId(filter.getValue()) : this.castValue(criteriaHolder, filter.getValue(), INCORRECT_FILTER_PARAMETERS); criteria.lt(valueToFind); }
@Override public void addCondition(Criteria criteria, FilterCondition filter, CriteriaHolder criteriaHolder) { /* Validate only numbers & dates */ this.validate(criteriaHolder, filter.getValue(), filter.isNegative(), INCORRECT_FILTER_PARAMETERS); Object valueToFind = ObjectId.isValid(filter.getValue()) ? new ObjectId(filter.getValue()) : this.castValue(criteriaHolder, filter.getValue(), INCORRECT_FILTER_PARAMETERS); criteria.lte(valueToFind); }
@Override public List<Launch> findLaunchIdsByProject(Project project) { Query query = query(where(PROJECT_ID_REFERENCE).is(isValid(project.getId()) ? new ObjectId(project.getId()) : project.getId())); query.fields().include(ID_REFERENCE); return mongoTemplate.find(query, Launch.class); }