Search in sources :

Example 6 with Folder

use of com.nedap.archie.rm.directory.Folder in project ehrbase by ehrbase.

the class FolderServiceImpTest method serializesFolderToXML.

@Test
@Ignore
public void serializesFolderToXML() throws IOException {
    String value = IOUtils.toString(FolderTestDataCanonicalJson.SIMPLE_EMPTY_FOLDER.getStream(), UTF_8);
    Folder folder = cut.unmarshal(value, Folder.class);
    StructuredString result = folderService.serialize(folder, StructuredStringFormat.XML);
    StructuredString result2 = folderService.serialize(folder, StructuredStringFormat.XML);
    assertThat(result).isNotNull();
    assertThat(result.getFormat()).isEqualTo(StructuredStringFormat.XML);
    assertThat(result.getValue()).isEqualToIgnoringWhitespace("<folder xsi:type=\"FOLDER\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><name><value>Simple empty folder</value></name></folder>");
}
Also used : StructuredString(org.ehrbase.response.ehrscape.StructuredString) StructuredString(org.ehrbase.response.ehrscape.StructuredString) Folder(com.nedap.archie.rm.directory.Folder) TemporaryFolder(org.junit.rules.TemporaryFolder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with Folder

use of com.nedap.archie.rm.directory.Folder in project ehrbase by ehrbase.

the class FolderAccess method buildFolderAccessTreeRecursively.

/**
 * Recursive method for populating the hierarchy of {@link I_FolderAccess}  for a given {@link
 * com.nedap.archie.rm.directory.Folder}.
 *
 * @param domainAccess       providing the information about the DB connection.
 * @param current            {@link  com.nedap.archie.rm.directory.Folder} explored in the current
 *                           iteration.
 * @param parent             folder of the {@link  com.nedap.archie.rm.directory.Folder} procided
 *                           as the current parameter.
 * @param dateTime           of the transaction that will be stored inthe DB.
 * @param ehrId              of the {@link com.nedap.archie.rm.ehr.Ehr} referencing the current
 *                           {@link  com.nedap.archie.rm.directory.Folder}.
 * @param contributionAccess that corresponds to the contribution that the {@link
 *                           com.nedap.archie.rm.directory.Folder} refers to.
 * @return {@link I_FolderAccess} with the complete hierarchy of sub-folders represented as {@link
 * I_FolderAccess}.
 * @throws Exception
 */
private static I_FolderAccess buildFolderAccessTreeRecursively(final I_DomainAccess domainAccess, final Folder current, final FolderAccess parent, final DateTime dateTime, final UUID ehrId, final I_ContributionAccess contributionAccess) {
    I_FolderAccess folderAccess = null;
    // if the parent already contains the FolderAccess for the specified folder return the corresponding FolderAccess
    if ((parent != null) && (parent.getSubfoldersList().containsKey(UUID.fromString(current.getUid().getValue())))) {
        return parent.getSubfoldersList().get(current.getUid());
    }
    // create the corresponding FolderAccess for the current folder
    folderAccess = FolderAccess.buildPlainFolderAccess(domainAccess, current, Timestamp.from(Instant.now()), ehrId, contributionAccess);
    // add to parent subfolder list
    if (parent != null) {
        parent.getSubfoldersList().put(((FolderAccess) folderAccess).getFolderRecord().getId(), folderAccess);
    }
    for (Folder child : current.getFolders()) {
        buildFolderAccessTreeRecursively(domainAccess, child, (FolderAccess) folderAccess, dateTime, ehrId, ((FolderAccess) folderAccess).getContributionAccess());
    }
    return folderAccess;
}
Also used : I_FolderAccess(org.ehrbase.dao.access.interfaces.I_FolderAccess) Folder(com.nedap.archie.rm.directory.Folder) I_FolderAccess(org.ehrbase.dao.access.interfaces.I_FolderAccess)

Example 8 with Folder

use of com.nedap.archie.rm.directory.Folder in project openEHR_SDK by ehrbase.

the class DefaultRestDirectoryEndpoint method find.

synchronized Folder find(String path) {
    if (StringUtils.isBlank(path)) {
        return root;
    }
    String[] split = path.split(FOLDER_DIVIDER);
    Folder current = root;
    for (String folderName : split) {
        Folder newFolder = Optional.ofNullable(current).map(Folder::getFolders).flatMap(l -> l.stream().filter(f -> folderName.equals(f.getName().getValue())).findAny()).orElse(null);
        if (newFolder == null) {
            newFolder = new Folder();
            newFolder.setArchetypeNodeId("openEHR-EHR-FOLDER.generic.v1");
            newFolder.setName(new DvText(folderName));
            if (current.getFolders() == null) {
                current.setFolders(new ArrayList<>());
            }
            current.addFolder(newFolder);
        }
        current = newFolder;
    }
    return current;
}
Also used : EHR_PATH(org.ehrbase.client.openehrclient.defaultrestclient.DefaultRestEhrEndpoint.EHR_PATH) DvText(com.nedap.archie.rm.datavalues.DvText) VersionUid(org.ehrbase.client.openehrclient.VersionUid) Optional(java.util.Optional) Folder(com.nedap.archie.rm.directory.Folder) CompositionEndpoint(org.ehrbase.client.openehrclient.CompositionEndpoint) DirectoryResponseData(org.ehrbase.response.openehr.DirectoryResponseData) URI(java.net.URI) UUID(java.util.UUID) FolderDAO(org.ehrbase.client.openehrclient.FolderDAO) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Folder(com.nedap.archie.rm.directory.Folder) DvText(com.nedap.archie.rm.datavalues.DvText)

Example 9 with Folder

use of com.nedap.archie.rm.directory.Folder in project openEHR_SDK by ehrbase.

the class DefaultRestDirectoryEndpoint method createRoot.

private void createRoot() {
    root = new Folder();
    root.setName(new DvText("root"));
    root.setArchetypeNodeId("openEHR-EHR-FOLDER.generic.v1");
    VersionUid versionUid = defaultRestClient.httpPost(resolve(""), root);
    rootVersion = versionUid;
}
Also used : VersionUid(org.ehrbase.client.openehrclient.VersionUid) Folder(com.nedap.archie.rm.directory.Folder) DvText(com.nedap.archie.rm.datavalues.DvText)

Example 10 with Folder

use of com.nedap.archie.rm.directory.Folder in project openEHR_SDK by ehrbase.

the class DefaultRestFolderDAO method addCompositionEntity.

@Override
public <T> T addCompositionEntity(T entity) {
    T updatedEntity = directoryEndpoint.getCompositionEndpoint().mergeCompositionEntity(entity);
    UUID uuid = DefaultRestCompositionEndpoint.extractVersionUid(updatedEntity).orElseThrow(() -> new ClientException(String.format("No Id Element for %s", entity.getClass()))).getUuid();
    Folder folder = getFolder();
    if (folder.getItems() == null) {
        folder.setItems(new ArrayList<>());
    }
    folder.getItems().add(new ObjectRef(new ObjectVersionId(uuid.toString()), "dffddfd", "VERSIONED_COMPOSITION"));
    directoryEndpoint.saveToDb();
    return updatedEntity;
}
Also used : ClientException(org.ehrbase.client.exception.ClientException) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) UUID(java.util.UUID) Folder(com.nedap.archie.rm.directory.Folder) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef)

Aggregations

Folder (com.nedap.archie.rm.directory.Folder)17 Test (org.junit.Test)12 UUID (java.util.UUID)7 I_FolderAccess (org.ehrbase.dao.access.interfaces.I_FolderAccess)6 DvText (com.nedap.archie.rm.datavalues.DvText)5 Ignore (org.junit.Ignore)5 ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)4 ArrayList (java.util.ArrayList)4 ItemStructure (com.nedap.archie.rm.datastructures.ItemStructure)3 UIDBasedId (com.nedap.archie.rm.support.identification.UIDBasedId)3 I_ContributionAccess (org.ehrbase.dao.access.interfaces.I_ContributionAccess)3 Item (com.nedap.archie.rm.datastructures.Item)2 ObjectRef (com.nedap.archie.rm.support.identification.ObjectRef)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 VersionUid (org.ehrbase.client.openehrclient.VersionUid)2 StructuredString (org.ehrbase.response.ehrscape.StructuredString)2 TemporaryFolder (org.junit.rules.TemporaryFolder)2 ObjectId (com.nedap.archie.rm.support.identification.ObjectId)1 PartyRef (com.nedap.archie.rm.support.identification.PartyRef)1