示例#1
0
  private IQueryResult queryFetch(ICompiledQuery code, UserInformation user) {

    // TODO check rights for channel

    String id = code.getString(1);

    try {
      Properties current = new Properties();
      Reader reader = driver.getFileStore().get(IType.TYPE_OBJECT)[0].getReader(id);
      current.load(reader);
      reader.close();

      String typeName = current.getProperty(IAttribute.M_TYPE);
      if (typeName == null) throw new MorseException(MorseException.OBJECT_NOT_FOUND, id);

      IType type = typeProvider.get(typeName);
      if (type == null) throw new MorseException(MorseException.TYPE_NOT_FOUND, typeName);

      ObjectFileStore[] store = fileStore.get(typeName);
      if (store == null) throw new MorseException(MorseException.TYPE_NOT_FOUND, typeName);

      if (!aclManager.hasRead(user, type.getAccessAcl()))
        throw new MorseException(
            MorseException.ACCESS_DENIED_READ,
            new String[] {"type", typeName, type.getAccessAcl()});

      LinkedList<Attr> attr = new LinkedList<Attr>();
      for (Iterator<IAttribute> i = type.getAttributes(); i.hasNext(); ) {
        Attr a = new Attr();
        a.attr = i.next();
        a.attrName = a.attrAlias = a.attr.getName();
        if (aclManager.hasRead(user, a.attr.getAccessAcl())) attr.add(a);
      }

      return new FileAbstractSelectResult(
          driver,
          type,
          store[0],
          IAttribute.M_ID,
          id,
          (Attr[]) attr.toArray(new Attr[attr.size()]));

    } catch (Exception e) {
      log.error(e);
      return new ErrorResult(1, 1, e.toString());
    }
  }
示例#2
0
  public void unlock(String id, boolean force, UserInformation user) throws MorseException {

    if (log.t4()) log.info("UNLOCK: " + id + ' ' + user);

    ObjectUtil.assetId(id);
    if (!force && user == null) throw new MorseException(MorseException.UNKNOWN_USER);

    // create lock file
    ObjectFileStore ofs = driver.getFileStore().get(IType.TYPE_OBJECT)[0];

    try {
      if (log.t4()) log.debug("xLOCK: " + id + ' ' + user);
      if (!ofs.lock(id)) throw new MorseException(MorseException.ERROR);
    } catch (IOException e) {
      throw new MorseException(MorseException.ERROR, e);
    }

    try {

      IQueryResult res = fetch(id, user, false);
      if (!res.next()) {
        res.close();
        throw new MorseException(MorseException.ACCESS_DENIED, id);
      }
      String lock = res.getString(IAttribute.M_LOCK);
      res.close();

      if (!force && ObjectUtil.validateId(lock) && !lock.equals(user.getUserId())) {
        throw new MorseException(MorseException.NOT_OWNER, id);
      }

      Properties p = new Properties();
      Reader reader = ofs.getReader(id);
      p.load(reader);
      reader.close();
      p.setProperty(IAttribute.M_LOCK, "");
      Writer writer = ofs.getWriter(id);
      p.store(writer);
      writer.close();

    } catch (Exception e) {
      log.error(e);
    } finally {
      if (log.t4()) log.debug("xUNLOCK: " + id + ' ' + user);
      ofs.unlock(id);
    }
  }
示例#3
0
  private IQueryResult queryLoad(ICompiledQuery code, UserInformation user) {

    String id = code.getString(1);
    boolean shared = code.size() > 2 && code.getInteger(2) == CMql.SHARED;

    try {
      Properties current = new Properties();
      Reader reader = driver.getFileStore().get(IType.TYPE_OBJECT)[0].getReader(id);
      current.load(reader);
      reader.close();

      String typeName = current.getProperty(IAttribute.M_TYPE);
      if (typeName == null) throw new MorseException(MorseException.OBJECT_NOT_FOUND, id);

      IType type = typeProvider.get(typeName);
      if (type == null) throw new MorseException(MorseException.TYPE_NOT_FOUND, typeName);

      ObjectFileStore[] store = fileStore.get(typeName);
      if (store == null) throw new MorseException(MorseException.TYPE_NOT_FOUND, typeName);

      if (!aclManager.hasRead(user, type.getAccessAcl()))
        throw new MorseException(
            MorseException.ACCESS_DENIED_READ,
            new String[] {"type", typeName, type.getAccessAcl()});

      if (!shared) return new FileAbstractLoadResultStream(this, id, store[1]);
      else {
        return new SingleRowResult(
            new IAttribute[] {IAttributeDefault.ATTR_OBJ_STRING, IAttributeDefault.ATTR_OBJ_STRING},
            new String[] {"channel", "path"},
            new String[] {getName(), store[1].getRelativePath(id)});
      }

    } catch (Exception e) {
      log.error(e);
      return new ErrorResult(1, 1, e.toString());
    }
  }
示例#4
0
 public IQueryResult fetch(String id, UserInformation user, boolean stamp) throws MorseException {
   ObjectFileStore[] store = driver.getFileStore().get(IType.TYPE_OBJECT);
   if (store == null) throw new MorseException(MorseException.TYPE_NOT_FOUND, IType.TYPE_OBJECT);
   Reader reader = null;
   Properties prop = new Properties();
   try {
     reader = store[0].getReader(id);
     prop.load(reader);
     reader.close();
   } catch (IOException e) {
     // throw new MorseException( MorseException.ERROR, e );
     if (log.t3()) log.error(e);
     throw new MorseException(MorseException.OBJECT_NOT_FOUND, id);
   }
   if (stamp)
     return new SingleRowResult(
         new IAttribute[] {IAttributeDefault.ATTR_OBJ_INT},
         new String[] {IAttribute.M_STAMP},
         new String[] {prop.getProperty(IAttribute.M_STAMP)});
   String typeName = prop.getProperty(IAttribute.M_TYPE);
   IType type = typeProvider.get(typeName);
   if (type == null) throw new MorseException(MorseException.TYPE_NOT_FOUND, typeName);
   LinkedList<Attr> attr = new LinkedList<Attr>();
   for (Iterator<IAttribute> i = type.getAttributes(); i.hasNext(); ) {
     Attr a = new Attr();
     a.attr = i.next();
     a.attrAlias = a.attrName = a.attr.getName();
     attr.add(a);
   }
   return new FileAbstractSelectResult(
       driver,
       type,
       driver.getFileStore().get(typeName)[0],
       IAttribute.M_ID,
       id,
       attr.toArray(new Attr[attr.size()]));
 }