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; }
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"); }
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 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]; } }
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 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; }
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_]*!")); }
/** * Returns the pagination mode specified by the given string. * Return configed default mode if the given mode is null. * Return null if the given string is not null, but not parsable */ public PaginationMode parsePaginationMode(String mode) { String m = mode; if (StringUtils.isNullOrEmpty(m)) { m = (String) dbConfig.get(CMSDBConfig.SYS_QUERY_PAGINATION_MODE); } for (PaginationMode pm : PaginationMode.values()) { if (pm.name().equalsIgnoreCase(m)) { return pm; } } return null; }
public ConsistentPolicy parsePolicy(String policy) { String rp = policy; if (StringUtils.isNullOrEmpty(rp)) { rp = ConsistentPolicy.SECONDARY_PREFERRED.getName(); } String writeConcern = (String) dbConfig.get(CMSDBConfig.SYS_WRITE_CONCERN); return ConsistentPolicy.parseString(rp, writeConcern); }
protected void validateDbName() { if(!StringUtils.isNullOrEmpty(getDbName())) { throw new IllegalMetaClassException(getName() + ": dbName must NOT be provided"); } if(!StringUtils.isNullOrEmpty(getValueDbName())) { throw new IllegalMetaClassException(getName() + ": valueDbName must NOT be provided"); } if(!StringUtils.isNullOrEmpty(getFlattenValueDbName())) { throw new IllegalMetaClassException(getName() + ": flattenValueDbName must NOT be provided"); } }
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 void parseQueryCursor(ParseQueryNode node, int totalQueryNodeCount) { if (StringUtils.isNullOrEmpty(cursorString)) { cursor.setJoinCursor(totalQueryNodeCount > 1); return; } if (totalQueryNodeCount == 1) { MetaClass meta = node.getMetaClass(); JsonEntity entity = new JsonEntity(meta, cursorString); cursor.setSingleCursorValue(entity); } else { String[] joinOids = cursorString.split(","); cursor.setJoinCursorValues(Arrays.asList(joinOids)); } } public void setCursor(QueryCursor cursor) {
private void checkMetaClassName(String name) { CheckConditions.checkCondition(!StringUtils.isNullOrEmpty(name), new IllegalMetaClassException("meta class name can not be empty")); CheckConditions.checkCondition(!StringUtils.isNullOrEmpty(name.trim()), new IllegalMetaClassException("meta class name can not be empty")); CheckConditions.checkCondition(!(isSystem(name)), new IllegalMetaClassException("meta class name cannot begin with 'system.' prefix")); CheckConditions.checkCondition(containsValidCharacters(name,CMSConsts.INVALID_META_CLASS_NAME_CHARACTERS), new IllegalMetaClassException("meta class name cannot contains invalid characters: " + Arrays.toString(CMSConsts.INVALID_META_CLASS_NAME_CHARACTERS))); }
public MongoMutex(Mongo mongo, String dbName, String collName, String lockName, String clientName, int expireTime, int renewPeriod) { super(); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(dbName), "dbName should not be null or empty"); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(collName), "collName should not be null or empty"); CheckConditions.checkArgument(mongo != null, "mongo should not be null"); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(lockName), "lockName should not be null or empty"); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(clientName), "clientName should not be null or empty"); CheckConditions.checkArgument(expireTime >= 1000, "expireTime must be larger than 1 second"); CheckConditions.checkArgument(renewPeriod >= 400, "renewPeroid must larger than 0.4 second so renew will not cost cpu alot"); CheckConditions.checkArgument(expireTime - renewPeriod >= 1000, "expireTime - renewPeriod must be larger than 1 second so client have enough time to renew"); this.lockName = lockName; this.clientName = clientName; this.expireTime = expireTime; this.renewPeriod = renewPeriod; coll = mongo.getDB(dbName).getCollection(collName); coll.setWriteConcern(WriteConcern.SAFE); createIfNotExist(coll, lockName); }
@JsonIgnore public MetaClass getParentMetaClass() { if (StringUtils.isNullOrEmpty(parent)) { return null; } if (metadataService == null) { throw new MetaDataException(MetaErrCodeEnum.NO_METASERVICE_PROVIDED, "no MetadataService provided to retrieve parent MetaClass"); } return metadataService.getMetaClass(parent, parentVersion, new MetadataContext()); }
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 void validate() { CheckConditions.checkCondition(!RESERVED_FIELD_NAME.contains(getName()), new IllegalMetaClassException(String.format("Reserved meta field name %s!", getName()))); CheckConditions.checkCondition(!StringUtils.isNullOrEmpty(getName()), new IllegalMetaClassException("meta field name can not be empty")); CheckConditions.checkCondition(!StringUtils.isNullOrEmpty(getName().trim()), new IllegalMetaClassException("meta field name can not be empty")); CheckConditions.checkCondition(org.apache.commons.lang.StringUtils.containsNone(getName(),CMSConsts.INVALID_META_FIELD_NAME_CHARACTERS), new IllegalMetaClassException("meta field " + name + " cannot contains invalid characters: " + Arrays.toString(CMSConsts.INVALID_META_FIELD_NAME_CHARACTERS))); if(!isInternal()) { CheckConditions.checkCondition(!INVALID_PATTERN.matcher(getName()).matches(), new IllegalMetaClassException("meta field name can not start with regex _[A-Za-z0-9]: " + getName())); } }
public void setupAncestors(MetaClass meta, IMetadataService metadataService, Map<String, MetaClass> metas) { if (meta.getParent() == null) { return; } ArrayList<String> ancestorList = new ArrayList<String>(); String p = meta.getParent(); while(!StringUtils.isNullOrEmpty(p)) { ancestorList.add(p); MetaClass m = metadataService.getMetaClass(p); if (m == null) { m = metas.get(p); } CheckConditions.checkCondition(m != null, new IllegalMetaClassException("can not get metaclass: " + p + " while setup ancestors for " + meta.getName())); p = m.getParent(); CheckConditions.checkCondition(p == null || !p.equals(meta.getName()), new IllegalMetaClassException("circle found for metaclass inherent")); } meta.setAncestors(ancestorList); // this.ancestors = ancestorList; }
private IEntity createBsonEntity(Branch branch, PersistenceContext persistenceContext) { MetaClass branchMeta = persistenceContext.getMetaClass(BranchMetaClass.TYPE_NAME); IEntity bsonEntity = toBson(branch, branchMeta, persistenceContext); if (StringUtils.isNullOrEmpty(entityContext.getModifier())) { bsonEntity.setCreator("system"); } else { bsonEntity.setCreator(entityContext.getModifier()); } return bsonEntity; }
private IEntity getUnMergedHostEntity(IEntity entity, EntityContext context, PersistenceContext persistenceContext) { String repoName = entity.getRepositoryName(); String branchId = entity.getBranchId(); IBranch branchEntity = branchHelper.getAndCheckCurrentBranch(repoName, branchId, context); String host = entity.getHostEntity(); if (StringUtils.isNullOrEmpty(host)) { host = context.getPath(); entity.setHostEntity(host); } String[] idParts = entityHelper.splitPath(host, true); IEntity queryEntity = entityGetManager.getHostEntity(entity, host, idParts, persistenceContext, true); return entityHelper.getAndCheckExsitingEntity(queryEntity, branchEntity, persistenceContext); }