com.structurizr.Workspace Java Examples

The following examples show how to use com.structurizr.Workspace. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EncryptedJsonTests.java    From java with Apache License 2.0 6 votes vote down vote up
@Test
public void test_write_and_read() throws Exception {
    final Workspace workspace1 = new Workspace("Name", "Description");

    // output the model as JSON
    EncryptedJsonWriter jsonWriter = new EncryptedJsonWriter(true);
    AesEncryptionStrategy encryptionStrategy = new AesEncryptionStrategy("password");
    final EncryptedWorkspace encryptedWorkspace1 = new EncryptedWorkspace(workspace1, encryptionStrategy);
    StringWriter stringWriter = new StringWriter();
    jsonWriter.write(encryptedWorkspace1, stringWriter);

    // and read it back again
    EncryptedJsonReader jsonReader = new EncryptedJsonReader();
    StringReader stringReader = new StringReader(stringWriter.toString());
    final EncryptedWorkspace encryptedWorkspace2 = jsonReader.read(stringReader);
    assertEquals("Name", encryptedWorkspace2.getName());
    assertEquals("Description", encryptedWorkspace2.getDescription());

    encryptedWorkspace2.getEncryptionStrategy().setPassphrase(encryptionStrategy.getPassphrase());
    final Workspace workspace2 = encryptedWorkspace2.getWorkspace();
    assertEquals("Name", workspace2.getName());
    assertEquals("Description", workspace2.getDescription());
}
 
Example #2
Source File: Theme.java    From java with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Workspace workspace = new Workspace("Theme", "This is a model of my software system.");
    Model model = workspace.getModel();

    Person user = model.addPerson("User", "A user of my software system.");
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "My software system.");
    user.uses(softwareSystem, "Uses");

    ViewSet views = workspace.getViews();
    SystemContextView contextView = views.createSystemContextView(softwareSystem, "SystemContext", "An example of a System Context diagram.");
    contextView.addAllSoftwareSystems();
    contextView.addAllPeople();

    // add a theme
    views.getConfiguration().setTheme("https://raw.githubusercontent.com/structurizr/java/master/structurizr-examples/src/com/structurizr/example/theme/theme.json");

    StructurizrClient structurizrClient = new StructurizrClient(API_KEY, API_SECRET);
    structurizrClient.putWorkspace(WORKSPACE_ID, workspace);
}
 
Example #3
Source File: StructurizrClientIntegrationTests.java    From java with Apache License 2.0 6 votes vote down vote up
@Test
public void test_putAndGetWorkspace_WithEncryption() throws Exception {
    structurizrClient.setEncryptionStrategy(new AesEncryptionStrategy("password"));
    Workspace workspace = new Workspace("Structurizr client library tests - with encryption", "A test workspace for the Structurizr client library");
    SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Software System", "Description");
    Person person = workspace.getModel().addPerson("Person", "Description");
    person.uses(softwareSystem, "Uses");
    SystemContextView systemContextView = workspace.getViews().createSystemContextView(softwareSystem, "SystemContext", "Description");
    systemContextView.addAllElements();

    structurizrClient.putWorkspace(20081, workspace);

    workspace = structurizrClient.getWorkspace(20081);
    assertNotNull(workspace.getModel().getSoftwareSystemWithName("Software System"));
    assertNotNull(workspace.getModel().getPersonWithName("Person"));
    assertEquals(1, workspace.getModel().getRelationships().size());
    assertEquals(1, workspace.getViews().getSystemContextViews().size());

    // and check the archive version is readable
    EncryptedWorkspace archivedWorkspace = new EncryptedJsonReader().read(new FileReader(getArchivedWorkspace()));
    assertEquals(20081, archivedWorkspace.getId());
    assertEquals("Structurizr client library tests - with encryption", archivedWorkspace.getName());
    assertTrue(archivedWorkspace.getEncryptionStrategy() instanceof AesEncryptionStrategy);

    assertEquals(1, workspaceArchiveLocation.listFiles().length);
}
 
Example #4
Source File: AutomaticDocumentationTemplateExample.java    From java with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Workspace workspace = new Workspace("Documentation - Automatic", "An empty software architecture document using the Structurizr template.");
    Model model = workspace.getModel();
    ViewSet views = workspace.getViews();

    Person user = model.addPerson("User", "A user of my software system.");
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "My software system.");
    user.uses(softwareSystem, "Uses");

    SystemContextView contextView = views.createSystemContextView(softwareSystem, "SystemContext", "An example of a System Context diagram.");
    contextView.addAllSoftwareSystems();
    contextView.addAllPeople();

    Styles styles = views.getConfiguration().getStyles();
    styles.addElementStyle(Tags.PERSON).shape(Shape.Person);

    // this directory includes a mix of Markdown and AsciiDoc files
    File documentationRoot = new File("./structurizr-examples/src/com/structurizr/example/documentation/automatic");

    AutomaticDocumentationTemplate template = new AutomaticDocumentationTemplate(workspace);
    template.addSections(softwareSystem, documentationRoot);

    StructurizrClient structurizrClient = new StructurizrClient(API_KEY, API_SECRET);
    structurizrClient.putWorkspace(WORKSPACE_ID, workspace);
}
 
Example #5
Source File: StructurizrClientIntegrationTests.java    From java with Apache License 2.0 6 votes vote down vote up
@Test
public void test_putAndGetWorkspace_WithoutEncryption() throws Exception {
    Workspace workspace = new Workspace("Structurizr client library tests - without encryption", "A test workspace for the Structurizr client library");
    SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Software System", "Description");
    Person person = workspace.getModel().addPerson("Person", "Description");
    person.uses(softwareSystem, "Uses");
    SystemContextView systemContextView = workspace.getViews().createSystemContextView(softwareSystem, "SystemContext", "Description");
    systemContextView.addAllElements();

    structurizrClient.putWorkspace(20081, workspace);

    workspace = structurizrClient.getWorkspace(20081);
    assertNotNull(workspace.getModel().getSoftwareSystemWithName("Software System"));
    assertNotNull(workspace.getModel().getPersonWithName("Person"));
    assertEquals(1, workspace.getModel().getRelationships().size());
    assertEquals(1, workspace.getViews().getSystemContextViews().size());

    // and check the archive version is readable
    Workspace archivedWorkspace = new JsonReader().read(new FileReader(getArchivedWorkspace()));
    assertEquals(20081, archivedWorkspace.getId());
    assertEquals("Structurizr client library tests - without encryption", archivedWorkspace.getName());
    assertEquals(1, archivedWorkspace.getModel().getSoftwareSystems().size());

    assertEquals(1, workspaceArchiveLocation.listFiles().length);
}
 
Example #6
Source File: ViewSetTests.java    From java with Apache License 2.0 6 votes vote down vote up
@Test
public void test_copyLayoutInformationFrom_WhenTheSystemLandscapeViewKeysMatch() {
    Workspace workspace1 = createWorkspace();
    SoftwareSystem softwareSystem1 = workspace1.getModel().getSoftwareSystemWithName("Software System");
    SystemLandscapeView view1 = workspace1.getViews().createSystemLandscapeView("landscape", "Description");
    view1.addAllElements();
    view1.getElements().iterator().next().setX(100);
    view1.setPaperSize(PaperSize.A3_Landscape);

    Workspace workspace2 = createWorkspace();
    SoftwareSystem softwareSystem2 = workspace2.getModel().getSoftwareSystemWithName("Software System");
    SystemLandscapeView view2 = workspace2.getViews().createSystemLandscapeView("context", "Description");
    view2.addAllElements();

    workspace2.getViews().copyLayoutInformationFrom(workspace1.getViews());
    assertEquals(100, view2.getElements().iterator().next().getX());
    assertEquals(PaperSize.A3_Landscape, view2.getPaperSize());
}
 
Example #7
Source File: ViewSetTests.java    From java with Apache License 2.0 6 votes vote down vote up
@Test
public void test_copyLayoutInformationFrom_WhenTheDynamicViewKeysMatch() {
    Workspace workspace1 = createWorkspace();
    Person person1 = workspace1.getModel().getPersonWithName("Person");
    SoftwareSystem softwareSystem1 = workspace1.getModel().getSoftwareSystemWithName("Software System");
    DynamicView view1 = workspace1.getViews().createDynamicView("context", "Description");
    view1.add(person1, softwareSystem1);
    view1.getElements().iterator().next().setX(100);
    view1.setPaperSize(PaperSize.A3_Landscape);

    Workspace workspace2 = createWorkspace();
    Person person2 = workspace2.getModel().getPersonWithName("Person");
    SoftwareSystem softwareSystem2 = workspace2.getModel().getSoftwareSystemWithName("Software System");
    DynamicView view2 = workspace2.getViews().createDynamicView("context", "Description");
    view2.add(person2, softwareSystem2);

    workspace2.getViews().copyLayoutInformationFrom(workspace1.getViews());
    assertEquals(100, view2.getElements().iterator().next().getX());
    assertEquals(PaperSize.A3_Landscape, view2.getPaperSize());
}
 
Example #8
Source File: StructurizrSimple.java    From tutorials with MIT License 6 votes vote down vote up
private static void addComponents(Workspace workspace) {
    Model model = workspace.getModel();

    SoftwareSystem paymentTerminal = model.getSoftwareSystemWithName(PAYMENT_TERMINAL);
    Container jvm1 = paymentTerminal.getContainerWithName("JVM-1");

    Component jaxrs = jvm1.addComponent("jaxrs-jersey", "restful webservice implementation", "rest");
    Component gemfire = jvm1.addComponent("gemfire", "Clustered Cache Gemfire", "cache");
    Component hibernate = jvm1.addComponent("hibernate", "Data Access Layer", "jpa");

    jaxrs.uses(gemfire, "");
    gemfire.uses(hibernate, "");

    ComponentView componentView = workspace.getViews().createComponentView(jvm1, COMPONENT_VIEW, "JVM Components");
    componentView.addAllComponents();
}
 
Example #9
Source File: JsonTests.java    From java with Apache License 2.0 6 votes vote down vote up
@Test
public void test_backwardsCompatibilityOfRenamingEnterpriseContextViewsToSystemLandscapeViews() throws Exception {
    Workspace workspace = new Workspace("Name", "Description");
    workspace.getViews().createSystemLandscapeView("key", "description");

    JsonWriter jsonWriter = new JsonWriter(false);
    StringWriter stringWriter = new StringWriter();
    jsonWriter.write(workspace, stringWriter);
    String workspaceAsJson = stringWriter.toString();
    workspaceAsJson = workspaceAsJson.replaceAll("systemLandscapeViews", "enterpriseContextViews");

    JsonReader jsonReader = new JsonReader();
    StringReader stringReader = new StringReader(workspaceAsJson);
    workspace = jsonReader.read(stringReader);
    assertEquals(1, workspace.getViews().getSystemLandscapeViews().size());
}
 
Example #10
Source File: DynamicViewTests.java    From java with Apache License 2.0 6 votes vote down vote up
@Test
public void test_normalSequence() {
    workspace = new Workspace("Name", "Description");
    model = workspace.getModel();

    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
    Container container1 = softwareSystem.addContainer("Container 1", "Description", "Technology");
    Container container2 = softwareSystem.addContainer("Container 2", "Description", "Technology");
    Container container3 = softwareSystem.addContainer("Container 3", "Description", "Technology");

    container1.uses(container2, "Uses");
    container1.uses(container3, "Uses");

    DynamicView view = workspace.getViews().createDynamicView(softwareSystem, "key", "Description");

    view.add(container1, container2);
    view.add(container1, container3);

    assertSame(container2, view.getRelationships().stream().filter(r -> r.getOrder().equals("1")).findFirst().get().getRelationship().getDestination());
    assertSame(container3, view.getRelationships().stream().filter(r -> r.getOrder().equals("2")).findFirst().get().getRelationship().getDestination());
}
 
Example #11
Source File: ViewSetTests.java    From java with Apache License 2.0 6 votes vote down vote up
@Test
public void test_copyLayoutInformationFrom_WhenTheContainerViewKeysMatch() {
    Workspace workspace1 = createWorkspace();
    SoftwareSystem softwareSystem1 = workspace1.getModel().getSoftwareSystemWithName("Software System");
    ContainerView view1 = workspace1.getViews().createContainerView(softwareSystem1, "containers", "Description");
    view1.addAllElements();
    view1.getElements().iterator().next().setX(100);
    view1.setPaperSize(PaperSize.A3_Landscape);

    Workspace workspace2 = createWorkspace();
    SoftwareSystem softwareSystem2 = workspace2.getModel().getSoftwareSystemWithName("Software System");
    ContainerView view2 = workspace2.getViews().createContainerView(softwareSystem2, "containers", "Description");
    view2.addAllElements();

    workspace2.getViews().copyLayoutInformationFrom(workspace1.getViews());
    assertEquals(100, view2.getElements().iterator().next().getX());
    assertEquals(PaperSize.A3_Landscape, view2.getPaperSize());
}
 
Example #12
Source File: MessageDigestIdGeneratorTests.java    From java with Apache License 2.0 6 votes vote down vote up
private void createWorkspaceWithExpectedIds(MessageDigestIdGenerator ids, String webappId, String databaseId, String relationshipId) {
    final Workspace ws = createWorkspace(ids);

    final Element webapp = ws.getModel().getElement(webappId);
    final Element database = ws.getModel().getElement(databaseId);
    final Relationship relationship = ws.getModel().getRelationship(relationshipId);

    assertNotNull(webapp);
    assertNotNull(database);
    assertNotNull(relationship);
    assertEquals("Web Application", webapp.getName());
    assertEquals("Database", database.getName());
    assertEquals("Reads from and writes to", relationship.getDescription());
    assertSame(webapp, relationship.getSource());
    assertSame(database, relationship.getDestination());
}
 
Example #13
Source File: ViewSetTests.java    From java with Apache License 2.0 6 votes vote down vote up
@Test
public void test_copyLayoutInformationFrom_WhenTheSystemContextViewKeysMatch() {
    Workspace workspace1 = createWorkspace();
    SoftwareSystem softwareSystem1 = workspace1.getModel().getSoftwareSystemWithName("Software System");
    SystemContextView view1 = workspace1.getViews().createSystemContextView(softwareSystem1, "context", "Description");
    view1.addAllElements();
    view1.getElements().iterator().next().setX(100);
    view1.setPaperSize(PaperSize.A3_Landscape);

    Workspace workspace2 = createWorkspace();
    SoftwareSystem softwareSystem2 = workspace2.getModel().getSoftwareSystemWithName("Software System");
    SystemContextView view2 = workspace2.getViews().createSystemContextView(softwareSystem2, "context", "Description");
    view2.addAllElements();

    workspace2.getViews().copyLayoutInformationFrom(workspace1.getViews());
    assertEquals(100, view2.getElements().iterator().next().getX());
    assertEquals(PaperSize.A3_Landscape, view2.getPaperSize());
}
 
Example #14
Source File: DocumentationTemplate.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new documentation template for the given workspace.
 *
 * @param workspace     the Workspace instance to create documentation for
 */
public DocumentationTemplate(@Nonnull Workspace workspace) {
    if (workspace == null) {
        throw new IllegalArgumentException("A workspace must be specified.");
    }

    this.documentation = workspace.getDocumentation();
    documentation.setTemplate(getMetadata());
}
 
Example #15
Source File: ViewSetTests.java    From java with Apache License 2.0 5 votes vote down vote up
@Test
public void test_createDeploymentViewForASoftwareSystem_ThrowsAnException_WhenANullSoftwareSystemIsSpecified() {
    try {
        new Workspace("", "").getViews().createDeploymentView((SoftwareSystem)null, "key", "Description");
        fail();
    } catch (IllegalArgumentException iae) {
        assertEquals("A software system must be specified.", iae.getMessage());
    }
}
 
Example #16
Source File: ViewSetTests.java    From java with Apache License 2.0 5 votes vote down vote up
@Test
public void test_copyLayoutInformationFrom_DoesNotDoAnythingIfThereIsNoDynamicViewToCopyInformationFrom() {
    Workspace workspace1 = createWorkspace();

    Workspace workspace2 = createWorkspace();
    Person person2 = workspace2.getModel().getPersonWithName("Person");
    SoftwareSystem softwareSystem2 = workspace2.getModel().getSoftwareSystemWithName("Software System");
    DynamicView view2 = workspace2.getViews().createDynamicView("context", "Description");
    view2.add(person2, softwareSystem2);

    workspace2.getViews().copyLayoutInformationFrom(workspace1.getViews());
    assertEquals(0, view2.getElements().iterator().next().getX()); // default
    assertNull(view2.getPaperSize()); // default
}
 
Example #17
Source File: ViewSetTests.java    From java with Apache License 2.0 5 votes vote down vote up
@Test
public void test_createDynamicViewForAContainer_ThrowsAnException_WhenAnEmptyKeyIsSpecified() {
    try {
        Workspace workspace = new Workspace("Name", "Description");
        SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Software System", "Description");
        Container container = softwareSystem.addContainer("Container", "Description", "Technology");
        workspace.getViews().createDynamicView(container, " ", "Description");
        fail();
    } catch (IllegalArgumentException iae) {
        assertEquals("A key must be specified.", iae.getMessage());
    }
}
 
Example #18
Source File: ViewTests.java    From java with Apache License 2.0 5 votes vote down vote up
@Test
public void test_enableAutomaticLayout_DisablesAutoLayout_WhenFalseIsSpecified() {
    SystemLandscapeView view = new Workspace("", "").getViews().createSystemLandscapeView("key", "Description");
    view.enableAutomaticLayout();
    assertNotNull(view.getAutomaticLayout());

    view.disableAutomaticLayout();
    assertNull(view.getAutomaticLayout());
}
 
Example #19
Source File: ViewSetTests.java    From java with Apache License 2.0 5 votes vote down vote up
private Workspace createWorkspace() {
    Workspace workspace = new Workspace("Name", "Description");
    Model model = workspace.getModel();

    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
    Person person = model.addPerson("Person", "Description");
    person.uses(softwareSystem, "Uses");
    Container container = softwareSystem.addContainer("Container", "Description", "Technology");
    Component component = container.addComponent("Component", "Description", "Technology");

    DeploymentNode deploymentNode = model.addDeploymentNode("Deployment Node", "Description", "Technology");
    ContainerInstance containerInstance = deploymentNode.add(container);

    return workspace;
}
 
Example #20
Source File: EncryptedWorkspace.java    From java with Apache License 2.0 5 votes vote down vote up
private void init(Workspace workspace, String plaintext, EncryptionStrategy encryptionStrategy) throws Exception {
    this.workspace = workspace;

    setId(workspace.getId());
    setName(workspace.getName());
    setDescription(workspace.getDescription());
    setVersion(workspace.getVersion());
    setRevision(workspace.getRevision());
    setLastModifiedUser(workspace.getLastModifiedUser());
    setLastModifiedAgent(workspace.getLastModifiedAgent());

    this.plaintext = plaintext;
    this.ciphertext = encryptionStrategy.encrypt(plaintext);
    this.encryptionStrategy = encryptionStrategy;
}
 
Example #21
Source File: ViewSetTests.java    From java with Apache License 2.0 5 votes vote down vote up
@Test
public void test_createDeploymentViewForASoftwareSystem_ThrowsAnException_WhenAnEmptyKeyIsSpecified() {
    try {
        Workspace workspace = new Workspace("Name", "Description");
        SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Software System", "Description");
        workspace.getViews().createDeploymentView(softwareSystem, " ", "Description");
        fail();
    } catch (IllegalArgumentException iae) {
        assertEquals("A key must be specified.", iae.getMessage());
    }
}
 
Example #22
Source File: ThemeUtils.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Serializes the theme (element and relationship styles) in the specified workspace to a JSON string.
 *
 * @param workspace     a Workspace instance
 * @return              a JSON string
 * @throws Exception    if something goes wrong
 */
public static String toJson(Workspace workspace) throws Exception {
    if (workspace == null) {
        throw new IllegalArgumentException("A workspace must be provided.");
    }

    StringWriter writer = new StringWriter();
    write(workspace, writer);

    return writer.toString();
}
 
Example #23
Source File: ViewSetTests.java    From java with Apache License 2.0 5 votes vote down vote up
@Test
public void test_createFilteredView_ThrowsAnException_WhenANullKeyIsSpecified() {
    try {
        Workspace workspace = new Workspace("Name", "Description");
        SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("systemLandscape", "Description");
        workspace.getViews().createFilteredView(view, null, "Description", FilterMode.Include, "tag1", "tag2");
        fail();
    } catch (IllegalArgumentException iae) {
        assertEquals("A key must be specified.", iae.getMessage());
    }
}
 
Example #24
Source File: WorkspaceUtils.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the specified JSON string to a Workspace instance.
 *
 * @param json      the JSON definition of the workspace
 * @return  a Workspace instance
 * @throws Exception    if the JSON can not be deserialized
 */
public static Workspace fromJson(String json) throws Exception {
    if (json == null || json.trim().length() == 0) {
        throw new IllegalArgumentException("A JSON string must be provided.");
    }

    StringReader stringReader = new StringReader(json);
    return new JsonReader().read(stringReader);
}
 
Example #25
Source File: ViewSetTests.java    From java with Apache License 2.0 5 votes vote down vote up
@Test
public void test_createFilteredView_ThrowsAnException_WhenADuplicateKeyIsUsed() {
    Workspace workspace = new Workspace("Name", "Description");
    SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("systemLandscape", "Description");
    workspace.getViews().createFilteredView(view, "filtered", "Description", FilterMode.Include, "tag1", "tag2");
    try {
        workspace.getViews().createFilteredView(view, "filtered", "Description", FilterMode.Include, "tag1", "tag2");
        fail();
    } catch (IllegalArgumentException iae) {
        assertEquals("A view with the key filtered already exists.", iae.getMessage());
    }
}
 
Example #26
Source File: ViewSetTests.java    From java with Apache License 2.0 5 votes vote down vote up
@Test
public void test_createDynamicViewForASoftwareSystem_ThrowsAnException_WhenANullSoftwareSystemIsSpecified() {
    try {
        new Workspace("", "").getViews().createDynamicView((SoftwareSystem)null, "key", "Description");
        fail();
    } catch (IllegalArgumentException iae) {
        assertEquals("A software system must be specified.", iae.getMessage());
    }
}
 
Example #27
Source File: WorkspaceUtils.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Saves a workspace to a JSON definition as a file.
 *
 * @param workspace     a Workspace object
 * @param file          a File representing the JSON definition
 * @throws Exception    if something goes wrong
 */
public static void saveWorkspaceToJson(Workspace workspace, File file) throws Exception {
    if (workspace == null) {
        throw new IllegalArgumentException("A workspace must be provided.");
    } else if (file == null) {
        throw new IllegalArgumentException("The path to a JSON file must be specified.");
    }

    OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
    new JsonWriter(true).write(workspace, writer);
    writer.flush();
    writer.close();
}
 
Example #28
Source File: WorkspaceUtils.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Loads a workspace from a JSON definition saved as a file.
 *
 * @param file a File representing the JSON definition
 * @return a Workspace object
 * @throws Exception if something goes wrong
 */
public static Workspace loadWorkspaceFromJson(File file) throws Exception {
    if (file == null) {
        throw new IllegalArgumentException("The path to a JSON file must be specified.");
    } else if (!file.exists()) {
        throw new IllegalArgumentException("The specified JSON file does not exist.");
    }

    return new JsonReader().read(new FileReader(file));
}
 
Example #29
Source File: EncryptedWorkspace.java    From java with Apache License 2.0 5 votes vote down vote up
@JsonIgnore
public Workspace getWorkspace() throws Exception {
    if (this.workspace != null) {
        return this.workspace;
    } else if (this.ciphertext != null) {
        this.plaintext = encryptionStrategy.decrypt(ciphertext);
        JsonReader jsonReader = new JsonReader();
        StringReader stringReader = new StringReader(plaintext);
        return jsonReader.read(stringReader);
    } else {
        return null;
    }
}
 
Example #30
Source File: EncryptedWorkspace.java    From java with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an encrypted version of the specified workspace.
 *
 * @param workspace             the Workspace to encrypt
 * @param encryptionStrategy    the encryption strategy
 * @throws Exception            if an error occurs while creating the encrypted workspace
 */
public EncryptedWorkspace(Workspace workspace, EncryptionStrategy encryptionStrategy) throws Exception {
    setConfiguration(workspace.getConfiguration());
    workspace.clearConfiguration();

    JsonWriter jsonWriter = new JsonWriter(false);
    StringWriter stringWriter = new StringWriter();
    jsonWriter.write(workspace, stringWriter);

    init(workspace, stringWriter.toString(), encryptionStrategy);
}