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