/** * Store. */ public void store() { if (state != null) { state.put("agents", agents); } }
/** * Set the API Key for using the paid Google Translate service. * @param key */ public void setKey(@Name("key") String key) { getState().put("key", key); }
/** * Remove a calendar agent data from the state * @param agent * @param data */ private void removeAgentData(String agent) { State state = getState(); Map<String, AgentData> calendarAgents = getState().get("calendarAgents",new TypeUtil<HashMap<String, AgentData>>(){}); if (calendarAgents != null && calendarAgents.containsKey(agent)) { calendarAgents.remove(agent); state.put("calendarAgents", calendarAgents); } }
/** * Put value. * * @param state * the {@link State} to update with specified {@code value} * @param value * the new value for this {@link StateEntry} in specified * @return the previous value or {@code null} if none existed {@code state} * @see java.util.Map#put(Object, Object) */ public T putValue(final State state, final T value) { try { return TypeUtil.inject(state.put(getKey(), value), valueType); } catch (final ClassCastException e) { LOG.log(Level.WARNING, "Problem casting agent's previous state value, key: " + key, e); return null; } }
/** * Put data for a calendar agent into the state * * @param agentUrl * @param data */ private void putAgentData(String agentUrl, AgentData data) { State state = getState(); Map<String, AgentData> calendarAgents = getState().get("calendarAgents", new TypeUtil<HashMap<String, AgentData>>(){}); if (calendarAgents == null) { calendarAgents = new HashMap<String, AgentData>(); } calendarAgents.put(agentUrl, data); state.put("calendarAgents", calendarAgents); }
/** * Instantiates a new test scale agent. * * @param id * the id * @param config * the config * @param parent * the parent * @param nofChildren * the nof children */ public TestScaleAgent(final String id, final Config config, final URI parent, final List<Integer> nofChildren) { super(id, config); this.parent = parent; getState().put("key", "value"); if (nofChildren.size() > 0) { for (int i = 0; i < nofChildren.get(0); i++) { Agent newAgent = new TestScaleAgent(id + "_" + i, config, getUrls().get(0), nofChildren.subList(1, nofChildren.size())); children.add(newAgent.getUrls().get(0)); } } }
/** * Retrieve a list with all calendars in this google calendar * @return String with id of the task list */ private String getDefaultTaskList() throws Exception { String defaultList= getState().get("defaultList",String.class); if(defaultList==null) { ArrayNode taskLists = getTaskList(); for(JsonNode taskList : taskLists) { if(taskList.get("title").textValue().equals("Paige Task List")){ getState().put("defaultList", taskList.get("id").textValue()); return taskList.get("id").textValue(); } } } // No default list found so going to create one if(defaultList==null) { ObjectNode taskList = JOM.createObjectNode(); taskList.put("title", "Paige Task List"); taskList = createTaskList(taskList); defaultList = taskList.get("id").textValue(); getState().put("defaultList", defaultList); } return defaultList; }
/** * Set access token and refresh token, used to authorize the calendar agent. * These tokens must be retrieved via Oauth 2.0 authorization. * * @param access_token * @param token_type * @param expires_in * @param refresh_token * @throws IOException */ public void setAuthorization(@Name("access_token") String access_token, @Name("token_type") String token_type, @Name("expires_in") Integer expires_in, @Name("refresh_token") String refresh_token) throws IOException { State state = getState(); // retrieve user information String url = "https://www.googleapis.com/oauth2/v1/userinfo"; Map<String, String> headers = new HashMap<String, String>(); headers.put("Authorization", token_type + " " + access_token); String resp = HttpUtil.get(url, headers); ObjectNode info = JOM.getInstance().readValue(resp, ObjectNode.class); String email = info.has("email") ? info.get("email").asText() : null; String name = info.has("name") ? info.get("name").asText() : null; DateTime expires_at = calculateExpiresAt(expires_in); Authorization auth = new Authorization(access_token, token_type, expires_at, refresh_token); // store the tokens in the state state.put("auth", auth); state.put("email", email); state.put("name", name); }
/** * Add an issue to the issue list * The issue will trigger an event * @param issue */ private void addIssue(Issue issue) { ArrayList<Issue> issues = getIssues(); issues.add(issue); getState().put("issues", issues); // trigger an error event try { String event = issue.getType().toString(); ObjectNode data = JOM.createObjectNode(); data.put("issue", JOM.getInstance().convertValue(issue, ObjectNode.class)); ObjectNode params = JOM.createObjectNode(); params.put("description", issue.getMessage()); params.put("data", data); getEventsFactory().trigger(event, params); } catch (Exception e) { e.printStackTrace(); } }
/** * Store. * * @param key * the key * @param val * the val */ private void store(final String key, final InstantiationEntry val) { State innerState = null; if (val != null) { innerState = val.getState(); } if (innerState == null) { innerState = new StateBuilder().withConfig( new StateConfig((ObjectNode) myParams.get("state")).put( "id", key)).build(); } if (innerState != null) { innerState.put("entry", JOM.getInstance().valueToTree(val)); } }
/** * Retrieve authorization tokens * @return * @throws Exception */ private Authorization getAuthorization() throws Exception { Authorization auth = getState().get("auth",Authorization.class); // check if access_token is expired DateTime expires_at = (auth != null) ? auth.getExpiresAt() : null; if (expires_at != null && expires_at.isBeforeNow()) { // TODO: remove this logging logger.info("access token is expired. refreshing now..."); refreshAuthorization(auth); getState().put("auth", auth); } return auth; }
/** * Retrieve authorization tokens * * @return * @throws Exception */ private Authorization getAuthorization() throws Exception { Authorization auth = getState().get("auth", Authorization.class); // check if access_token is expired DateTime expires_at = (auth != null) ? auth.getExpiresAt() : null; if (expires_at != null && expires_at.isBeforeNow()) { refreshAuthorization(auth); getState().put("auth", auth); } return auth; }
state.put("updateTask", task);
Attendee attendee = activity.withConstraints().withAttendee(agent); attendee.setResponseStatus(RESPONSE_STATUS.declined); getState().put("activity", activity);
status.setActivityStatus(Status.ACTIVITY_STATUS.planned); status.setUpdated(DateTime.now().toString()); state.put("activity", activity); logger.info("Activity replanned at " + solution.toString()); // TODO: cleanup logging try { status.setActivityStatus(Status.ACTIVITY_STATUS.error); status.setUpdated(DateTime.now().toString()); state.put("activity", activity);
getState().put("activity", activity);
getState().put("activity", activity);