Search in sources :

Example 6 with AttributeSequence

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

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

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

the class FilingImpl method getAttributes.

/*
	 * GetAttributes: PROCEDURE [ file: Handle, types: AttributeTypeSequence,
	 *                            session: Session ]
	 *   RETURNS [ attributes: AttributeSequence ]
	 *   REPORTS [ AccessError, AttributeTypeError, AuthenticationError,
	 *             HandleError, SessionError, UndefinedError ]
	 *   = 8;
	 */
private static void getAttributes(GetAttributesParams params, GetAttributesResults results) {
    logParams("getAttributes", params);
    // check session
    Session session = resolveSession(params.session);
    // check specified file handle
    Handle fileHandle = Handle.get(params.handle);
    if (fileHandle == null || fileHandle.isNullHandle()) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    FileEntry fe = fileHandle.getFe();
    if (fe == null) {
        new HandleErrorRecord(HandleProblem.nullDisallowed).raise();
    }
    // transfer the requested values
    List<iValueGetter<FilingCommon.AttributeSequence>> getters = getFile2CourierAttributeGetters(params.types, session.getFilingVersion());
    for (iValueGetter<FilingCommon.AttributeSequence> getter : getters) {
        getter.access(results.attributes, fe);
    }
    // done
    logResult("getAttributes", results);
}
Also used : dev.hawala.xns.level4.filing.fs.iValueGetter(dev.hawala.xns.level4.filing.fs.iValueGetter) HandleErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.HandleErrorRecord) FileEntry(dev.hawala.xns.level4.filing.fs.FileEntry) AttributeSequence(dev.hawala.xns.level4.filing.FilingCommon.AttributeSequence)

Example 9 with AttributeSequence

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

the class FilingImpl method getFile2CourierAttributeGetters.

private static List<iValueGetter<FilingCommon.AttributeSequence>> getFile2CourierAttributeGetters(AttributeTypeSequence types, int filingVersion) {
    List<iValueGetter<FilingCommon.AttributeSequence>> getters = new ArrayList<>();
    if (types.isAllAttributeTypes()) {
        getters.add((filingVersion < 5) ? AttributeUtils::file2courier_allAttributes4 : AttributeUtils::file2courier_allAttributes5or6);
        return getters;
    }
    List<iValueGetter<AttributeSequence>> file2courierInterpreted = (filingVersion < 5) ? AttributeUtils.file2courier_interpreted4 : AttributeUtils.file2courier_interpreted5or6;
    for (int i = 0; i < types.size(); i++) {
        int attrType = (int) types.get(i).get();
        iValueGetter<FilingCommon.AttributeSequence> getter;
        if (attrType < file2courierInterpreted.size()) {
            if ((getter = file2courierInterpreted.get(attrType)) != null) {
                getters.add(getter);
            } else {
                new AttributeTypeErrorRecord(ArgumentProblem.unimplemented, attrType).raise();
            }
        } else {
            getters.add((s, fe) -> AttributeUtils.file2courier_uninterpreted(s, attrType, fe));
        }
    }
    return getters;
}
Also used : AttributeTypeErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.AttributeTypeErrorRecord) dev.hawala.xns.level4.filing.fs.iValueGetter(dev.hawala.xns.level4.filing.fs.iValueGetter) ArrayList(java.util.ArrayList) AttributeSequence(dev.hawala.xns.level4.filing.FilingCommon.AttributeSequence)

Example 10 with AttributeSequence

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

the class AttributeUtils method file2courier_accessList.

/*
	 * FileEntry => Courier
	 */
private static void file2courier_accessList(AttributeSequence s, long atCode, boolean isDefaulted, List<AccessEntry> accessEntries, boolean forFiling4) {
    AccessList acl = forFiling4 ? AccessList.make4() : AccessList.make5or6();
    acl.defaulted.set(isDefaulted);
    for (AccessEntry a : accessEntries) {
        FilingCommon.AccessEntry fa = acl.entries.add();
        fa.key.from(a.key);
        if (a.access == FsConstants.fullAccess) {
            // fa.access.add().set(AccessType.fullAccess);
            fa.access.add(AccessType.readAccess);
            fa.access.add(AccessType.writeAccess);
            fa.access.add(AccessType.ownerAccess);
            fa.access.add(AccessType.addAccess);
            fa.access.add(AccessType.removeAccess);
        } else {
            if ((a.access & FsConstants.readAccess) != 0) {
                fa.access.add(AccessType.readAccess);
            }
            if ((a.access & FsConstants.writeAccess) != 0) {
                fa.access.add(AccessType.writeAccess);
            }
            if ((a.access & FsConstants.ownerAccess) != 0) {
                fa.access.add(AccessType.ownerAccess);
            }
            if ((a.access & FsConstants.addAccess) != 0) {
                fa.access.add(AccessType.addAccess);
            }
            if ((a.access & FsConstants.removeAccess) != 0) {
                fa.access.add(AccessType.removeAccess);
            }
        }
    }
    Attribute attr = s.value.add();
    try {
        attr.encodeData(acl);
    } catch (Exception e) {
        new UndefinedErrorRecord(FilingCommon.UNDEFINEDERROR_ENCODE_ERROR).raise();
    }
    attr.type.set(atCode);
}
Also used : UndefinedErrorRecord(dev.hawala.xns.level4.filing.FilingCommon.UndefinedErrorRecord) AccessEntry(dev.hawala.xns.level4.filing.fs.AccessEntry) FilterAttribute(dev.hawala.xns.level4.filing.FilingCommon.FilterAttribute) Attribute(dev.hawala.xns.level4.filing.FilingCommon.Attribute) UninterpretedAttribute(dev.hawala.xns.level4.filing.fs.UninterpretedAttribute) AccessList(dev.hawala.xns.level4.filing.FilingCommon.AccessList)

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