Search in sources :

Example 1 with HandleErrorRecord

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

the class FilingImpl method copy.

/*
	 * Copy: PROCEDURE [ file, destinationDirectory: Handle ,
	 *                   attributes: AttributeSequence, controls: ControlSequence,
	 *                   session: Session ]
	 *   RETURNS [ newFile: Handle ]
	 *   REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
	 *             AuthenticationError, ControlTypeError, ControlValueError,
	 *             HandleError, InsertionError, SessionError, SpaceError,
	 *             UndefinedError ]
	 *   = 10;
	 */
private static void copy(CopyParams params, CopyResults results) {
    logParams("copy", 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 copied
        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();
    // copy the file and return new file
    List<iValueSetter> attrSetters = getCourier2FileAttributeSetters(params.attributes);
    try (Volume.Session modSession = vol.startModificationSession()) {
        // do the copy
        FileEntry newFe = modSession.copy(fe, destinationDirectory, attrSetters, session.getUsername());
        // prepare results
        Handle newFeHandle = new Handle(session, newFe);
        newFeHandle.setIdTo(results.newHandle);
        logResult("copy", results);
    } 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 2 with HandleErrorRecord

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

the class FilingImpl method changeAttributes.

/*
	 * ChangeAttributes: PROCEDURE [ file: Handle, attributes: AttributeSequence,
	 *                               session: Session ]
	 *   REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
	 *             AuthenticationError, HandleError, InsertionError,
	 *             SessionError, SpaceError, UndefinedError ]
	 *   = 9;
	 */
private static void changeAttributes(ChangeAttributesParams params, RECORD results) {
    logParams("changeAttributes", 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 == null || fileHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    if (fileHandle.isVolumeRoot()) {
        // the file system root cannot be modified
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    FileEntry fe = fileHandle.getFe();
    if (fe == null) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    // change attributes
    List<iValueSetter> attrSetters = getCourier2FileAttributeSetters(params.attributes);
    try (Volume.Session modSession = vol.startModificationSession()) {
        modSession.updateFileAttributes(fe, attrSetters, session.getUsername());
    } catch (InterruptedException e) {
        new UndefinedErrorRecord(FilingCommon.UNDEFINEDERROR_CANNOT_MODIFY_VOLUME).raise();
    } catch (EndOfMessageException e) {
        new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
    } catch (CourierException ce) {
        // this is a RuntimeException, why is it catch-ed by Exception ???????
        throw ce;
    } catch (Exception e1) {
        new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
    }
}
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) ConnectionErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord) 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) CourierException(dev.hawala.xns.level3.courier.exception.CourierException) Volume(dev.hawala.xns.level4.filing.fs.Volume) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry)

Example 3 with HandleErrorRecord

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

the class FilingImpl method retrieve.

/*
	 * Retrieve: PROCEDURE [ file: Handle, content: BulkData.Sink, session: Session ]
	 *   REPORTS [ AccessError, AuthenticationError, ConnectionError,
	 *             HandleError, SessionError, TransferError, UndefinedError ]
	 *   = 13;
	 */
private static void retrieve(RetrieveParams params, RECORD results) {
    logParams("retrieve", params);
    // check session
    Session session = resolveSession(params.session);
    Volume vol = session.getService().getVolume();
    // check specified file handle
    Handle fileHandle = Handle.get(params.file);
    if (fileHandle == null || fileHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    FileEntry fe = fileHandle.getFe();
    if (fe == null) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    // transfer file content
    try {
        ByteContentSink sink = new ByteContentSink(params.content);
        vol.retrieveContent(fe.getFileID(), sink, session.getUsername());
    } catch (NoMoreWriteSpaceException | IOException e) {
        log("##  Filing.Retrieve() => %s : %s\n", e.getClass().getName(), e.getMessage());
        new TransferErrorRecord(TransferProblem.aborted).raise();
    }
    // prolongate the sessions life if this took longer
    session.continueUse();
}
Also used : Volume(dev.hawala.xns.level4.filing.fs.Volume) TransferErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.TransferErrorRecord) HandleErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry) IOException(java.io.IOException) NoMoreWriteSpaceException(dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException)

Example 4 with HandleErrorRecord

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

the class FilingImpl method serialize.

/*
	 * Serialize: PROCEDURE [ file: Handle, serializedFile: BulkData.Sink,
	 *                        session: Session ]
	 *   REPORTS [ AccessError, AuthenticationError, ConnectionError,
	 *             HandleError, SessionError, TransferError, UndefinedError ]
	 *   = 15;
	 */
private static void serialize(SerializeParams params, RECORD results) {
    logParams("serialize", params);
    // check session
    Session session = resolveSession(params.session);
    // check file
    Handle fileHandle = Handle.get(params.file);
    if (fileHandle == null || fileHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    if (fileHandle.isVolumeRoot()) {
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    // prevent session timeout when processing large trees
    session.holdClosing();
    try {
        // build up the tree structure
        SerializedFile serializedFile = new SerializedFile(ws -> new SerializeTreeWireStream(ws, session), session.getFilingVersion() < 5);
        FileEntry startFe = fileHandle.getFe();
        fillSerializeData(startFe, serializedFile.file, session.getFilingVersion());
        // transfer the data
        sendBulkData("serialize", params.serializedFile, serializedFile);
    } finally {
        // restart timeout checks on the session
        session.continueUse();
    }
}
Also used : AccessErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord) SerializedFile(dev.hawala.xns.level4.filing.FilingCommon.SerializedFile) HandleErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry)

Example 5 with HandleErrorRecord

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

the class FilingImpl method create.

/*
	 * Create: PROCEDURE [ directory: Handle, attributes: AttributeSequence,
	 *                     controls: ControlSequence, session: Session ]
	 *   RETURNS [ file: Handle ]
	 *   REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
	 *             AuthenticationError, ControlTypeError, ControlValueError,
	 *             HandleError, InsertionError, SessionError, SpaceError,
	 *             UndefinedError ]
	 *   = 4;
	 */
private static void create(CreateParams params, FileHandleRecord results) {
    logParams("create", 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
    // let the file be created
    FileEntry fe = createFile(null, session, dirHandle.getFe().getFileID(), params.attributes, null, null);
    // prepare results
    Handle fileHandle = new Handle(session, fe);
    fileHandle.setIdTo(results.file);
    logResult("create", results);
    // prolongate the sessions life
    session.continueUse();
}
Also used : AccessErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord) HandleErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry)

Aggregations

HandleErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord)12 FileEntry (dev.hawala.xns.level4.filing.fs.FileEntry)9 AccessErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord)8 EndOfMessageException (dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException)6 NoMoreWriteSpaceException (dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException)6 Volume (dev.hawala.xns.level4.filing.fs.Volume)6 IOException (java.io.IOException)6 CourierException (dev.hawala.xns.level3.courier.exception.CourierException)5 SpaceErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord)5 UndefinedErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord)4 ConnectionErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord)3 dev.hawala.xns.level4.filing.fs.iValueSetter (dev.hawala.xns.level4.filing.fs.iValueSetter)3 SerializedFile (dev.hawala.xns.level4.filing.FilingCommon.SerializedFile)2 CHOICE (dev.hawala.xns.level3.courier.CHOICE)1 AccessControl (dev.hawala.xns.level4.filing.FilingCommon.AccessControl)1 AttributeSequence (dev.hawala.xns.level4.filing.FilingCommon.AttributeSequence)1 ControlType (dev.hawala.xns.level4.filing.FilingCommon.ControlType)1 LockControl (dev.hawala.xns.level4.filing.FilingCommon.LockControl)1 TimeoutControl (dev.hawala.xns.level4.filing.FilingCommon.TimeoutControl)1 TransferErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.TransferErrorRecord)1