Skip to content

Commit

Permalink
Merge pull request #132 from InCadence/126
Browse files Browse the repository at this point in the history
#126 Implemented ability to delete templates with the file persister
  • Loading branch information
InCadence committed Feb 27, 2019
2 parents 3906a83 + 6318fe4 commit 4e7b8d6
Showing 1 changed file with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,23 @@
import com.incadencecorp.coalesce.framework.datamodel.CoalesceEntity;
import com.incadencecorp.coalesce.framework.datamodel.CoalesceEntityTemplate;

import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.*;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
* This implementation uses the file system to store and retrieve Coalesce
Expand Down Expand Up @@ -226,21 +238,34 @@ public void saveTemplate(CoalesceEntityTemplate... templates) throws CoalescePer
@Override
public void deleteTemplate(String... keys) throws CoalescePersistorException
{
throw new CoalescePersistorException("Not Implemented");
unregisterTemplate(keys);
}

@Override
public void unregisterTemplate(String... keys) throws CoalescePersistorException
{
throw new CoalescePersistorException("Not Implemented");
Path sub = root.resolve(TEMPLATE_DIRECTORY);

for (String key : keys)
{
try
{
Files.deleteIfExists(sub.resolve(key));
}
catch (IOException e)
{
throw new CoalescePersistorException("Failed Deleting Template: " + key, e);
}
}
}

@Override
public void registerTemplate(CoalesceEntityTemplate... templates) throws CoalescePersistorException
{
Path sub = root.resolve(TEMPLATE_DIRECTORY);

for (CoalesceEntityTemplate template : templates)
{
Path sub = root.resolve(TEMPLATE_DIRECTORY);
Path filename = sub.resolve(template.getKey());

try
Expand All @@ -260,14 +285,10 @@ public void registerTemplate(CoalesceEntityTemplate... templates) throws Coalesc
{
writer.write(template.toXml());
}
catch (IOException e)
{
throw new CoalescePersistorException("(FAILED) Saving Entity", e);
}
}
catch (IOException e)
{
throw new CoalescePersistorException("Failed to Record Entity", e);
throw new CoalescePersistorException("(FAILED) Saving Template: " + template.getKey(), e);
}
}
}
Expand Down

0 comments on commit 4e7b8d6

Please sign in to comment.