Search in sources :

Example 1 with SelectionsType

use of com.intel.mtwilson.tag.selection.xml.SelectionsType in project OpenAttestation by OpenAttestation.

the class TagSelectionJsonTest method createTagSelectionJson.

@Test
public void createTagSelectionJson() throws JsonProcessingException, IOException {
    SelectionsType selections = SelectionBuilder.factory().selection().textAttributeKV("Country", "US").build();
    // {"selections":[{"attributes":[{"text":{"value":"Country=US"},"oid":"2.5.4.789.1"}]}]}
    log.debug("selections: {}", mapper.writeValueAsString(selections));
}
Also used : SelectionsType(com.intel.mtwilson.tag.selection.xml.SelectionsType) Test(org.junit.Test)

Example 2 with SelectionsType

use of com.intel.mtwilson.tag.selection.xml.SelectionsType in project OpenAttestation by OpenAttestation.

the class SelectionUtil method copySelectionsValidOn.

/**
     * Returns a new SelectionsType instance with only the selections and
     * default selections that are
     * valid today. The options section is copied to the new selections instance
     * for convenience.
     * The copy is a "shallow" copy - the copy refers to the same selections,
     * default selections, and options in the input.
     * To make a "deep" copy you can first serialize the selections, then
     * de-serialize into a new deep copy, and then call this method with the 
     * deep copy as input.
     */
public static SelectionsType copySelectionsValidOn(SelectionsType selections, Date validOn) {
    GregorianCalendar today = new GregorianCalendar();
    // http://docs.oracle.com/javase/7/docs/api/java/util/GregorianCalendar.html
    today.setTime(validOn);
    SelectionsType copy = new SelectionsType();
    for (SelectionType selection : selections.getSelection()) {
        // skip if the selection is not currently valid (notBefore<today<notAfter) ; if notBefore or notAfter are not defined, then validity is assumed
        if (selection.getNotBefore() != null && today.before(selection.getNotBefore().toGregorianCalendar())) {
            log.debug("skipping selection because of notBefore date {}", selection.getNotBefore().toString());
            continue;
        }
        if (selection.getNotAfter() != null && today.after(selection.getNotAfter().toGregorianCalendar())) {
            log.debug("skipping selection because of notAfter date {}", selection.getNotAfter().toString());
            continue;
        }
        copy.getSelection().add(selection);
    }
    // repeat the same action for the default selections
    if (selections.getDefault() != null) {
        copy.setDefault(new DefaultType());
        for (SelectionType selection : selections.getDefault().getSelection()) {
            // skip if the selection is not currently valid (notBefore<today<notAfter) ; if notBefore or notAfter are not defined, then validity is assumed
            if (selection.getNotBefore() != null && today.before(selection.getNotBefore().toGregorianCalendar())) {
                log.debug("skipping default selection because of notBefore date {}", selection.getNotBefore().toString());
                continue;
            }
            if (selection.getNotAfter() != null && today.after(selection.getNotAfter().toGregorianCalendar())) {
                log.debug("skipping default selection because of notAfter date {}", selection.getNotAfter().toString());
                continue;
            }
            copy.getDefault().getSelection().add(selection);
        }
    }
    // copy the options
    copy.setOptions(selections.getOptions());
    return copy;
}
Also used : SelectionsType(com.intel.mtwilson.tag.selection.xml.SelectionsType) SelectionType(com.intel.mtwilson.tag.selection.xml.SelectionType) DefaultType(com.intel.mtwilson.tag.selection.xml.DefaultType) GregorianCalendar(java.util.GregorianCalendar)

Example 3 with SelectionsType

use of com.intel.mtwilson.tag.selection.xml.SelectionsType in project OpenAttestation by OpenAttestation.

the class TagSelectionJsonTest method createTagSelectionJsonById.

@Test
public void createTagSelectionJsonById() throws JsonProcessingException, IOException {
    SelectionsType selections = SelectionBuilder.factory().selection().name("California Finance").build();
    // {"selections":[{"attributes":[{"text":{"value":"Country=US"},"oid":"2.5.4.789.1"}]}]}
    log.debug("selections: {}", mapper.writeValueAsString(selections));
}
Also used : SelectionsType(com.intel.mtwilson.tag.selection.xml.SelectionsType) Test(org.junit.Test)

Example 4 with SelectionsType

use of com.intel.mtwilson.tag.selection.xml.SelectionsType in project OpenAttestation by OpenAttestation.

the class TagSelectionJsonTest method parseTagSelectionJson.

@Test
public void parseTagSelectionJson() throws IOException {
    String json = "{\"selections\":[{\"attributes\":[{\"text\":{\"value\":\"Country=US\"},\"oid\":\"2.5.4.789.1\"}]}]}";
    SelectionsType selections = mapper.readValue(json, SelectionsType.class);
    printSelections(selections);
}
Also used : SelectionsType(com.intel.mtwilson.tag.selection.xml.SelectionsType) Test(org.junit.Test)

Example 5 with SelectionsType

use of com.intel.mtwilson.tag.selection.xml.SelectionsType in project OpenAttestation by OpenAttestation.

the class TagSelectionJsonTest method createTagSelectionWithDefaultJson.

/**
     * Sample output:
     * <pre>
     * selections: {"options":{"cache":{"mode":"on"}},"default":{"selections":[{"attributes":[{"text":{"value":"Country=US"},"oid":"2.5.4.789.1"}]}]},"selections":[{"subjects":[{"uuid":null,"name":null,"ip":{"value":"192.168.1.100"}}],"attributes":[{"text":{"value":"Country=US"},"oid":"2.5.4.789.1"}]}]}
     * </pre>
     * @throws JsonProcessingException 
     */
@Test
public void createTagSelectionWithDefaultJson() throws JsonProcessingException, IOException {
    SelectionsType selections = SelectionBuilder.factory().options().cacheMode("on").defaultSelection().textAttributeKV("Country", "US").selection().subjectIp("192.168.1.100").textAttributeKV("Country", "US").build();
    // {"selections":[{"attributes":[{"text":{"value":"Country=US"},"oid":"2.5.4.789.1"}]}]}
    log.debug("selections: {}", mapper.writeValueAsString(selections));
}
Also used : SelectionsType(com.intel.mtwilson.tag.selection.xml.SelectionsType) Test(org.junit.Test)

Aggregations

SelectionsType (com.intel.mtwilson.tag.selection.xml.SelectionsType)6 Test (org.junit.Test)5 DefaultType (com.intel.mtwilson.tag.selection.xml.DefaultType)1 SelectionType (com.intel.mtwilson.tag.selection.xml.SelectionType)1 GregorianCalendar (java.util.GregorianCalendar)1