List of usage examples for com.mongodb BasicDBObject get
public Object get(final String key)
From source file:org.restheart.handlers.metadata.ResponseTranformerMetadataHandler.java
License:Open Source License
@Override void enforceDbRepresentationTransformLogic(HttpServerExchange exchange, RequestContext context) throws InvalidMetadataException { List<RepresentationTransformer> dbRts = RepresentationTransformer.getFromJson(context.getDbProps()); RequestContext.TYPE requestType = context.getType(); // DB or COLLECTION for (RepresentationTransformer rt : dbRts) { if (rt.getPhase() == RepresentationTransformer.PHASE.RESPONSE) { Transformer t = (Transformer) NamedSingletonsFactory.getInstance().get("transformers", rt.getName());//from w w w . j a va2s .c o m if (t == null) { throw new IllegalArgumentException( "cannot find singleton " + rt.getName() + " in singleton group transformers"); } if (rt.getScope() == RepresentationTransformer.SCOPE.THIS && requestType == RequestContext.TYPE.DB) { t.tranform(exchange, context, context.getResponseContent(), rt.getArgs()); } else if (rt.getScope() == RepresentationTransformer.SCOPE.CHILDREN && requestType == RequestContext.TYPE.COLLECTION) { BasicDBObject _embedded = (BasicDBObject) context.getResponseContent().get("_embedded"); // evaluate the script on children collection BasicDBList colls = (BasicDBList) _embedded.get("rh:coll"); if (colls != null) { for (String k : colls.keySet()) { DBObject coll = (DBObject) colls.get(k); t.tranform(exchange, context, coll, rt.getArgs()); } } } } } }
From source file:org.restheart.handlers.metadata.ResponseTranformerMetadataHandler.java
License:Open Source License
@Override void enforceCollRepresentationTransformLogic(HttpServerExchange exchange, RequestContext context) throws InvalidMetadataException { List<RepresentationTransformer> dbRts = RepresentationTransformer.getFromJson(context.getCollectionProps()); RequestContext.TYPE requestType = context.getType(); // DOCUMENT or COLLECTION for (RepresentationTransformer rt : dbRts) { if (rt.getPhase() == RepresentationTransformer.PHASE.RESPONSE) { Transformer t;//from w w w. j a va 2 s.c o m try { t = (Transformer) NamedSingletonsFactory.getInstance().get("transformers", rt.getName()); } catch (IllegalArgumentException ex) { context.addWarning("error applying transformer: " + ex.getMessage()); return; } if (t == null) { throw new IllegalArgumentException( "cannot find singleton " + rt.getName() + " in singleton group transformers"); } if (rt.getScope() == RepresentationTransformer.SCOPE.THIS && requestType == RequestContext.TYPE.COLLECTION) { // evaluate the script on collection t.tranform(exchange, context, context.getResponseContent(), rt.getArgs()); } else if (rt.getScope() == RepresentationTransformer.SCOPE.CHILDREN && requestType == RequestContext.TYPE.COLLECTION) { BasicDBObject _embedded = (BasicDBObject) context.getResponseContent().get("_embedded"); // execute the logic on children documents BasicDBList docs = (BasicDBList) _embedded.get("rh:doc"); if (docs != null) { for (String k : docs.keySet()) { DBObject doc = (DBObject) docs.get(k); t.tranform(exchange, context, doc, rt.getArgs()); } } // execute the logic on children files BasicDBList files = (BasicDBList) _embedded.get("rh:file"); if (files != null) { for (String k : files.keySet()) { DBObject file = (DBObject) files.get(k); t.tranform(exchange, context, file, rt.getArgs()); } } } else if (rt.getScope() == RepresentationTransformer.SCOPE.CHILDREN && requestType == RequestContext.TYPE.DOCUMENT) { t.tranform(exchange, context, context.getResponseContent(), rt.getArgs()); } } } }
From source file:org.restheart.handlers.schema.JsonSchemaTransformer.java
License:Open Source License
@Override public void tranform(HttpServerExchange exchange, RequestContext context, final DBObject contentToTransform, DBObject args) {//from ww w. ja v a 2 s. c om if (context.getType() == RequestContext.TYPE.SCHEMA) { if (context.getMethod() == RequestContext.METHOD.GET) { unescapeSchema(context.getResponseContent()); } else if (context.getMethod() == RequestContext.METHOD.PUT || context.getMethod() == RequestContext.METHOD.PATCH) { // generate id as specs mandates SchemaStoreURL uri = new SchemaStoreURL(context.getDBName(), context.getDocumentId()); context.getContent().put("id", uri.toString()); // escape all $ prefixed keys escapeSchema(contentToTransform); // add (overwrite) $schema field contentToTransform.put("_$schema", "http://json-schema.org/draft-04/schema#"); } } else if (context.getType() == RequestContext.TYPE.SCHEMA_STORE) { if (context.getMethod() == RequestContext.METHOD.POST) { // generate id as specs mandates Object schemaId; if (context.getContent().get("_id") == null) { schemaId = new ObjectId(); context.getContent().put("id", schemaId); } else { schemaId = context.getContent().get("_id"); } SchemaStoreURL uri = new SchemaStoreURL(context.getDBName(), schemaId); context.getContent().put("id", uri.toString()); // escape all $ prefixed keys escapeSchema(contentToTransform); // add (overwrite) $schema field contentToTransform.put("_$schema", "http://json-schema.org/draft-04/schema#"); } else if (context.getMethod() == RequestContext.METHOD.GET) { // apply transformation on embedded schemas BasicDBObject _embedded = (BasicDBObject) context.getResponseContent().get("_embedded"); if (_embedded != null) { // execute the logic on children documents BasicDBList docs = (BasicDBList) _embedded.get("rh:schema"); if (docs != null) { docs.keySet().stream().map((k) -> (DBObject) docs.get(k)).forEach((doc) -> { unescapeSchema(doc); }); } } } } }
From source file:org.sdsai.dsds.mongo.MongoUtils.java
License:Open Source License
public static Object getPrimitive(final BasicDBObject dbo, final String fieldName, final Class<?> returnType) throws Exception { final boolean contained = dbo.containsField(fieldName); if (Boolean.TYPE.equals(returnType)) return contained ? dbo.getBoolean(fieldName) : Boolean.FALSE; if (Short.TYPE.equals(returnType) || Byte.TYPE.equals(returnType) || Integer.TYPE.equals(returnType)) return (Integer) (contained ? dbo.getInt(fieldName) : 0); if (Character.TYPE.equals(returnType)) return (Character) ((dbo.get(fieldName) + "").charAt(0)); if (Long.TYPE.equals(returnType)) return (Long) (contained ? dbo.getLong(fieldName) : 0L); if (Float.TYPE.equals(returnType)) return (Float) (contained ? Float.valueOf(dbo.get(fieldName) + "") : 0F); if (Double.TYPE.equals(returnType)) return (Double) (contained ? dbo.getDouble(fieldName) : 0D); return null;// w w w . j av a 2s . c om }
From source file:org.sdsai.dsds.mongo.MongoUtils.java
License:Open Source License
public static <T> T fromDBObjectHelper(DBObject dbo, final String fieldName, final Class<T> returnType) throws Exception { logger.debug("Converting {}:{}", fieldName, returnType.getName()); //logger.debug("-->{}", dbo); if (returnType.isPrimitive()) { @SuppressWarnings("unchecked") final T t = (T) getPrimitive((BasicDBObject) dbo, fieldName, returnType); return t; }/*www .j av a 2 s . c om*/ if (isValueOfAble(returnType)) { @SuppressWarnings("unchecked") final T t = (T) returnType.getMethod("valueOf", String.class).invoke(null, dbo.get(fieldName).toString()); return t; } if (returnType.isArray()) { final BasicDBList dblist = (BasicDBList) dbo.get("list"); // FIXME return null; } if (Collection.class.isAssignableFrom(returnType)) { dbo = (DBObject) dbo.get(fieldName); final BasicDBList dblist = (BasicDBList) dbo.get("list"); @SuppressWarnings("unchecked") final Collection<Object> c = (Collection<Object>) objectFactory .newInstance(dbo.get("Class").toString()); for (int i = 0; i < dblist.size(); i++) { Object tmpo = dblist.get(i); if (tmpo instanceof DBObject) tmpo = fromDBObjectHelper((DBObject) tmpo); ; c.add(tmpo); } @SuppressWarnings("unchecked") final T t = (T) c; return t; } if (Map.class.isAssignableFrom(returnType)) { dbo = (DBObject) dbo.get(fieldName); final BasicDBObject dbmap = (BasicDBObject) dbo.get("map"); @SuppressWarnings("unchecked") final Map<String, Object> map = (Map<String, Object>) objectFactory .newInstance(dbo.get("Class").toString()); for (final String tmpFieldName : dbmap.keySet()) { Object tmpo = dbmap.get(tmpFieldName); if (tmpo instanceof DBObject) tmpo = fromDBObjectHelper((DBObject) tmpo); map.put(fieldName, tmpo); } @SuppressWarnings("unchecked") final T t = (T) map; return t; } // user object. @SuppressWarnings("unchecked") final T t = (T) fromDBObjectHelper((DBObject) dbo.get(fieldName)); return t; }
From source file:org.semispace.semimeter.dao.mongo.SemiMeterDaoMongo.java
License:Apache License
private boolean updateTrendCounters(final DBObject doc, final long before180min, final long before15min) { long oneHour = 60 * 60 * 1000; BasicDBObject day = (BasicDBObject) doc.get("day"); DBObject hours = (DBObject) day.get("hours"); int last15Counter = 0; int last180Counter = 0; for (String h : hours.keySet()) { long hourmillis = Long.valueOf(h); if (hourmillis >= (before180min - oneHour)) { DBObject currentHour = (DBObject) hours.get(h); DBObject minutes = (DBObject) currentHour.get("minutes"); for (String m : minutes.keySet()) { long minutemillis = Long.valueOf(m); DBObject obj = null;// w ww.j a va 2 s .com if (minutemillis >= before180min) { obj = (DBObject) minutes.get(m); last180Counter += (Integer) obj.get("count"); } if (minutemillis >= before15min) { last15Counter += (Integer) obj.get("count"); } } } } int oldVal = day.get("last15minutes") == null ? 0 : (Integer) day.get("last15minutes"); boolean objChanged = false; if (oldVal != last15Counter) { objChanged = true; day.put("last15minutes", last15Counter); } oldVal = day.get("last180minutes") == null ? 0 : (Integer) day.get("last180minutes"); if (oldVal != last180Counter) { objChanged = true; day.put("last180minutes", last180Counter); } return objChanged; }
From source file:org.sipfoundry.commons.userdb.ValidUsers.java
License:Open Source License
private static User extractUser(DBObject obj) { if (obj == null) { return null; }//from w w w. j a v a2 s .c om User user = new User(); user.setSysId(getStringValue(obj, ID)); user.setIdentity(getStringValue(obj, IDENTITY)); user.setUserName(getStringValue(obj, UID)); user.setDisplayName(getStringValue(obj, DISPLAY_NAME)); user.setUri(getStringValue(obj, CONTACT)); user.setPasstoken(getStringValue(obj, HASHED_PASSTOKEN)); user.setPintoken(getStringValue(obj, PINTOKEN)); user.setVoicemailPintoken(getStringValue(obj, VOICEMAIL_PINTOKEN)); BasicDBList permissions = (BasicDBList) obj.get(PERMISSIONS); if (permissions != null) { user.setInDirectory(permissions.contains(IMDB_PERM_AA)); user.setHasVoicemail(permissions.contains(IMDB_PERM_VOICEMAIL)); user.setCanRecordPrompts(permissions.contains(IMDB_PERM_RECPROMPTS)); user.setCanTuiChangePin(permissions.contains(IMDB_PERM_TUICHANGEPIN)); } user.setUserBusyPrompt(Boolean.valueOf(getStringValue(obj, USERBUSYPROMPT))); user.setMoh(getStringValue(obj, MOH)); user.setVoicemailTui(getStringValue(obj, VOICEMAILTUI)); user.setEmailAddress(getStringValue(obj, EMAIL)); if (obj.keySet().contains(NOTIFICATION)) { user.setEmailFormat(getStringValue(obj, NOTIFICATION)); } user.setAttachAudioToEmail(Boolean.valueOf(getStringValue(obj, ATTACH_AUDIO))); user.setAltEmailAddress(getStringValue(obj, ALT_EMAIL)); if (obj.keySet().contains(ALT_NOTIFICATION)) { user.setAltEmailFormat(getStringValue(obj, ALT_NOTIFICATION)); } user.setAltAttachAudioToEmail(Boolean.valueOf(getStringValue(obj, ALT_ATTACH_AUDIO))); BasicDBList aliasesObj = (BasicDBList) obj.get(ALIASES); if (aliasesObj != null) { Vector<String> aliases = new Vector<String>(); for (int i = 0; i < aliasesObj.size(); i++) { DBObject aliasObj = (DBObject) aliasesObj.get(i); if (aliasObj.get(RELATION).toString().equals(ALIAS)) { aliases.add(aliasObj.get(ALIAS_ID).toString()); } } user.setAliases(aliases); } if (obj.keySet().contains(SYNC)) { ImapInfo imapInfo = new ImapInfo(); imapInfo.setSynchronize(Boolean.valueOf(getStringValue(obj, SYNC))); imapInfo.setHost(getStringValue(obj, HOST)); imapInfo.setPort(getStringValue(obj, PORT)); imapInfo.setUseTLS(Boolean.valueOf(getStringValue(obj, TLS))); imapInfo.setAccount(getStringValue(obj, ACCOUNT)); imapInfo.setPassword(getStringValue(obj, PASSWD)); user.setImapInfo(imapInfo); if (imapInfo.isSynchronize()) { user.setEmailFormat(EmailFormats.FORMAT_IMAP); user.setAttachAudioToEmail(true); } // // If account isn't set, use the e-mail username if (imapInfo.getAccount() == null || imapInfo.getAccount().length() == 0) { if (user.getEmailAddress() != null) { imapInfo.setAccount(user.getEmailAddress().split("@")[0]); } } } // contact info related data user.setCellNum(getStringValue(obj, CELL_PHONE_NUMBER)); user.setHomeNum(getStringValue(obj, HOME_PHONE_NUMBER)); user.setConfEntryIM(getStringValue(obj, CONF_ENTRY_IM)); user.setConfExitIM(getStringValue(obj, CONF_EXIT_IM)); user.setVMEntryIM(getStringValue(obj, LEAVE_MESSAGE_BEGIN_IM)); user.setVMExitIM(getStringValue(obj, LEAVE_MESSAGE_END_IM)); user.setCallIM(getStringValue(obj, CALL_IM)); user.setCallFromAnyIM(getStringValue(obj, CALL_FROM_ANY_IM)); user.setImEnabled(Boolean.valueOf(getStringValue(obj, IM_ENABLED))); user.setJid(getStringValue(obj, IM_ID)); user.setAltJid(getStringValue(obj, ALT_IM_ID)); user.setImDisplayName(getStringValue(obj, IM_DISPLAY_NAME)); user.setOnthePhoneMessage(getStringValue(obj, IM_ON_THE_PHONE_MESSAGE)); user.setAdvertiseOnCallStatus(Boolean.valueOf(getStringValue(obj, IM_ADVERTISE_ON_CALL_STATUS))); user.setShowOnCallDetails(Boolean.valueOf(getStringValue(obj, IM_SHOW_ON_CALL_DETAILS))); user.setCompanyName(getStringValue(obj, COMPANY_NAME)); user.setJobDepartment(getStringValue(obj, JOB_DEPT)); user.setJobTitle(getStringValue(obj, JOB_TITLE)); user.setFaxNumber(getStringValue(obj, FAX_NUMBER)); // office details user.setOfficeStreet(getStringValue(obj, OFFICE_STREET)); user.setOfficeCity(getStringValue(obj, OFFICE_CITY)); user.setOfficeState(getStringValue(obj, OFFICE_STATE)); user.setOfficeZip(getStringValue(obj, OFFICE_ZIP)); user.setOfficeCountry(getStringValue(obj, OFFICE_COUNTRY)); // home details user.setHomeCity(getStringValue(obj, HOME_CITY)); user.setHomeState(getStringValue(obj, HOME_STATE)); user.setHomeZip(getStringValue(obj, HOME_ZIP)); user.setHomeCountry(getStringValue(obj, HOME_COUNTRY)); user.setHomeStreet(getStringValue(obj, HOME_STREET)); user.setAvatar(getStringValue(obj, AVATAR)); // active greeting related data if (obj.keySet().contains(ACTIVEGREETING)) { user.setActiveGreeting(getStringValue(obj, ACTIVEGREETING)); } user.setPlayDefaultVmOption(Boolean.valueOf(getStringValue(obj, PLAY_DEFAULT_VM))); // personal attendant related data if (obj.keySet().contains(PERSONAL_ATT)) { BasicDBObject pao = (BasicDBObject) obj.get(PERSONAL_ATT); String operator = getStringValue(pao, OPERATOR); String language = getStringValue(pao, LANGUAGE); Map<String, String> menu = new HashMap<String, String>(); StringBuilder validDigits = new StringBuilder(10); BasicDBList buttonsList = (BasicDBList) pao.get(BUTTONS); if (buttonsList != null) { for (int i = 0; i < buttonsList.size(); i++) { DBObject button = (DBObject) buttonsList.get(i); if (button != null) { menu.put(getStringValue(button, DIALPAD), getStringValue(button, ITEM)); validDigits.append(getStringValue(button, DIALPAD)); } } } user.setPersonalAttendant(new PersonalAttendant(language, operator, menu, validDigits.toString())); } // distribution lists if (obj.keySet().contains(DISTRIB_LISTS)) { Distributions distribs = new Distributions(); BasicDBList distribList = (BasicDBList) obj.get(DISTRIB_LISTS); if (distribList != null) { for (int i = 0; i < distribList.size(); i++) { DBObject distrib = (DBObject) distribList.get(i); if (distrib != null) { distribs.addList(getStringValue(distrib, DIALPAD), StringUtils.split(getStringValue(distrib, ITEM), " ")); } } } user.setDistributions(distribs); } if (user.isInDirectory()) { buildDialPatterns(user); } return user; }
From source file:org.sipfoundry.sipxconfig.mongo.MongoServer.java
License:Open Source License
public MongoServer(BasicDBObject dbo) { m_id = dbo.getInt("_id"); m_name = dbo.getString("name"); m_type = SERVER;//w w w . j a v a 2s .c o m if (StringUtils.contains(m_name, String.valueOf(MongoSettings.ARBITER_PORT))) { m_type = ARBITER; } m_configured = true; m_state = dbo.getString("stateStr"); m_health = UP; if (dbo.containsField(HEALTH)) { if (dbo.getInt(HEALTH) == 0) { m_health = DOWN; } } if (dbo.containsField(ERR_MSG)) { m_errMsg = dbo.getString(ERR_MSG); } try { BSONTimestamp optime = (BSONTimestamp) dbo.get("optime"); if (optime.getTime() != 0) { m_optimeDate = new Date((long) optime.getTime() * 1000).toString(); } } catch (NumberFormatException ex) { m_optimeDate = NA; } }
From source file:org.sipfoundry.sipxconfig.openacd.OpenAcdProvisioningContextTestIntegration.java
License:Open Source License
public void testOpenAcdCommands() { MockOpenAcdProvisioningContext provContext = new MockOpenAcdProvisioningContext(); m_openAcdContextImpl.setProvisioningContext(provContext); // test openacd client creation OpenAcdClient client = new OpenAcdClient(); client.setIdentity("001"); client.setName("clientName"); m_openAcdContextImpl.saveClient(client); // test client update client.setName("newClientName"); m_openAcdContextImpl.saveClient(client); // test openacd skill creation OpenAcdSkillGroup skillGroup = new OpenAcdSkillGroup(); skillGroup.setName("Programming"); m_openAcdContextImpl.saveSkillGroup(skillGroup); OpenAcdSkill skill = new OpenAcdSkill(); skill.setName("Java"); skill.setAtom("_java"); skill.setGroup(skillGroup);/*from w w w . j a v a2 s . co m*/ skill.setDescription("Java Skill"); m_openAcdContextImpl.saveSkill(skill); // test skill update skill.setName("Python"); m_openAcdContextImpl.saveSkill(skill); OpenAcdSkill skill1 = new OpenAcdSkill(); skill1.setName("C"); skill1.setAtom("_c"); skill1.setGroup(skillGroup); skill1.setDescription("C Skill"); m_openAcdContextImpl.saveSkill(skill1); // test agent group creation OpenAcdAgentGroup group = new OpenAcdAgentGroup(); group.setName("Group"); group.setClients(Collections.singleton(client)); group.addSkill(skill); group.addSkill(skill1); group.addQueue(m_openAcdContextImpl.getQueueByName("default_queue")); m_openAcdContextImpl.saveAgentGroup(group); // test queue creation OpenAcdQueue queue = new OpenAcdQueue(); queue.setName("QueueName"); queue.setAgentGroups(Collections.singleton(group)); queue.addSkill(skill); queue.addSkill(skill1); queue.setGroup(m_openAcdContextImpl.getQueueGroupByName("Default")); m_openAcdContextImpl.saveQueue(queue); // test create queue group OpenAcdQueueGroup qGroup = new OpenAcdQueueGroup(); qGroup.setName("QGroup"); qGroup.addSkill(skill); qGroup.addSkill(skill1); qGroup.addAgentGroup(group); m_openAcdContextImpl.saveQueueGroup(qGroup); List<BasicDBObject> commands = provContext.getCommands(); BasicDBObject addClientCommand = commands.get(0); assertEquals("ADD", addClientCommand.get("command")); assertEquals(1, addClientCommand.get("count")); List<BasicDBObject> objects = (List<BasicDBObject>) addClientCommand.get("objects"); assertEquals(1, objects.size()); assertEquals("client", objects.get(0).get("type")); assertEquals("clientName", objects.get(0).get("name")); assertEquals("001", objects.get(0).get("identity")); BasicDBObject updateClientCommand = commands.get(1); assertEquals("UPDATE", updateClientCommand.get("command")); assertEquals(1, updateClientCommand.get("count")); objects = (List<BasicDBObject>) updateClientCommand.get("objects"); assertEquals("newClientName", objects.get(0).get("name")); BasicDBObject addSkillCommand = commands.get(2); assertEquals("ADD", addSkillCommand.get("command")); assertEquals(1, addSkillCommand.get("count")); objects = (List<BasicDBObject>) addSkillCommand.get("objects"); assertEquals(1, objects.size()); assertEquals("skill", objects.get(0).get("type")); assertEquals("Java", objects.get(0).get("name")); assertEquals("_java", objects.get(0).get("atom")); assertEquals("Programming", objects.get(0).get("groupName")); BasicDBObject updateSkillCommand = commands.get(3); assertEquals("UPDATE", updateSkillCommand.get("command")); assertEquals(1, updateSkillCommand.get("count")); objects = (List<BasicDBObject>) updateSkillCommand.get("objects"); assertEquals(1, objects.size()); assertEquals("skill", objects.get(0).get("type")); assertEquals("Python", objects.get(0).get("name")); BasicDBObject addAnotherSkillCommand = commands.get(4); assertEquals("ADD", addSkillCommand.get("command")); assertEquals(1, addAnotherSkillCommand.get("count")); objects = (List<BasicDBObject>) addAnotherSkillCommand.get("objects"); assertEquals(1, objects.size()); assertEquals("skill", objects.get(0).get("type")); BasicDBObject addAgentGroupCommand = commands.get(5); assertEquals("ADD", addAgentGroupCommand.get("command")); assertEquals(1, addAgentGroupCommand.get("count")); objects = (List<BasicDBObject>) addAgentGroupCommand.get("objects"); assertEquals(1, objects.size()); assertEquals("profile", objects.get(0).get("type")); assertEquals("Group", objects.get(0).get("name")); assertEquals("_java, _c", objects.get(0).get("skillsAtoms")); assertEquals("default_queue", objects.get(0).get("queuesName")); assertEquals("newClientName", objects.get(0).get("clientsName")); BasicDBObject addQueueCommand = commands.get(6); assertEquals("ADD", addQueueCommand.get("command")); assertEquals(1, addQueueCommand.get("count")); objects = (List<BasicDBObject>) addQueueCommand.get("objects"); assertEquals(1, objects.size()); assertEquals("queue", objects.get(0).get("type")); assertEquals("QueueName", objects.get(0).get("name")); assertEquals("Default", objects.get(0).get("queueGroup")); assertEquals("_java, _c", objects.get(0).get("skillsAtoms")); assertEquals("Group", objects.get(0).get("profiles")); assertEquals("1", objects.get(0).get("weight")); BasicDBObject addQueueGroupCommand = commands.get(7); assertEquals("ADD", addQueueGroupCommand.get("command")); assertEquals(1, addQueueGroupCommand.get("count")); objects = (List<BasicDBObject>) addQueueGroupCommand.get("objects"); assertEquals(1, objects.size()); assertEquals("queueGroup", objects.get(0).get("type")); assertEquals("QGroup", objects.get(0).get("name")); assertEquals("_java, _c", objects.get(0).get("skillsAtoms")); assertEquals("Group", objects.get(0).get("profiles")); }
From source file:org.sipfoundry.sipxconfig.openacd.OpenAcdProvisioningContextTestIntegration.java
License:Open Source License
public void testOpenAcdConfigureCommands() { MockOpenAcdProvisioningContext provContext = new MockOpenAcdProvisioningContext(); FreeswitchMediaCommand command = new FreeswitchMediaCommand(true, "test@testme", "{ignore_early_media=true}sofia/mydomain.com/$1"); provContext.configure(Collections.singletonList(command)); OpenAcdAgentConfigCommand agentCommand = new OpenAcdAgentConfigCommand(true); provContext.configure(Collections.singletonList(agentCommand)); BasicDBObject addQueueGroupCommand = provContext.getCommands().get(0); assertEquals("CONFIGURE", addQueueGroupCommand.get("command")); assertEquals(1, addQueueGroupCommand.get("count")); List<BasicDBObject> objects = (List<BasicDBObject>) addQueueGroupCommand.get("objects"); assertEquals(1, objects.size());/*from ww w . ja v a 2s .c o m*/ assertEquals("freeswitch_media_manager", objects.get(0).get("type")); assertEquals("true", objects.get(0).get("enabled")); assertEquals("test@testme", objects.get(0).get("node")); assertEquals("{ignore_early_media=true}sofia/mydomain.com/$1", objects.get(0).get("dialString")); BasicDBObject enableListenerCommand = provContext.getCommands().get(1); assertEquals("CONFIGURE", enableListenerCommand.get("command")); assertEquals(1, enableListenerCommand.get("count")); objects = (List<BasicDBObject>) enableListenerCommand.get("objects"); assertEquals("agent_configuration", objects.get(0).get("type")); assertEquals("true", objects.get(0).get("listenerEnabled")); provContext = new MockOpenAcdProvisioningContext(); OpenAcdLogConfigCommand logConfigCommand = new OpenAcdLogConfigCommand("warning", "/var/etc"); provContext.configure(Collections.singletonList(logConfigCommand)); BasicDBObject configCommand = provContext.getCommands().get(0); assertEquals("CONFIGURE", configCommand.get("command")); assertEquals(1, configCommand.get("count")); objects = (List<BasicDBObject>) configCommand.get("objects"); assertEquals(1, objects.size()); assertEquals("log_configuration", objects.get(0).get("type")); assertEquals("warning", objects.get(0).get("logLevel")); assertEquals("/var/etc/openacd/", objects.get(0).get("logDir")); }