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()])); }
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()); } }
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()); } }