Esempio n. 1
0
  private void completeEvidenceDocument() throws IOException {

    String tempText =
        "<table><tr><td class=\"subHeading\">Evidence:</td><td class=\"info\">"
            + this.theEvidence.getName()
            + "</td></tr>\n";

    // add the type of evidence
    tempText +=
        "<tr><td class=\"subHeading\">Type:</td><td class=\"info\">"
            + this.theEvidence.getType()
            + "</td></tr>\n";

    // add the evidence description
    tempText +=
        "<tr><td class=\"subHeading\">Description:</td><td class=\"info\">"
            + this.theEvidence.getDescription()
            + "</td></tr>\n";

    // add the sources relating to the given piece of evidence
    tempText += "<tr><td class=\"subHeading\">References:</td><td class=\"info\" colspan=\"3\">\n";

    for (Source s : this.theEvidence.getSources(allTheSources)) {
      tempText +=
          "\t<li><a href=\"../source/" + s.getName() + ".html\">" + s.getName() + "</a></li>\n";
    }

    tempText += "</td></tr>\n";
    // tempText +="</body></html>";
    tempText +=
        "</table></div>\n<div id=\"footer\">\n\t&copy; "
            + getYear()
            + " <a href=\"http://www.eecs.qmul.ac.uk/research/view/risk-and-information-management\"> Risk and Information Management (RIM) Research Group, Queen Mary, University of London</a>\n</div>\n</body>\n</html>";
    appendCurrentDocument(tempText, "evidence");
  }
Esempio n. 2
0
  /**
   * Determines if the subset of information in a SourceRef is equal to particular Source object.
   * Note that only the final segment of the href field of the SourceRef is compared to the Source
   * object, as the Source object does not contain its own URI. Thus if the SourceRef was from a
   * different server than the Source object, this test would return true even though the SourceRef
   * points to a different copy of this Source object.
   *
   * @param source The Source to be compared.
   * @return True if all the fields in the SourceRef correspond to the same fields in the Source
   */
  public boolean equalsSource(Source source) {
    String hrefSourceName = this.getHref().substring(this.getHref().lastIndexOf('/') + 1);

    return (this.getName().equals(source.getName())
        && (this.getOwner().equals(source.getOwner()))
        && (this.isPublic() == source.isPublic())
        && (this.isVirtual() == source.isVirtual())
        && (this.getCoordinates().equals(source.getCoordinates()))
        && (this.getLocation().equals(source.getLocation()))
        && (this.getDescription().equals(source.getDescription()))
        && (source.getName().equals(hrefSourceName)));
  }
Esempio n. 3
0
  /**
   * Return the Properties that enumerate the keys for this Source
   *
   * @param source the Source
   * @return the relevant Properties
   */
  protected static Properties getKeyProperties(Source source) {
    Properties keys = null;
    synchronized (sourceKeys) {
      keys = sourceKeys.get(source);
      if (keys == null) {
        String sourceNameKeysFileName = source.getName() + "_keys.properties";
        keys = PropertiesUtil.loadProperties(sourceNameKeysFileName);

        String sourceTypeKeysFileName = source.getType() + "_keys.properties";
        if (keys == null) {
          keys = PropertiesUtil.loadProperties(sourceTypeKeysFileName);
        }

        if (keys == null) {
          throw new RuntimeException(
              "can't find keys for source: "
                  + source
                  + " after trying to find: "
                  + sourceNameKeysFileName
                  + " and: "
                  + sourceTypeKeysFileName);
        }

        sourceKeys.put(source, keys);
      }
    }
    return keys;
  }
 protected void say(Source source, String str) {
   Server server = source.getServer();
   if (source.talkable()) {
     source.messageReceived(server.getNick(), str);
     server.say(source.getName(), str);
   } else {
     source.report(getText(IRCTextProvider.INTERPRETOR_NOT_ON_CHANNEL));
   }
 }
Esempio n. 5
0
 /**
  * Creates a SourceRef object from a Source object using the provided URI for the SourceRef
  * pointing to the full Source resource. Needs to be kept up to date with any changes to the
  * schema, which is bogus.
  *
  * @param source The Source to build the SourceRef from.
  * @param uri The URI where the Source is located.
  */
 public SourceRef(Source source, String uri) {
   this(
       source.getName(),
       source.getOwner(),
       source.isPublic(),
       source.isVirtual(),
       source.getCoordinates(),
       source.getLocation(),
       source.getDescription(),
       uri);
 }
Esempio n. 6
0
  public Object getValueAt(int row, int col) {

    Source s = sources.get(row);

    switch (col) {
      case 0:
        return s.getName();
      case 1:
        return s.getPosition();
      case 2:
        return s.getEmail();
    }
    return null;
  }
 private Source getSource(String serverName, String type, String name) {
   Enumeration<Server> e = _servers.keys();
   while (e.hasMoreElements()) {
     Server s = (Server) e.nextElement();
     String sname = s.getServerName();
     if (sname.equals(serverName) || serverName.length() == 0) {
       Enumeration<Source> f = s.getSources();
       while (f.hasMoreElements()) {
         Source src = (Source) f.nextElement();
         if (src.getType().equals(type) && src.getName().equals(name)) return src;
       }
     }
   }
   return null;
 }
Esempio n. 8
0
  private String associateFile(Source source, String propertyName) throws Exception {
    if (source.hasProperty(propertyName)) {
      source.deleteProperty(propertyName);
    }
    File stats = source.createFileProperty(propertyName);
    DataSource ds = dsf.getDataSource(source.getName());
    ds.open();
    long rc = ds.getRowCount();
    ds.close();

    FileOutputStream fis = new FileOutputStream(stats);
    String rcStr = Long.toString(rc);
    fis.write(rcStr.getBytes());
    fis.close();

    return rcStr;
  }
Esempio n. 9
0
 @Override
 public int compareTo(Source other) {
   return getName().compareTo(other.getName());
 }
Esempio n. 10
0
  protected AndromedaFile parseAllFiles(IParser p) throws Exception {
    AndromedaFile af = null;

    // Assemble file lists
    List<Source> natives =
        FileCollector.getFilesFromList(options.nativeLibFolder, options.nativeList);
    List<Source> langFiles = getLanguageFiles();
    List<Source> triggers = null;

    int numFiles = files.size();
    if (options.mapIn != null) {
      if (numFiles > 0) {
        Program.log.caption(
            "+++ Compiling map "
                + options.mapIn.getName()
                + " and "
                + numFiles
                + " additional script files +++");
      } else {
        Program.log.caption("+++ Compiling map " + options.mapIn.getName() + " +++");
      }
      System.out.print("Extracting code from map file...");
      map = new MoPaQ(options.mapIn);
      triggers = new TriggerExtractor().extractTriggers(map);
      System.out.println(" DONE (" + getTime() + " ms)");
    } else {
      if (options.triggersIn != null) {
        triggers = new TriggerExtractor().extractTriggers(options.triggersIn);
      }
      Program.log.caption("+++ Compiling " + numFiles + " script files +++");
      if (numFiles > 0) {

      } else {
        Program.log.caption("+++ Compiling map " + options.mapIn.getName() + " +++");
      }
    }

    // Natives
    if (parseNatives)
      for (Source f : natives) {
        System.out.print("Parsing native library [" + f.getName() + "]...");
        af = p.parse(f, af, AndromedaFileInfo.TYPE_NATIVE);
        System.out.println(" DONE (" + getTime() + " ms)");
      }

    // Language files
    for (Source f : langFiles) {
      System.out.print("Parsing andromeda system library [" + f.getName() + "]...");
      af = p.parse(f, af, AndromedaFileInfo.TYPE_LANGUAGE);
      System.out.println(" DONE (" + getTime() + " ms)");
    }

    // Normal files
    for (Source f : files) {
      System.out.print("Parsing " + f.getTypeName() + " [" + f.getName() + "]...");
      af = p.parse(f, af, AndromedaFileInfo.TYPE_MAIN);
      System.out.println(" DONE (" + getTime() + " ms)");
    }

    // Triggers in the input map if one was specified
    if (triggers != null) {
      for (Source f : triggers) {
        System.out.print("Parsing " + f.getTypeName() + " [" + f.getName() + "]...");
        af = p.parse(f, af, AndromedaFileInfo.TYPE_MAIN);
        System.out.println(" DONE (" + getTime() + " ms)");
      }
    }

    return af;
  }
Esempio n. 11
0
 @Override
 public String getName() {
   return base.getName();
 }
Esempio n. 12
0
 /**
  * Creates a SourceRef object from a Source object. The Server argument is required to build the
  * URI in the SourceRef pointing to the full Source resource.
  *
  * @param source The Source to build the SourceRef from.
  * @param server The Server where the Source is located.
  */
 public SourceRef(Source source, Server server) {
   this(source, server.getHostName() + Server.SOURCES_URI + "/" + source.getName());
 }
Esempio n. 13
0
  /**
   * Return a Set of PrimaryKeys relevant to a given Source for a ClassDescriptor. The Set contains
   * all the primary keys that exist on a particular class that are used by the source, without
   * performing any recursion. The Model.getClassDescriptorsForClass() method is recommended if you
   * wish for all the primary keys of the class' parents as well.
   *
   * @param cld the ClassDescriptor
   * @param source the Source
   * @param os the ObjectStore that these PrimaryKeys are used in, for creating indexes
   * @return a Set of PrimaryKeys
   */
  public static Set<PrimaryKey> getPrimaryKeys(ClassDescriptor cld, Source source, ObjectStore os) {
    GetPrimaryKeyCacheKey key = new GetPrimaryKeyCacheKey(cld, source);
    synchronized (getPrimaryKeyCache) {
      Set<PrimaryKey> keySet = getPrimaryKeyCache.get(key);
      if (keySet == null) {
        keySet = new LinkedHashSet<PrimaryKey>();
        Properties keys = getKeyProperties(source);
        if (keys != null) {
          if (!verifiedSources.contains(source)) {
            String packageNameWithDot =
                cld.getName().substring(0, cld.getName().lastIndexOf('.') + 1);
            LOG.info(
                "Verifying primary key config for source "
                    + source
                    + ", packageName = "
                    + packageNameWithDot);
            for (Map.Entry<Object, Object> entry : keys.entrySet()) {
              String cldName = (String) entry.getKey();
              String keyList = (String) entry.getValue();
              if (!cldName.contains(".")) {
                ClassDescriptor iCld =
                    cld.getModel().getClassDescriptorByName(packageNameWithDot + cldName);
                if (iCld != null) {
                  Map<String, PrimaryKey> map = PrimaryKeyUtil.getPrimaryKeys(iCld);

                  String[] tokens = keyList.split(",");
                  for (int i = 0; i < tokens.length; i++) {
                    String token = tokens[i].trim();
                    if (map.get(token) == null) {
                      throw new IllegalArgumentException(
                          "Primary key "
                              + token
                              + " for class "
                              + cldName
                              + " required by datasource "
                              + source.getName()
                              + " in "
                              + source.getName()
                              + "_keys.properties is not defined in "
                              + cld.getModel().getName()
                              + "_keyDefs.properties");
                    }
                  }
                } else {
                  LOG.warn(
                      "Ignoring entry for "
                          + cldName
                          + " in file "
                          + cld.getModel().getName()
                          + "_keyDefs.properties - not in model!");
                }
              }
            }
            verifiedSources.add(source);
          }
          Map<String, PrimaryKey> map = PrimaryKeyUtil.getPrimaryKeys(cld);
          String cldName = TypeUtil.unqualifiedName(cld.getName());
          String keyList = (String) keys.get(cldName);
          if (keyList != null) {
            String[] tokens = keyList.split(",");
            for (int i = 0; i < tokens.length; i++) {
              String token = tokens[i].trim();
              if (map.get(token) == null) {
                throw new IllegalArgumentException(
                    "Primary key "
                        + token
                        + " for class "
                        + cld.getName()
                        + " required by data source "
                        + source.getName()
                        + " in "
                        + source.getName()
                        + "_keys.properties is not defined in "
                        + cld.getModel().getName()
                        + "_keyDefs.properties");
              } else {
                keySet.add(map.get(token));
              }
            }
          }
          for (Map.Entry<Object, Object> entry : keys.entrySet()) {
            String propKey = (String) entry.getKey();
            String fieldList = (String) entry.getValue();
            int posOfDot = propKey.indexOf('.');
            if (posOfDot > 0) {
              String propCldName = propKey.substring(0, posOfDot);
              if (cldName.equals(propCldName)) {
                String keyName = propKey.substring(posOfDot + 1);
                PrimaryKey pk = new PrimaryKey(keyName, fieldList, cld);
                if (!keySet.contains(pk)) {
                  keySet.add(pk);
                  if (os instanceof ObjectStoreInterMineImpl) {
                    ObjectStoreInterMineImpl osimi = (ObjectStoreInterMineImpl) os;
                    DatabaseSchema schema = osimi.getSchema();
                    ClassDescriptor tableMaster = schema.getTableMaster(cld);
                    String tableName = DatabaseUtil.getTableName(tableMaster);
                    List<String> fields = new ArrayList<String>();

                    for (String field : pk.getFieldNames()) {
                      String colName = DatabaseUtil.generateSqlCompatibleName(field);
                      if (tableMaster.getReferenceDescriptorByName(field, true) != null) {
                        colName += "id";
                      }
                      fields.add(colName);
                    }
                    String sql =
                        "CREATE INDEX "
                            + tableName
                            + "__"
                            + keyName
                            + " ON "
                            + tableName
                            + " ("
                            + StringUtil.join(fields, ", ")
                            + ")";
                    System.out.println("Creating index: " + sql);
                    LOG.info("Creating index: " + sql);
                    Connection conn = null;
                    try {
                      conn = osimi.getConnection();
                      conn.createStatement().execute(sql);
                    } catch (SQLException e) {
                      LOG.warn("Index creation failed", e);
                    } finally {
                      if (conn != null) {
                        osimi.releaseConnection(conn);
                      }
                    }
                  }
                }
              }
            }
          }
        } else {
          throw new IllegalArgumentException(
              "Unable to find keys for source "
                  + source.getName()
                  + " in file "
                  + source.getName()
                  + "_keys.properties");
        }
        getPrimaryKeyCache.put(key, keySet);
      }
      return keySet;
    }
  }
 private static String makeKey(Source source, String shortcutId) {
   return source.getName() + "#" + shortcutId;
 }
 public String getName() {
   return mSource.getName();
 }