public static String getEnvCMSHome() { String cmsHome = System.getenv().get(CMS_HOME); if (StringUtils.isNullOrEmpty(cmsHome)) { cmsHome = System.getProperty(CMS_HOME); if (StringUtils.isNullOrEmpty(cmsHome)) { return null; } } return cmsHome; }
public static String generateEmbedIdByEmbedPath(String embedPath, String embedId) { CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(embedPath)); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(embedId)); return StringUtils.join(IEntity.ID_SEP, embedPath, embedId); }
public static String join(String separator, String... array) { return join(separator, Arrays.asList(array)); }
public static String getEmbedPath(String embedId) { String[] idParts = embedId.split(ID_SEP_REG); if (idParts.length < 4) { return null; } return StringUtils.join(IEntity.ID_SEP, Arrays.asList(idParts).subList(0, idParts.length - 1)); }
private final void checkArguments(String branchId, String entityId, String entityType) { CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(branchId), "Miss valid branch id"); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(entityId), "Miss valid entity id"); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(entityType), "Miss valid entity type"); }
public static String generateEmbedPath(String rootType, String parentId, MetaField metaField) { CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(parentId)); CheckConditions.checkNotNull(metaField); String genPath = null; if(parentId.startsWith(rootType)){ genPath = StringUtils.join(IEntity.ID_SEP, parentId, metaField.getName()); } else { genPath = StringUtils.join(IEntity.ID_SEP, rootType, parentId, metaField.getName()); } return genPath; }
public static String getParentId(String embedId) { String[] idParts = embedId.split(ID_SEP_REG); if(idParts.length <= 4){ return idParts[1]; } return StringUtils.join(IEntity.ID_SEP, Arrays.asList(idParts).subList(0, idParts.length-2)); }
private final void checkArguments(String branchId, String entityId, String entityType) { CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(branchId), "Miss valid branch id"); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(entityId), "Miss valid entity id"); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(entityType), "Miss valid entity type"); }
/** * Mongo array operations doesn't not support $ with pullAll. Find the extract index number. */ protected String getEmbedPath(BitSet arrayBits, String embedId, DBObject getObject, MetaClass rootMetaClass) { List<String> updatePathList = new ArrayList<String>(); getArrayOffsetPath(arrayBits, embedId, getObject, rootMetaClass, updatePathList); return StringUtils.join(EntityIDHelper.DOT, updatePathList); }
public String[] splitPath(String path, boolean check) { if (!StringUtils.isNullOrEmpty(path)) { String[] idParts = path.split(IEntity.ID_SEP_REG); if (idParts.length % 2 == 1) { return idParts; } } if (check) { throw new CmsEntMgrException(EntMgrErrCodeEnum.INVALID_HOST_ENTITY_PATH, MessageFormat.format( "invalid inner class path {0}", path)); } else { return new String[0]; } }
/** * Mongo array operations doesn't not support $ with pullAll. Find the extract index number. */ protected String getEmbedPath(BitSet arrayBits, String embedId, DBObject getObject, MetaClass rootMetaClass) { List<String> updatePathList = new ArrayList<String>(); getArrayOffsetPath(arrayBits, embedId, getObject, rootMetaClass, updatePathList); return StringUtils.join(FlattenEntityIDHelper.DOT, updatePathList); }
private void loadConfigFromInputStream(InputStream in) { try { Properties p = new Properties(); p.load(in); String conn = p.getProperty(MONGO_CONNECTION); if (!StringUtils.isNullOrEmpty(conn)) { mongoConnection = conn; } String serverName = p.getProperty(SERVER_NAME); if (!StringUtils.isNullOrEmpty(serverName)) { this.serverName = serverName; } allowReggexFullScan = Boolean.parseBoolean(p.getProperty(ALLOW_REGGEX_FULL_SCAN)); } catch (IOException e) { logger.error("failed to load file from default config file", e); throw new RuntimeException("failed to load file from default config file", e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { logger.error("failed to close config file", e); throw new RuntimeException("failed to close config file", e); } } } }
protected String getUpdatePath(BitSet arrayBits, String embedId, DBObject getObject, MetaClass rootMetaClass) { // mongodb only support one $ in the dot notation path List<String> updatePathList = new ArrayList<String>(); if (arrayBits.cardinality() <= 1) { // use $ operator for 1- array in the path: a.$.b or a.b.$ getArrayLocatorPath(arrayBits, embedId, rootMetaClass, updatePathList); } else { // use offset for 2+ array in the path: a.0.b.1 getArrayOffsetPath(arrayBits, embedId, getObject, rootMetaClass, updatePathList); } return StringUtils.join(EntityIDHelper.DOT, updatePathList); }
static List<ServerAddress> parseServerString(String servers) { CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(servers)); ArrayList<ServerAddress> addrs = new ArrayList<ServerAddress>(); String[] serverList = servers.split(","); for (String server : serverList) { String[] pair = server.split(":"); try { if(pair.length == 1) { addrs.add(new ServerAddress(pair[0].trim())); } else if (pair.length == 2) { addrs.add(new ServerAddress(pair[0].trim(), Integer.valueOf(pair[1].trim()))); } else { throw new RuntimeException("Bad server string: " + servers); } } catch (UnknownHostException e) { throw new RuntimeException("parse server string error", e); } } return addrs; }
protected String getUpdatePath(BitSet arrayBits, String embedId, DBObject getObject, MetaClass rootMetaClass) { // mongodb only support one $ in the dot notation path List<String> updatePathList = new ArrayList<String>(); if (arrayBits.cardinality() <= 1) { // use $ operator for 1- array in the path: a.$.b or a.b.$ getArrayLocatorPath(arrayBits, embedId, rootMetaClass, updatePathList); } else { // use offset for 2+ array in the path: a.0.b.1 getArrayOffsetPath(arrayBits, embedId, getObject, rootMetaClass, updatePathList); } return StringUtils.join(FlattenEntityIDHelper.DOT, updatePathList); }
public JsonEntity getJoinCursorValue(int index, MetaClass meta) { if (cursorValues == null) { return null; } JsonEntity entity = null; if (index >= 0 && cursorValues.size() > index) { String oid = cursorValues.get(index); if (!StringUtils.isNullOrEmpty(oid)) { entity = new JsonEntity(meta); entity.setId(oid); } } return entity; }
/** * Mongo array operations doesn't not support $ with pullAll. Find the extract index number. */ protected String getEmbedPath(BitSet arrayBits, String embedId, DBObject getObject, MetaClass rootMetaClass) { List<String> updatePathList = new ArrayList<String>(); getArrayOffsetPath(arrayBits, embedId, getObject, rootMetaClass, updatePathList); return StringUtils.join(EntityIDHelper.DOT, updatePathList); }
private void checkIndexName() { CheckConditions.checkCondition(!StringUtils.isNullOrEmpty(indexName) && !StringUtils.isNullOrEmpty(indexName.trim()), new IllegalIndexException("index name can not be empty")); CheckConditions.checkCondition(indexName.length() < CMSConsts.MAX_LENGTH_OF_INDEX_NAME, new IllegalIndexException("The length of index name can not be exceed " + CMSConsts.MAX_LENGTH_OF_INDEX_NAME)); CheckConditions.checkCondition(PATTERN.matcher(getIndexName()).matches(), new IllegalIndexException( "index name must be characters of [A-Za-z0-9_]*!")); }
protected String getUpdatePath(BitSet arrayBits, String embedId, DBObject getObject, MetaClass rootMetaClass) { // mongodb only support one $ in the dot notation path List<String> updatePathList = new ArrayList<String>(); if (arrayBits.cardinality() <= 1) { // use $ operator for 1- array in the path: a.$.b or a.b.$ getArrayLocatorPath(arrayBits, embedId, rootMetaClass, updatePathList); } else { // use offset for 2+ array in the path: a.0.b.1 getArrayOffsetPath(arrayBits, embedId, getObject, rootMetaClass, updatePathList); } return StringUtils.join(EntityIDHelper.DOT, updatePathList); }
private Map<String, MetaClass> prepareMetaClassMap(List<MetaClass> metaClasses) { HashMap<String, MetaClass> metas = new HashMap<String, MetaClass>(); HashSet<String> pluralNames = new HashSet<String>(); for (MetaClass m : metaClasses) { String name = m.getName(); String pluralName = m.getpluralName(); if (StringUtils.isNullOrEmpty(name)) { throw new IllegalMetaClassException("meta class name can not be empty"); } if (metas.containsKey(name) || metas.containsKey(pluralName)) { throw new IllegalMetaClassException("duplicate metaClass name in batchUpsert"); } if (pluralNames.contains(name) || pluralNames.contains(pluralName)) { throw new IllegalMetaClassException("duplicate metaClass plural name in batchUpsert"); } if (pluralName != null) { pluralNames.add(pluralName); } metas.put(name, m); } return metas; }