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