use of org.phoebus.olog.entity.Tag in project phoebus-olog by Olog.
the class TagRepository method deleteById.
@Override
public void deleteById(String tagName) {
try {
UpdateResponse response = client.update(new UpdateRequest(ES_TAG_INDEX, ES_TAG_TYPE, tagName).doc(jsonBuilder().startObject().field("state", State.Inactive).endObject()).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE), RequestOptions.DEFAULT);
if (response.getResult().equals(UPDATED)) {
BytesReference ref = client.get(new GetRequest(ES_TAG_INDEX, ES_TAG_TYPE, response.getId()), RequestOptions.DEFAULT).getSourceAsBytesRef();
Tag deletedTag = mapper.readValue(ref.streamInput(), Tag.class);
logger.log(Level.INFO, "Deleted tag " + deletedTag.toLogger());
}
} catch (DocumentMissingException e) {
logger.log(Level.SEVERE, "Failed to delete tag: " + tagName + " because it does not exist", e);
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to delete tag: " + tagName + " because it does not exist");
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed to delete tag: " + tagName, e);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to delete tag: " + tagName);
}
}
use of org.phoebus.olog.entity.Tag in project phoebus-olog by Olog.
the class TagRepository method save.
/**
*/
@Override
public <S extends Tag> S save(S tag) {
try {
IndexRequest indexRequest = new IndexRequest(ES_TAG_INDEX, ES_TAG_TYPE, tag.getName()).source(mapper.writeValueAsBytes(tag), XContentType.JSON).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT);
if (response.getResult().equals(CREATED) || response.getResult().equals(UPDATED)) {
BytesReference ref = client.get(new GetRequest(ES_TAG_INDEX, ES_TAG_TYPE, response.getId()), RequestOptions.DEFAULT).getSourceAsBytesRef();
Tag createdTag = mapper.readValue(ref.streamInput(), Tag.class);
return (S) createdTag;
}
return null;
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed to create tag: " + tag, e);
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to create tag: " + tag);
}
}
use of org.phoebus.olog.entity.Tag in project phoebus-olog by Olog.
the class LogResourceTest method init.
@Before
public void init() {
logbook1 = new Logbook("name1", "user");
logbook2 = new Logbook("name2", "user");
tag1 = new Tag("tag1");
tag2 = new Tag("tag2");
log1 = LogBuilder.createLog().id(1L).owner("owner").title("title").withLogbooks(Set.of(logbook1, logbook2)).description("description1").withTags(Set.of(tag1, tag2)).createDate(now).level("Urgent").build();
log2 = LogBuilder.createLog().id(2L).owner("user").withLogbooks(Set.of(logbook1, logbook2)).description("description2").createDate(now).level("Urgent").build();
}
use of org.phoebus.olog.entity.Tag in project phoebus-olog by Olog.
the class TagRepositoryIT method createTag.
/**
* Test the creation of a test tag
*
* @throws IOException
*/
@Test
public void createTag() throws IOException {
tagRepository.save(testTag1);
Optional<Tag> result = tagRepository.findById(testTag1.getName());
assertThat("Failed to create Tag " + testTag1, result.isPresent() && result.get().equals(testTag1));
// Manual cleanup since Olog does not delete things
client.delete(new DeleteRequest(ES_TAG_INDEX, ES_TAG_TYPE, testTag1.getName()), RequestOptions.DEFAULT);
}
use of org.phoebus.olog.entity.Tag in project phoebus-olog by Olog.
the class OlogTagsIT method handleTagsCreateCheck.
/**
* Test {@link gov.bnl.log.OlogResourceDescriptors#TAG_RESOURCE_URI}.
*/
@Test
public void handleTagsCreateCheck() {
// what
// check(s) for create tags
// e.g.
// user without required role
// content
// json - incomplete
// name - null, empty
// state - null, (empty, incorrect value (ok: Active, Inactive))
// --------------------------------------------------------------------------------
// Retrieve a Tag
// x List Tags
// Create a Tag
// x Create Tags
// Remove Tag
Tag tag_check = new Tag();
ObjectMapper mapper = new ObjectMapper();
try {
String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
Tag[] tags = new Tag[] { tag_t1_state_a, tag_t2_state_a, tag_t3_state_a, tag_t4_state_a, tag_t5_state_a, tag_t6_state_i, tag_t7_state_i, tag_t8_state_i, tag_t9_state_i, tag_t10_state_i, tag_check };
response = ITUtil.runShellCommand(createCurlTagsForAdmin(mapper.writeValueAsString(tags)));
ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
tag_check.setName(null);
tags[10] = tag_check;
response = ITUtil.runShellCommand(createCurlTagsForAdmin(mapper.writeValueAsString(tags)));
ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
tag_check.setName("");
tags[10] = tag_check;
response = ITUtil.runShellCommand(createCurlTagsForAdmin(mapper.writeValueAsString(tags)));
ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
} catch (IOException e) {
fail();
} catch (InterruptedException e) {
fail();
} catch (Exception e) {
fail();
}
}
Aggregations