Changeset 1430 for trunk


Ignore:
Timestamp:
08/14/19 14:22:44 (5 years ago)
Author:
bln4
Message:

Fixed bug for when there are no surrogates left for a primary.

Location:
trunk/src/org/expeditee
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/encryption/Actions.java

    r1414 r1430  
    2323import org.expeditee.gui.Frame;
    2424import org.expeditee.gui.FrameIO;
     25import org.expeditee.gui.MessageBay;
    2526import org.expeditee.items.Item;
    2627import org.expeditee.items.Text;
     
    3132public class Actions implements CryptographyConstants {
    3233       
    33         public static void TestSurrogate(Item primary) {
    34                 System.out.println("Test surrogates: ");
     34        public static void SetSurrogateFor(Text surrogate, Text action) {
     35                Frame frame = DisplayController.getCurrentFrame();
     36                String[] split = action.getText().split(" ");
     37               
     38                if (split.length >= 2) {
     39                        int primaryID = Integer.parseInt(split[1]);
     40                        Item itemWithID = frame.getItemWithID(primaryID);
     41                        if (itemWithID == null) {
     42                                MessageBay.displayMessage("No item with ID " + primaryID + " exists on this frame.");
     43                                return;
     44                        } else {
     45                                itemWithID.addToSurrogates(surrogate);
     46                        }
     47                } else {
     48                        MessageBay.displayMessage("Usage: SetSurrogateFor Int, inject desired surrogate.");
     49                }
    3550        }
    3651       
  • trunk/src/org/expeditee/encryption/io/EncryptedExpWriter.java

    r1420 r1430  
    194194                Function<Item, Boolean> isTagInherited = surrogate -> surrogate.isTagInherited(tag + "");
    195195                BinaryOperator<Boolean> trueExists = (a, b) -> a || b;
    196                 boolean surrogatesInherit = surrogateItems.stream().map(isTagInherited).collect(Collectors.reducing(trueExists)).get();
     196                boolean surrogatesInherit = surrogateItems.stream().map(isTagInherited).collect(Collectors.reducing(trueExists)).orElseGet(() -> false);
    197197                boolean userHasKey = Label.getLabel(toWrite.getEncryptionLabel()) == LabelResult.SuccessResolveLabelToKey;
    198198               
    199                 // If we have no surrogates that inherit this property from us, and we have the label required to encrypt it, then we should entry it.
     199                // If we have no surrogates that inherit this property from us, and we have the label required to encrypt it, then we should encrypt it.
    200200                if (!surrogatesInherit && userHasKey) {
    201201                        EncryptionDetail reencryptOnSave = new EncryptionDetail(EncryptionDetail.Type.ReencryptOnSave);
  • trunk/src/org/expeditee/encryption/items/surrogates/Label.java

    r1415 r1430  
    5454
    5555        public static List<String> getAccessibleLabelsNames(ItemsList itemsList) {
     56                // TODO make copy of itemsList in here and then adjust callers so they do not need to make copy.
     57                // Alternatively, filter instead of removeIf
    5658                Text[] userLabels = KeyList.UserLabels.get();
    5759                Stream<String> accessibleUserWideLabels = Arrays.asList(userLabels).stream().map(label -> label.getText());
    5860               
    59                 Predicate<Item> isLabelWithoutEncryptionLabel = item -> item.getEncryptionLabel() == null || item.getEncryptionLabel().isEmpty();
    60                 itemsList.removeIf(isLabelWithoutEncryptionLabel);
     61                Predicate<Item> isItemWithoutEncryptionLabel = item -> item.getEncryptionLabel() == null || item.getEncryptionLabel().isEmpty();
     62                itemsList.removeIf(isItemWithoutEncryptionLabel);
    6163                Stream<String> accessibleFrameLocalLabels = itemsList.underlying().stream().map(item -> item.getEncryptionLabel()).distinct();
    6264               
  • trunk/src/org/expeditee/gui/AttributeUtils.java

    r1415 r1430  
    308308                        _Attrib.put("EncryptionLabel",          Item.class.getMethod("getEncryptionLabel"),
    309309                                                                                                Item.class.getMethod("setEncryptionLabel", pString));
     310                        _Attrib.put("ID",                                       Item.class.getMethod("getID"),
     311                                                                                                Item.class.getMethod("setIDFail", pInt));
    310312                       
    311313                        // Text Items
  • trunk/src/org/expeditee/gui/DisplayController.java

    r1415 r1430  
    12351235               
    12361236                Label.progressSurrogateMode();
     1237                Frame currentFrame = DisplayController.getCurrentFrame();
     1238                ItemsList primaryBody = currentFrame.getPrimaryBody();
     1239                ItemsList primaryBodyCopy = new ItemsList(primaryBody);
     1240                List<String> accessibleLabelsNames = Label.getAccessibleLabelsNames(primaryBodyCopy);
     1241                StringBuilder sb = new StringBuilder("Surrogate Mode currently accepts labels: ");
     1242                for (String acceessibleLabel: accessibleLabelsNames) {
     1243                        sb.append(acceessibleLabel + ", ");
     1244                }
     1245                String message = sb.substring(0, sb.length() - 2);
     1246                MessageBay.displayMessage(message);
    12371247               
    12381248                getCurrentFrame().parse();
  • trunk/src/org/expeditee/gui/Frame.java

    r1426 r1430  
    3131import java.util.List;
    3232import java.util.Map;
     33import java.util.Set;
    3334import java.util.Stack;
    3435import java.util.stream.Collectors;
     
    10201021                if (item.isSurrogate()) {
    10211022                        removeItem(item, recalculate, _surrogateItemsBody);
     1023                        Set<Item> primariesSurrogates = item.getPrimary().getSurrogates();
     1024                        primariesSurrogates.remove(item);
    10221025                } else {
    10231026                        removeItem(item, recalculate, _primaryItemsBody);
  • trunk/src/org/expeditee/items/Item.java

    r1429 r1430  
    10431043         * TODO: What does it mean to have a negative ID# (as used in TDFC)? cts16
    10441044         */
    1045         public int getID()
    1046         {
     1045        public int getID() {
    10471046                return _id;
    10481047        }
     
    22192218                }
    22202219        }
     2220       
     2221        /**
     2222         * Function called when a user attempts to set the ID of a Item.  Simply provides
     2223         * feedback to the user telling them that they are not allowed to do this.  This
     2224         * function is provided so that users are able to get the ID of a item when
     2225         * extracting properties.  See {@link org.expeditee.gui.AttributeUtils}.
     2226         *
     2227         * @param newID The requested new ID that will be ignored.
     2228         */
     2229        public void setIDFail(int newID) {
     2230                MessageBay.displayMessage("A user cannot change the ID of an item.");
     2231        }
    22212232
    22222233        /**
     
    41564167
    41574168        public void addToSurrogates(Item surrogate) {
     4169                this.getParent().removeItem(surrogate);
    41584170                this.surrogateItems.add(surrogate);
    41594171                surrogate.setAsSurrogateFor(this);
     
    41624174                EncryptionDetail reencryptOnSave = new EncryptionDetail(EncryptionDetail.Type.ReencryptOnSave);
    41634175                EncryptionDetail unencryptedOnSave = new EncryptionDetail(EncryptionDetail.Type.UnencryptedOnSave);
    4164                 EncryptionDetail inheritanceCheckOnSave = new EncryptionDetail(EncryptionDetail.Type.InheritanceCheckOnSave);
    41654176               
    41664177                for (Character tag: DefaultFrameWriter.getItemCharTags().keySet()) {
     
    41794190               
    41804191                for (String tag: DefaultFrameWriter.getItemStrTags().keySet()) {
    4181                         primaryPropertyEncryption.put(tag, inheritanceCheckOnSave.clone());
     4192                        primaryPropertyEncryption.put(tag, unencryptedOnSave.clone());
    41824193                        surrogate.surrogatePropertyInheritance.put(tag + "", true);
    41834194                }
     
    42314242         */
    42324243        protected boolean subjectToInheritanceCheckOnSave(String tag) {
     4244                if (tag.equals(DefaultFrameWriter.TYPE_AND_ID_STR)) {
     4245                        return false;
     4246                }
    42334247                Item primary = getPrimary();
    42344248                if (primary == null) return false;
Note: See TracChangeset for help on using the changeset viewer.