Search in sources :

Example 11 with AttributeSequence

use of dev.hawala.xns.level4.filing.FilingCommon.AttributeSequence in project dodo by devhawala.

the class FilingImpl method open.

/*
	 * Open: PROCEDURE [ attributes: AttributeSequence, directory: Handle,
	 *                   controls: ControlSequence, session: Session ]
	 *   RETURNS [ file: Handle ]
	 *   REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
	 *             AuthenticationError, ControlTypeError, ControlValueError,
	 *             HandleError, SessionError, UndefinedError ]
	 *   = 2;
	 */
private static void open(OpenParams params, FileHandleRecord results) {
    logParams("open", params);
    // check session
    Session session = resolveSession(params.session);
    Volume vol = session.getService().getVolume();
    // check specified parent directory handle
    Handle directoryHandle = Handle.get(params.directory);
    // attributes specifying the file to open
    // - exactly one of: fileID, name, pathname
    // - optional: parentID, type, version
    int primaryAttrCount = 0;
    Long fileId = null;
    String name = null;
    String pathname = null;
    Long parentId = null;
    Long type = null;
    Integer version = null;
    AttributeSequence attrs = params.attributes;
    for (int i = 0; i < attrs.value.size(); i++) {
        Attribute av = attrs.value.get(i);
        switch((int) (av.type.get() & 0xFFFF)) {
            case FilingCommon.atFileID:
                if (primaryAttrCount == 1) {
                    new AttributeValueErrorRecord(ArgumentProblem.unreasonable, FilingCommon.atFileID).raise();
                }
                primaryAttrCount = 1;
                fileId = av.getAsFileID();
                break;
            case FilingCommon.atName:
                if (primaryAttrCount == 1) {
                    new AttributeValueErrorRecord(ArgumentProblem.unreasonable, FilingCommon.atName).raise();
                }
                primaryAttrCount = 1;
                name = av.getAsString();
                break;
            case FilingCommon.atPathname:
                if (primaryAttrCount == 1) {
                    new AttributeValueErrorRecord(ArgumentProblem.unreasonable, FilingCommon.atPathname).raise();
                }
                primaryAttrCount = 1;
                pathname = av.getAsString();
                break;
            case FilingCommon.atParentID:
                parentId = av.getAsFileID();
                break;
            case FilingCommon.atType:
                type = av.getAsLongCardinal();
                break;
            case FilingCommon.atVersion:
                version = av.getAsCardinal();
                break;
            default:
        }
    }
    // check the file specs
    if (primaryAttrCount == 0) {
        if ((directoryHandle == null || directoryHandle.isNullHandle()) && (parentId == null || parentId.longValue() == 0L)) {
            Handle rootHandle = new Handle(session, vol.rootDirectory);
            rootHandle.setIdTo(results.file);
            logResult("Open", results);
            return;
        }
        new AttributeValueErrorRecord(ArgumentProblem.missing, FilingCommon.atFileID).raise();
    }
    if (directoryHandle != null && parentId != null) {
        if (directoryHandle.isVolumeRoot()) {
            if (parentId != 0) {
                new AttributeValueErrorRecord(ArgumentProblem.unreasonable, FilingCommon.atParentID).raise();
            }
        } else {
            if (directoryHandle.getFe().getFileID() != parentId) {
                new AttributeValueErrorRecord(ArgumentProblem.unreasonable, FilingCommon.atParentID).raise();
            }
        }
    } else if (directoryHandle != null && !directoryHandle.isVolumeRoot()) {
        parentId = directoryHandle.getFe().getFileID();
    }
    FileEntry fe = null;
    if (fileId != null) {
        if (fileId == FsConstants.rootFileID) {
            fe = vol.rootDirectory;
        } else {
            fe = vol.openByFileID(fileId, parentId, type, session.getUsername());
        }
    } else if (name != null) {
        fe = vol.openByName(name, parentId, type, version, session.getUsername());
    } else if (pathname != null) {
        List<PathElement> path = PathElement.parse(pathname);
        fe = vol.openByPath(path, parentId, type, version, session.getUsername());
    }
    // check the outcome
    if (fe != null) {
        Handle newHandle = new Handle(session, fe);
        newHandle.setIdTo(results.file);
    } else {
        new AccessErrorRecord(AccessProblem.fileNotFound).raise();
    }
    logResult("Open", results);
}
Also used : AccessErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord) AttributeValueErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AttributeValueErrorRecord) Attribute(dev.hawala.xns.level4.filing.FilingCommon.Attribute) UninterpretedAttribute(dev.hawala.xns.level4.filing.fs.UninterpretedAttribute) PathElement(dev.hawala.xns.level4.filing.fs.PathElement) Volume(dev.hawala.xns.level4.filing.fs.Volume) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry) AttributeSequence(dev.hawala.xns.level4.filing.FilingCommon.AttributeSequence)

Example 12 with AttributeSequence

use of dev.hawala.xns.level4.filing.FilingCommon.AttributeSequence in project dodo by devhawala.

the class FilingImpl method store.

/*
	 * Store: PROCEDURE [ directory: Handle, attributes: AttributeSequence,
	 *                    controls: ControlSequence, content: BulkData.Source,
	 *                    session: Session ]
	 *   RETURNS [ file: Handle ]
	 *   REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
	 *             AuthenticationError, ConnectionError, ControlTypeError,
	 *             ControlValueError, HandleError, InsertionError,	SessionError,
	 *             SpaceError, TransferError, UndefinedError ]
	 *   = 12;
	 */
private static void store(StoreParams params, FileHandleRecord results) {
    logParams("store", params);
    // check session
    Session session = resolveSession(params.session);
    // check specified directory file handle
    Handle dirHandle = Handle.get(params.directory);
    if (dirHandle.isVolumeRoot()) {
        // the file system root cannot be modified
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    if (dirHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.directoryRequired).raise();
    }
    // TODO: check (access-)controls on directory
    final FileEntry fe;
    try {
        ByteContentSource source = new ByteContentSource(params.content);
        fe = createFile(null, session, dirHandle.getFe().getFileID(), params.attributes, source, null);
    } catch (EndOfMessageException e) {
        new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
        return;
    }
    // prepare results
    Handle fileHandle = new Handle(session, fe);
    fileHandle.setIdTo(results.file);
    logResult("store", results);
    // prolongate the sessions life if this took longer
    session.continueUse();
}
Also used : AccessErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord) HandleErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry) ConnectionErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord)

Example 13 with AttributeSequence

use of dev.hawala.xns.level4.filing.FilingCommon.AttributeSequence in project dodo by devhawala.

the class FilingImpl method getCourier2FileAttributeSetters.

private static List<iValueSetter> getCourier2FileAttributeSetters(AttributeSequence as) {
    List<iValueSetter> setters = new ArrayList<>();
    for (int i = 0; i < as.value.size(); i++) {
        Attribute a = as.value.get(i);
        setters.add(AttributeUtils.courier2file(a));
    }
    return setters;
}
Also used : Attribute(dev.hawala.xns.level4.filing.FilingCommon.Attribute) UninterpretedAttribute(dev.hawala.xns.level4.filing.fs.UninterpretedAttribute) ArrayList(java.util.ArrayList) dev.hawala.xns.level4.filing.fs.iValueSetter(dev.hawala.xns.level4.filing.fs.iValueSetter)

Example 14 with AttributeSequence

use of dev.hawala.xns.level4.filing.FilingCommon.AttributeSequence in project dodo by devhawala.

the class FilingImpl method move.

/*
	 * Move: PROCEDURE [ file, destinationDirectory: Handle ,
	 *                   attributes: AttributeSequence, session: Session ]
	 *   REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
	 *             AuthenticationError, HandleError, InsertionError,
	 *             SessionError, SpaceError, UndefinedError ]
	 *   = 11;
	 */
private static void move(MoveParams params, RECORD result) {
    logParams("move", params);
    // check session
    Session session = resolveSession(params.session);
    Volume vol = session.getService().getVolume();
    // check specified file handle
    Handle fileHandle = Handle.get(params.handle);
    if (fileHandle.isVolumeRoot()) {
        // the file system root cannot be copied
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    if (fileHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    FileEntry fe = fileHandle.getFe();
    if (fe.getParentID() == FsConstants.rootFileID) {
        // file system root folders cannot be moved
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    // check the destination
    Handle destinationDirHandle = Handle.get(params.destinationDirectory);
    if (destinationDirHandle.isVolumeRoot()) {
        // the file system root cannot be target
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    if (destinationDirHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    FileEntry destinationDirectory = destinationDirHandle.getFe();
    // move the file
    List<iValueSetter> attrSetters = getCourier2FileAttributeSetters(params.attributes);
    try (Volume.Session modSession = vol.startModificationSession()) {
        modSession.move(fe, destinationDirectory, attrSetters, session.getUsername());
        logResult("move", result);
    } catch (InterruptedException e) {
        new UndefinedErrorRecord(FilingCommon.UNDEFINEDERROR_CANNOT_MODIFY_VOLUME).raise();
    } catch (Exception e) {
        new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
    }
    // prolongate the sessions life if this took longer
    session.continueUse();
}
Also used : AccessErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord) HandleErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord) SpaceErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord) dev.hawala.xns.level4.filing.fs.iValueSetter(dev.hawala.xns.level4.filing.fs.iValueSetter) NoMoreWriteSpaceException(dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) IOException(java.io.IOException) CourierException(dev.hawala.xns.level3.courier.exception.CourierException) UndefinedErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord) Volume(dev.hawala.xns.level4.filing.fs.Volume) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry)

Example 15 with AttributeSequence

use of dev.hawala.xns.level4.filing.FilingCommon.AttributeSequence in project dodo by devhawala.

the class AttributeUtils method file2courier_position.

private static void file2courier_position(AttributeSequence s, FileEntry fe) {
    long position = fe.getPosition();
    Attribute attr = s.value.add();
    attr.setAsPosition(position);
}
Also used : FilterAttribute(dev.hawala.xns.level4.filing.FilingCommon.FilterAttribute) Attribute(dev.hawala.xns.level4.filing.FilingCommon.Attribute) UninterpretedAttribute(dev.hawala.xns.level4.filing.fs.UninterpretedAttribute)

Aggregations

FileEntry (dev.hawala.xns.level4.filing.fs.FileEntry)10 Attribute (dev.hawala.xns.level4.filing.FilingCommon.Attribute)8 UninterpretedAttribute (dev.hawala.xns.level4.filing.fs.UninterpretedAttribute)8 AccessErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord)7 HandleErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord)7 EndOfMessageException (dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException)6 UndefinedErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord)6 Volume (dev.hawala.xns.level4.filing.fs.Volume)6 CourierException (dev.hawala.xns.level3.courier.exception.CourierException)5 NoMoreWriteSpaceException (dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException)5 AttributeSequence (dev.hawala.xns.level4.filing.FilingCommon.AttributeSequence)5 FilterAttribute (dev.hawala.xns.level4.filing.FilingCommon.FilterAttribute)5 SpaceErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord)5 dev.hawala.xns.level4.filing.fs.iValueSetter (dev.hawala.xns.level4.filing.fs.iValueSetter)5 IOException (java.io.IOException)5 ConnectionErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord)4 dev.hawala.xns.level4.filing.fs.iValueGetter (dev.hawala.xns.level4.filing.fs.iValueGetter)4 StreamOf (dev.hawala.xns.level3.courier.StreamOf)2 AttributeValueErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.AttributeValueErrorRecord)2 ArrayList (java.util.ArrayList)2