Пример #1
0
  /**
   * Update book-keeping fields on the alarm. Returns an up-to-date version of the alarm. Some of
   * its fields may have been updated since the REST client last retrieved the alarm being updated.
   *
   * @param alarmIdPath
   * @param stream input JSON
   * @return updated JSON encoded alarm
   */
  @PUT
  @Path("{alarm_id}")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response update(
      @PathParam("alarm_id") final String alarmIdPath, final InputStream stream) {
    log.info("PUT NEW ALARM at /{}", alarmIdPath);

    try {
      final ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
      log.info("jsonTree={}", jsonTree);

      final Alarm alarm = codec(Alarm.class).decode(jsonTree, this);

      final AlarmService service = get(AlarmService.class);

      if (Long.parseLong(alarmIdPath) != alarm.id().fingerprint()) {
        throw new IllegalArgumentException(
            "id in path is "
                + Long.parseLong(alarmIdPath)
                + " but payload uses id="
                + alarm.id().fingerprint());
      }
      final Alarm updated = service.update(alarm);
      final ObjectNode encoded = new AlarmCodec().encode(updated, this);
      return ok(encoded.toString()).build();

    } catch (IOException ioe) {
      throw new IllegalArgumentException(ioe);
    }
  }
Пример #2
0
  @Test
  public void verifyMinimalAlarmIsEncoded() throws Exception {
    final JsonCodec<Alarm> alarmCodec = context.codec(Alarm.class);

    final Alarm alarm = getDecodedAlarm(alarmCodec, "alarm-minimal.json");
    assertCommon(alarm);

    assertThat(alarm.timeCleared(), nullValue());
    assertThat(alarm.assignedUser(), nullValue());
  }
Пример #3
0
  @Test
  public void verifyFullyLoadedAlarmIsEncoded() throws Exception {
    final JsonCodec<Alarm> alarmCodec = context.codec(Alarm.class);

    final Alarm alarm = getDecodedAlarm(alarmCodec, "alarm-full.json");
    assertCommon(alarm);

    assertThat(alarm.timeCleared(), is(2222L));
    assertThat(alarm.assignedUser(), is("foo"));
  }
Пример #4
0
 private void assertCommon(Alarm alarm) {
   assertThat(alarm.id(), is(new AlarmId(10L)));
   assertThat(alarm.description(), is("NE is not reachable"));
   assertThat(alarm.source(), is(AlarmEntityId.NONE));
   assertThat(alarm.timeRaised(), is(999L));
   assertThat(alarm.timeUpdated(), is(1111L));
   assertThat(alarm.severity(), is(Alarm.SeverityLevel.MAJOR));
   assertThat(alarm.serviceAffecting(), is(true));
   assertThat(alarm.acknowledged(), is(false));
   assertThat(alarm.manuallyClearable(), is(true));
 }