Search in sources :

Example 1 with SpaceErrorRecord

use of dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord 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 SpaceErrorRecord

use of dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord 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 SpaceErrorRecord

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

the class FilingImpl method createFile.

private static FileEntry createFile(Volume.Session modificationSession, Session session, long directoryFileID, AttributeSequence pAttributes, iContentSource source, ExceptionHandler exceptionHandler) {
    // get the volume
    Volume vol = session.getService().getVolume();
    // extract the minimal attributes => required: name ; optional: isDirectory(false), version(1/next), type(unknown)
    String name = null;
    boolean isDirectory = false;
    Integer version = null;
    Long type = null;
    for (int i = 0; i < pAttributes.value.size(); i++) {
        Attribute attr = pAttributes.value.get(i);
        switch((int) (attr.type.get() & 0xFFFF)) {
            case FilingCommon.atName:
                name = attr.getAsString();
                break;
            case FilingCommon.atIsDirectory:
                isDirectory = attr.getAsBoolean();
                break;
            case FilingCommon.atVersion:
                version = attr.getAsCardinal();
                break;
            case FilingCommon.atType:
                type = attr.getAsLongCardinal();
                break;
        }
    }
    if (name == null) {
        new AttributeValueErrorRecord(ArgumentProblem.missing, FilingCommon.atName).raise();
    }
    // create the new file
    List<iValueSetter> attrSetters = getCourier2FileAttributeSetters(pAttributes);
    System.out.printf("volStartModificationsession()\n");
    try {
        System.out.printf("createFile( dirId = %d , isdirectory = %s , name = '%s' )\n", directoryFileID, "" + isDirectory, name);
        Volume.Session modSession = (modificationSession == null) ? vol.startModificationSession() : modificationSession;
        final FileEntry fe;
        try {
            fe = modSession.createFile(directoryFileID, isDirectory, name, version, type, session.getUsername(), attrSetters, source);
        } finally {
            if (modificationSession == null) {
                modSession.close();
            }
        }
        System.out.printf("-> done createFile(): fileID = %d\n", (fe != null) ? fe.getFileID() : -2);
        return fe;
    } catch (InterruptedException e) {
        System.out.printf("!!! InterruptedException !!!\n");
        new UndefinedErrorRecord(FilingCommon.UNDEFINEDERROR_CANNOT_MODIFY_VOLUME).raise();
    } catch (EndOfMessageException e) {
        System.out.printf("!!! EndOfMessageException !!!\n");
        new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
    } catch (CourierException ce) {
        // this is a RuntimeException, why is it catch-ed by Exception ???????
        System.out.printf("!!! CourierException !!!\n");
        throw ce;
    } catch (Exception e) {
        System.out.printf("!!! Exception: %s -- %s !!!\n", e.getClass().getName(), e.getMessage());
        if (exceptionHandler != null) {
            exceptionHandler.accept(e);
        } else {
            new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
        }
    }
    // keep the compiler happy
    return null;
}
Also used : AttributeValueErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AttributeValueErrorRecord) Attribute(dev.hawala.xns.level4.filing.FilingCommon.Attribute) UninterpretedAttribute(dev.hawala.xns.level4.filing.fs.UninterpretedAttribute) 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 4 with SpaceErrorRecord

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

the class FilingImpl method deserialize.

/*
	 * Deserialize: PROCEDURE [ directory: Handle, attributes: AttributeSequence,
	 *                          controls: ControlSequence, serializedFile: BulkData.Source,
	 *                          session: Session ]
	 *   RETURNS [ file: Handle ]
	 *   REPORTS [ AccessError, AttributeTypeError, AttributeValueError,
	 *             AuthenticationError, ConnectionError, ControlTypeError,
	 *             ControlValueError, HandleError, InsertionError,
	 *             SessionError, SpaceError, TransferError, UndefinedError ]
	 *   = 16;
	 */
private static void deserialize(DeserializeParams params, FileHandleRecord results) {
    logParams("deserialize", params);
    // check session
    Session session = resolveSession(params.session);
    // check directory
    Handle dirHandle = Handle.get(params.directory);
    if (dirHandle == null || dirHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    if (dirHandle.isVolumeRoot()) {
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    // prevent session timeout when processing large trees
    session.holdClosing();
    // do the transfer and deserialization
    try (Volume.Session modSession = session.getService().getVolume().startModificationSession()) {
        SerializedFile deserializedFile = new SerializedFile(ws -> new DeserializeTreeWireStream(ws, dirHandle.getFe().getFileID(), session, results, modSession), false);
        params.serializedFile.receive(deserializedFile);
    } catch (EndOfMessageException e) {
        new ConnectionErrorRecord(ConnectionProblem.otherCallProblem).raise();
    } catch (Exception e) {
        System.out.printf("!!! Exception: %s -- %s !!!\n", e.getClass().getName(), e.getMessage());
        new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
    } finally {
        // restart timeout checks on the session
        session.continueUse();
    }
}
Also used : AccessErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord) Volume(dev.hawala.xns.level4.filing.fs.Volume) SerializedFile(dev.hawala.xns.level4.filing.FilingCommon.SerializedFile) HandleErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord) EndOfMessageException(dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException) SpaceErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord) 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)

Example 5 with SpaceErrorRecord

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

the class FilingImpl method delete.

/*
	 * Delete: PROCEDURE [ file: Handle, session: Session ]
	 *   REPORTS [ AccessError, AuthenticationError, HandleError, SessionError, UndefinedError ]
	 *   = 5;
	 */
private static void delete(FileHandleAndSessionRecord params, RECORD results) {
    logParams("delete", params);
    // check session
    Session session = resolveSession(params.session);
    // check specified file handle
    Handle fileHandle = Handle.get(params.handle);
    if (fileHandle.isVolumeRoot()) {
        // the file system root cannot be deleted
        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 deleted
        new AccessErrorRecord(AccessProblem.accessRightsInsufficient).raise();
    }
    // so delete the file (including the subtree if this is a directory!)
    try (Volume.Session modSession = session.getService().getVolume().startModificationSession()) {
        modSession.deleteFile(fe, session.getUsername());
    } catch (InterruptedException e) {
        System.out.printf("!!! InterruptedException !!!\n");
        new UndefinedErrorRecord(FilingCommon.UNDEFINEDERROR_CANNOT_MODIFY_VOLUME).raise();
    } catch (CourierException ce) {
        // this is a RuntimeException, why is it catch-ed by Exception ???????
        System.out.printf("!!! CourierException !!!\n");
        throw ce;
    } catch (Exception e) {
        System.out.printf("!!! Exception: %s -- %s !!!\n", e.getClass().getName(), e.getMessage());
        new SpaceErrorRecord(SpaceProblem.mediumFull).raise();
    }
    // prolongate the sessions life if this took longer
    session.continueUse();
}
Also used : UndefinedErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord) AccessErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord) CourierException(dev.hawala.xns.level3.courier.exception.CourierException) Volume(dev.hawala.xns.level4.filing.fs.Volume) HandleErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord) SpaceErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry) 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)

Aggregations

CourierException (dev.hawala.xns.level3.courier.exception.CourierException)6 EndOfMessageException (dev.hawala.xns.level3.courier.iWireStream.EndOfMessageException)6 NoMoreWriteSpaceException (dev.hawala.xns.level3.courier.iWireStream.NoMoreWriteSpaceException)6 SpaceErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.SpaceErrorRecord)6 Volume (dev.hawala.xns.level4.filing.fs.Volume)6 IOException (java.io.IOException)6 AccessErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.AccessErrorRecord)5 HandleErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord)5 UndefinedErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord)5 FileEntry (dev.hawala.xns.level4.filing.fs.FileEntry)5 dev.hawala.xns.level4.filing.fs.iValueSetter (dev.hawala.xns.level4.filing.fs.iValueSetter)4 ConnectionErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.ConnectionErrorRecord)3 Attribute (dev.hawala.xns.level4.filing.FilingCommon.Attribute)1 AttributeValueErrorRecord (dev.hawala.xns.level4.filing.FilingCommon.AttributeValueErrorRecord)1 SerializedFile (dev.hawala.xns.level4.filing.FilingCommon.SerializedFile)1 UninterpretedAttribute (dev.hawala.xns.level4.filing.fs.UninterpretedAttribute)1