Clover coverage report -
Coverage timestamp: Mon May 5 2008 11:56:20 GMT-05:00
file stats: LOC: 295   Methods: 33
NCLOC: 196   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MetaData.java 60% 81.2% 97% 80.4%
coverage coverage
 1    /*
 2    * Copyright 2005 The Regents of the University of Michigan
 3    *
 4    * Licensed under the Apache License, Version 2.0 (the "License");
 5    * you may not use this file except in compliance with the License.
 6    * You may obtain a copy of the License at
 7    *
 8    * http://www.apache.org/licenses/LICENSE-2.0
 9    *
 10    * Unless required by applicable law or agreed to in writing, software
 11    * distributed under the License is distributed on an "AS IS" BASIS,
 12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13    * See the License for the specific language governing permissions and
 14    * limitations under the License.
 15    */
 16    package org.proteomecommons.tranche.util;
 17   
 18    import java.util.ArrayList;
 19    import org.proteomecommons.tranche.Signature;
 20   
 21    /**
 22    *
 23    * @author Jayson Falkner - jfalkner@umich.edu
 24    * @author James "Augie" Hill - augie@828productions.com
 25    */
 26    public class MetaData {
 27    // some arbitrary bits that can be used in the status bit
 28    public static final int VERSION_ONE_BIT = (int) Math.pow(2, 0);
 29    public static final int PROJECT_FILE_BIT = (int) Math.pow(2, 1);
 30    public static final int STICKY_DATA_BIT = (int) Math.pow(2, 2);
 31    public static final int STICKY_META_DATA_BIT = (int) Math.pow(2, 3);
 32    public static final int GZIP_COMPRESSED_BIT = (int) Math.pow(2, 4);
 33    public static final int LIMITED_LIFE_BIT = (int) Math.pow(2, 5);
 34    public static final int MIME_TYPE_BIT = (int) Math.pow(2, 6);
 35    // rest of the bits are reserved
 36    private String version = "1";
 37    // timestamp
 38    private long timestamp = System.currentTimeMillis();
 39    // the expiration date of this data
 40    private long expiration = 0;
 41    // the original file's name
 42    private String name = "";
 43    // list of the parts. order matters.
 44    private ArrayList<BigHash> parts = new ArrayList();
 45    // list of encodings, .e.g "LZMA" and "AES"
 46    private ArrayList<FileEncoding> encodings = new ArrayList();
 47    // list of annotations
 48    private ArrayList<MetaDataAnnotation> annotations = new ArrayList();
 49    // list of signatures
 50    private ArrayList<Signature> signatures = new ArrayList();
 51    // the flags
 52    private int flags = VERSION_ONE_BIT | GZIP_COMPRESSED_BIT;
 53    // the MIME type
 54    private String mimeType = null;
 55   
 56  34639 public boolean hasMimeType() {
 57  34639 return (MIME_TYPE_BIT & flags) != 0;
 58    }
 59   
 60  17 public boolean isStickyData() {
 61  17 return (STICKY_DATA_BIT & flags) != 0;
 62    }
 63   
 64  19 public boolean isStickyMetaData() {
 65  19 return (STICKY_META_DATA_BIT & flags) != 0;
 66    }
 67   
 68  22996 public boolean isProjectFile() {
 69    // check the name
 70  22996 if (getName() != null && getName().contains(ProjectFile.DEFAULT_PROJECT_FILE_NAME)) {
 71  155 return true;
 72    }
 73    // check for the project file bit
 74  22841 return (PROJECT_FILE_BIT & flags) != 0;
 75    }
 76   
 77  34641 public boolean isLimitedLife() {
 78  34641 return (LIMITED_LIFE_BIT & flags) != 0;
 79    }
 80   
 81  34639 public boolean isGZIPCompressed() {
 82  34639 return (GZIP_COMPRESSED_BIT & flags) != 0;
 83    }
 84   
 85  23532 public boolean isVersionOne() {
 86  23532 return (VERSION_ONE_BIT & flags) != 0;
 87    }
 88   
 89  18 public boolean isDeleted() {
 90  18 synchronized (annotations) {
 91  18 for (MetaDataAnnotation mda : annotations) {
 92  43 if (mda.getName().equals(MetaDataAnnotation.PROP_DELETED)) {
 93  3 return true;
 94    }
 95    }
 96    }
 97  15 return false;
 98    }
 99   
 100  2 public void setDeleted(boolean isDeleted) {
 101  2 if (isDeleted && !isDeleted()) {
 102  1 synchronized (annotations) {
 103  1 annotations.add(new MetaDataAnnotation(MetaDataAnnotation.PROP_DELETED, String.valueOf(System.currentTimeMillis())));
 104    }
 105  1 } else if (!isDeleted && isDeleted()) {
 106  1 synchronized (annotations) {
 107  1 MetaDataAnnotation deletedAnnotation = null;
 108  1 for (MetaDataAnnotation mda : annotations) {
 109  1 if (mda.getName().equals(MetaDataAnnotation.PROP_DELETED)) {
 110  1 deletedAnnotation = mda;
 111    }
 112    }
 113  1 if (deletedAnnotation != null) {
 114  1 annotations.remove(deletedAnnotation);
 115    }
 116    }
 117    }
 118    }
 119   
 120    /**
 121    *Helper method that will inspect the encodings and check that all encryptions have a passphrase.
 122    */
 123  34 public boolean isEncrypted() {
 124    // sync to avoid others from mucking with the encodings
 125  34 synchronized (encodings) {
 126    // check each encoding
 127  34 for (FileEncoding fe : encodings) {
 128    // if it is AES, look for the passphrase
 129    // if (fe.getName().equals(FileEncoding.AES) && fe.getProperties().getProperty(FileEncoding.PROP_PASSPHRASE) == null) {
 130  72 if (fe.getName().equals(FileEncoding.AES)) {
 131  5 return true;
 132    }
 133    }
 134    }
 135  29 return false;
 136    }
 137   
 138  0 public void setPublicPassphrase(String passphrase) throws Exception {
 139  0 FileEncoding AESFileEncoding = null;
 140   
 141    // sync to avoid others from mukcing with the encodings
 142  0 synchronized (encodings) {
 143    // check each encoding
 144  0 for (FileEncoding fe : encodings) {
 145    // if it is AES, look for the passphrase
 146  0 if (fe.getName().equals(FileEncoding.AES)) {
 147  0 AESFileEncoding = fe;
 148  0 break;
 149    }
 150    }
 151    }
 152   
 153    // make sure this meta data points to data that is actually encrypted
 154  0 if (AESFileEncoding == null) {
 155  0 throw new RuntimeException("The data is not encrypted.");
 156    }
 157   
 158    // finish by setting the passphrase
 159  0 if (passphrase == null || passphrase.equals("")) {
 160  0 AESFileEncoding.getProperties().remove(FileEncoding.PROP_PASSPHRASE);
 161    } else {
 162  0 AESFileEncoding.setProperty(FileEncoding.PROP_PASSPHRASE, passphrase);
 163  0 addAnnotation(new MetaDataAnnotation(MetaDataAnnotation.PROP_PUBLISHED_TIMESTAMP, String.valueOf(System.currentTimeMillis())));
 164    }
 165    }
 166   
 167  1 public String getPublicPassphrase() throws Exception {
 168  1 FileEncoding AESFileEncoding = null;
 169   
 170    // sync to avoid others from mukcing with the encodings
 171  1 synchronized (encodings) {
 172    // check each encoding
 173  1 for (FileEncoding fe : encodings) {
 174    // if it is AES, look for the passphrase
 175  2 if (fe.getName().equals(FileEncoding.AES)) {
 176  1 AESFileEncoding = fe;
 177  1 break;
 178    }
 179    }
 180    }
 181   
 182    // make sure this meta data points to data that is actually encrypted
 183  1 if (AESFileEncoding == null) {
 184  0 throw new RuntimeException("The data is not encrypted.");
 185    }
 186   
 187    // check for a public passphrase
 188  1 if (AESFileEncoding.getProperty(FileEncoding.PROP_PASSPHRASE) == null) {
 189    // why are we pitching the exception here!?
 190    // throw new RuntimeException("There is no public passphrase set.");
 191   
 192    // returning null here makes sense
 193  1 return null;
 194    }
 195   
 196  0 return AESFileEncoding.getProperty(FileEncoding.PROP_PASSPHRASE);
 197    }
 198   
 199  12548 public ArrayList<BigHash> getParts() {
 200  12548 return parts;
 201    }
 202   
 203  23521 public void setParts(ArrayList<BigHash> parts) {
 204  23521 this.parts = parts;
 205    }
 206   
 207  13026 public ArrayList<FileEncoding> getEncodings() {
 208  13026 return encodings;
 209    }
 210   
 211  23521 public void setEncodings(ArrayList<FileEncoding> encodings) {
 212  23521 this.encodings = encodings;
 213    }
 214   
 215  16 public String getVersion() {
 216  16 return version;
 217    }
 218   
 219  23521 public void setVersion(String version) {
 220  23521 this.version = version;
 221    }
 222   
 223  11122 public ArrayList<MetaDataAnnotation> getAnnotations() {
 224  11122 return annotations;
 225    }
 226   
 227  2 public void addAnnotation(MetaDataAnnotation mda) {
 228  2 this.annotations.add(mda);
 229    }
 230   
 231  23521 public void setAnnotations(ArrayList<MetaDataAnnotation> annotations) {
 232  23521 this.annotations = annotations;
 233    }
 234   
 235  11996 public ArrayList<Signature> getSignatures() {
 236  11996 return signatures;
 237    }
 238   
 239  23521 public void setSignatures(ArrayList<Signature> sigs) {
 240  23521 this.signatures = sigs;
 241    }
 242   
 243  57533 public String getName() {
 244  57533 return name;
 245    }
 246   
 247  34620 public void setName(String name) {
 248  34620 this.name = name;
 249    }
 250   
 251  11115 public long getTimestamp() {
 252  11115 return timestamp;
 253    }
 254   
 255  33935 public void setTimestamp(long timestamp) {
 256  33935 this.timestamp = timestamp;
 257    }
 258   
 259  1 public long getExpiration() {
 260  1 return expiration;
 261    }
 262   
 263  2 public void setExpiration(long expiration) {
 264  2 this.expiration = expiration;
 265  2 if (expiration != 0) {
 266  1 setFlags(getFlags() | MetaData.LIMITED_LIFE_BIT);
 267    } else {
 268    // auto-flag off the limited life bit
 269  1 setFlags(getFlags() & (VERSION_ONE_BIT | PROJECT_FILE_BIT | STICKY_DATA_BIT | STICKY_META_DATA_BIT | GZIP_COMPRESSED_BIT | MetaData.MIME_TYPE_BIT));
 270    }
 271    }
 272   
 273  53526 public int getFlags() {
 274  53526 return flags;
 275    }
 276   
 277  54833 public void setFlags(int flags) {
 278  54833 this.flags = flags;
 279    }
 280   
 281  10429 public String getMimeType() {
 282  10429 return mimeType;
 283    }
 284   
 285  31236 public void setMimeType(String mimeType) {
 286  31236 this.mimeType = mimeType;
 287    // flag the mime bit
 288  31236 if (mimeType != null) {
 289  31236 setFlags(getFlags() | MetaData.MIME_TYPE_BIT);
 290    } else {
 291    // auto-flag off the mime-type bit
 292  0 setFlags(getFlags() & (VERSION_ONE_BIT | PROJECT_FILE_BIT | STICKY_DATA_BIT | STICKY_META_DATA_BIT | GZIP_COMPRESSED_BIT | LIMITED_LIFE_BIT));
 293    }
 294    }
 295    }