public static MetaClass getMetaClass(Repository repoInst) { IMetadataService metaService = repoInst.getMetadataService(); MetaClass historyMetaClass = metaService.getMetaClass(NAME); if (historyMetaClass != null) { return historyMetaClass; } throw new RuntimeException("no history meta class found"); }
@Override public void validateMetaClass(String className) { MetaClass meta = repo.getMetadataService().getMetaClass(className); if (meta == null) { throw new MetaClassNotExistsException(repo.getRepositoryName(), className); } validator.validate(meta); }
@Override public void updateRepository(Repository repo) { CheckConditions.checkNotNull(repo, "repository can not be null"); CheckConditions.checkNotNull(repo.getRepositoryName(), "repository name can not be null"); String repositoryName = repo.getRepositoryName(); try { metadataLock.lock(); if (repo.getRepositoryAdmin() != null) { setDbo.put(Repository.REPOSITORY_FIELD_ADMIN_NAME, repo.getRepositoryAdmin()); setDbo.put(Repository.REPOSITORY_FIELD_TYPE_NAME, repo.getAccessType().name()); if (repo.getOptions() != null) { setDbo.put(Repository.REPOSITORY_FIELD_OPTIONS_NAME, repositoryOptionConverter.toBson(repo.getOptions()));
@Test public void testRepositoryConvert() { String repositoryName = "name"; Repository repo = new Repository(); repo.setRepositoryName(repositoryName); Date now = new Date(); repo.setCreateTime(now); repo.setState(Repository.StateEnum.normal); ObjectConverter<Repository> c = new ObjectConverter<Repository>(); String json = c.toJson(repo); Repository repo1 = c.fromJson(json, Repository.class); Assert.assertEquals(repo1.getRepositoryName(), repo.getRepositoryName()); Assert.assertEquals(repo1.getCreateTime(), repo.getCreateTime()); // Assert.assertEquals(repo1.getDeletedTime(), repo.getDeletedTime()); // Assert.assertEquals(repo1.getDeletingTime(), repo.getDeletingTime()); }
@Test public void testCreateRepository() { Repository createRepo = new Repository(); createRepo.setRepositoryName("testNewRepo-cmsServer"); Repository repo = server.createRepository(CMSPriority.NON_CRITICAL, createRepo); Assert.assertNotNull(server.getRepository(CMSPriority.NON_CRITICAL, repo.getRepositoryName())); IBranch branch = server.getBranch(CMSPriority.NON_CRITICAL, repo.getRepositoryName(), IBranch.DEFAULT_BRANCH, entityContext); Assert.assertNotNull(branch); }
public String getRepositoryName(){ return this.repo.getRepositoryName(); }
@Test(expected=RepositoryExistsException.class) public void testRepositoryCreationException() { String repoName = "testRepoCreation"; try { repositoryService.getRepository(repoName); Assert.fail(); } catch (Exception e) { // expected } Repository r = null; r = repositoryService.createRepository(new Repository("r2")); Assert.assertEquals("r2", r.getRepositoryName()); r = repositoryService.createRepository(new Repository("r2")); }
@Test public void testGetMetaClasses() { MetadataContext metaContext = new MetadataContext(); IMetadataService ms = repositoryService.getRepository("raptor-paas").getMetadataService(); List<MetaClass> metas = ms.getMetaClasses(metaContext); Assert.assertEquals(34, metas.size()); ms = repositoryService.getRepository("software-deployment").getMetadataService(); metas = ms.getMetaClasses(metaContext); Assert.assertEquals(16, metas.size()); ms = repositoryService.createRepository(new Repository("newCreatedForGetMetaClasses")).getMetadataService(); metas = ms.getMetaClasses(metaContext); Assert.assertEquals(2, metas.size()); }
raptorMetaService = repoService.getRepository(RAPTOR_REPO).getMetadataService(); deployMetaService = repoService.getRepository(DEPLOY_REPO).getMetadataService(); stratusMetaService = repoService.getRepository(STRATUS_REPO).getMetadataService(); cmsdbMetaService = repoService.getRepository(CMSDB_REPO).getMetadataService(); Repository repository = new Repository(); repository.setRepositoryName(RAPTOR_REPO); RepositoryOption repositoryOption = new RepositoryOption(); repositoryOption.setMaxIndexedArraySize(3); repository.setOptions(repositoryOption); repoService.updateRepository(repository);
@Test(expected = IllegalIndexException.class) public void testValidateForUpdateField_indexSize2() { int defaultSystemMaxIndexSize = CMSConsts.MAX_INDEXES_PER_META_CLASS; MetaClass mClass = new MetaClass(); mClass.setName("TestIndexSize"); mClass.setRepository(RAPTOR_PAAS); MetaOption metaOption = mClass.getOptions(); int maxIndexSizePerRepo = defaultSystemMaxIndexSize + 1; repo.getOptions().setMaxNumOfIndexes(maxIndexSizePerRepo); for (int i = 0; i <= maxIndexSizePerRepo; i++) { MetaAttribute attr = new MetaAttribute(); attr.setName("field" + i); IndexInfo index = new IndexInfo("index" + i); metaOption.addIndex(index); } IMetadataService metaService = repo.getMetadataService(); try { metaService.createMetaClass(mClass, new MetadataContext()); } catch (IllegalIndexException e) { throw e; } finally { repo.getOptions().setMaxNumOfIndexes(null); } }
public Repository createRepository(CMSPriority p, Repository repo) { checkServerState(p, true); RepositoryOption repositoryOption = repo.getOptions(); if (null == repositoryOption.getMaxDocumentSize()) { repositoryOption.setMaxDocumentSize((Long) dbConfig.get(CMSDBConfig.DEFAULT_SYS_LIMIT_MAX_DOCUMENT_SIZE)); branch.setRepositoryName(repo.getRepositoryName()); branch.setMainBranch(true); branch.setId(IBranch.DEFAULT_BRANCH);
RepositoryOption repositoryOption = repo.getOptions(); Integer maxNumOfIndexes = CMSConsts.MAX_INDEXES_PER_META_CLASS; if (repositoryOption != null && repositoryOption.getMaxNumOfIndexes() != null) {
@Test public void testModifyInner() { int maxIndexedArraySize = 3; RepositoryOption option = new RepositoryOption(); option.setMaxIndexedArraySize(maxIndexedArraySize); Repository repo = repoService.getRepository(RAPTOR_REPO); RepositoryOption oldOption = repo.getOptions(); repo.setOptions(option); EntityContext context = newEntityContext(); IEntity door11 = buildQueryEntity(RAPTOR_REPO, IBranch.DEFAULT_BRANCH, "Door", "door11"); door11.setId("door11"); entityService.modify(door11, door11, context); repo.setOptions(oldOption); }
String repoName = "testRepoUpdate"; String repoAdmin = "unit"; Repository repo = new Repository(repoName); AccessType oldAccessType = AccessType.Public; repo.setAccessType(oldAccessType); repo.setCreateTime(new Date()); repo.setRepositoryAdmin(repoAdmin); Assert.assertEquals(oldAccessType, r.getAccessType()); Assert.assertEquals(repoAdmin, r.getRepositoryAdmin()); repo.setAccessType(newAccessType); String newAdmin = "newadmin"; repo.setRepositoryAdmin(newAdmin); repositoryService.updateRepository(repo); Repository getRepo = repositoryService.getRepository(repoName); Assert.assertEquals(newAccessType, getRepo.getAccessType()); Assert.assertEquals(newAdmin, getRepo.getRepositoryAdmin()); repo.setRepositoryAdmin(null); repositoryService.updateRepository(repo); getRepo = repositoryService.getRepository(repoName); Assert.assertEquals(newAccessType, getRepo.getAccessType()); Assert.assertEquals(newAdmin, getRepo.getRepositoryAdmin());
@Test public void testDeleteRepository() { Map<String, Object> newConfigs = new HashMap<String, Object>(); newConfigs.put(CMSDBConfig.SYS_ALLOW_REPOSITORY_DELETE, false); server.config(newConfigs); Repository createRepo = new Repository(); String repositoryName = "testDeleteRepo-cmsServer"; createRepo.setRepositoryName(repositoryName); server.createRepository(CMSPriority.NON_CRITICAL, createRepo); Repository getRepo = server.getRepository(CMSPriority.NEUTRAL, repositoryName); Assert.assertNotNull(getRepo); try { server.deleteRepository(CMSPriority.NEUTRAL, repositoryName); Assert.fail(); } catch (Exception e) { // expected as the configuration "SysAllowRepositoryDelete" should // be false } newConfigs = new HashMap<String, Object>(); newConfigs.put(CMSDBConfig.SYS_ALLOW_REPOSITORY_DELETE, true); server.config(newConfigs); server.deleteRepository(CMSPriority.NEUTRAL, repositoryName); try { server.getRepository(CMSPriority.NEUTRAL, repositoryName); Assert.fail(); } catch (RepositoryNotExistsException rnee) { // expected } }
@Test public void testBadReponameCreation() { String repoName = "test\"RepoCreation"; try { repositoryService.createRepository(new Repository(repoName)); Assert.fail(); } catch (MetaDataException e) { } //this repo name should not exist in the cms_sys db try { repositoryService.getRepository(repoName); Assert.fail(); } catch (Exception e) { e.printStackTrace(); } }
@Test public void testGetRepositories() { Repository repository = new Repository("repo1"); repository.setAccessType(AccessType.Private); repositoryService.createRepository(repository); List<Repository> publics = repositoryService.getRepositories(AccessType.Public); Assert.assertTrue(publics.size() > 0); List<Repository> privates = repositoryService.getRepositories(AccessType.Private); Assert.assertTrue(privates.size() > 0); }
@Override public List<Repository> getRepositories(AccessType type) { List<Repository> allRepos = cache.values(); List<Repository> result = new ArrayList<Repository>(); for (Repository repo : allRepos) { if (repo.getAccessType() == type) { result.add(repo); } } return result; }
public String getRepositoryName(){ return this.repo.getRepositoryName(); }
@Test public void testGetAll() { List<Repository> repos = repositoryService.getRepositories(new MetadataContext()); String repoName1 = "testGetAll1"; String repoName2 = "testGetAll2"; repositoryService.createRepository(new Repository(repoName1)); repositoryService.createRepository(new Repository(repoName2)); List<Repository> newRepos = repositoryService.getRepositories(new MetadataContext()); Assert.assertEquals(repos.size() + 2, newRepos.size()); boolean found1 = false; boolean found2 = false; for (Repository r : newRepos) { if (r.getRepositoryName().equals(repoName1)) found1 = true; if (r.getRepositoryName().equals(repoName2)) found2 = true; } Assert.assertTrue(found1 && found2); }