use of dev.hawala.xns.level4.filing.fs.UninterpretedAttribute in project dodo by devhawala.
the class FileEntryTests method testFeAttributes.
@Test
public void testFeAttributes() {
FileEntry fe = new FileEntry(2033, 255, true, "test complex FileEntry", 1, 0, "complex:dev:hawala");
fe.setAccessListDefaulted(false);
fe.getAccessList().add(new AccessEntry("user1:dev:hawala", FsConstants.fullAccess));
fe.getAccessList().add(new AccessEntry("*:sys:tu-berlin", FsConstants.readAccess));
fe.setDefaultAccessListDefaulted(false);
fe.getDefaultAccessList().add(new AccessEntry("user2:dev:hawala", FsConstants.readAccess | FsConstants.writeAccess));
fe.getDefaultAccessList().add(new AccessEntry("userX:zrz:tu-berlin", FsConstants.ownerAccess));
fe.getUninterpretedAttributes().add(new UninterpretedAttribute(4433).add(0xFFFF).add(0).add(0x1234));
fe.getUninterpretedAttributes().add(new UninterpretedAttribute(1122).add(0).add(0x4321).add(0xFFFF).add(0xFFFF));
fe.setType(FsConstants.tDirectory);
fe.setChecksum(0xFEDC);
fe.setDataSize(4567);
fe.setReadBy("user1:dev:hawala");
fe.setReadOn(0x4255);
fe.setModifiedBy("userX:zrz:tu-berlin");
fe.setModifiedOn(0x4242);
fe.setChildrenUniquelyNamed(false);
// createdOn
fe.setOrderingKey(3);
fe.setOrderingAscending(false);
fe.setOrderingInterpretation(FsConstants.intrTime);
System.out.println();
System.out.println(fe.toString());
FileEntry result = outIn(fe);
System.out.println(result.toString());
assertEquals("fe -> outIn() -> result", fe.toString(), result.toString());
}
use of dev.hawala.xns.level4.filing.fs.UninterpretedAttribute in project dodo by devhawala.
the class MailService method postMail.
/**
* Create a new mail posted to one or more recipients.
*
* @param sender the user sending the mail
* @param recipients list of already verified recipients of the mail, having
* groups (aka distribution-lists) already expanded
* @param contentsType the type id for the mail content
* @param source the filing source for the mail content
* @return the mail identification for the created mail
*/
public int[] postMail(ThreePartName sender, NameList recipients, long contentsType, iContentSource source) {
try (Session fSession = this.mailsVolume.startModificationSession()) {
// get the next free mail-id
int[] mailId = this.allocateMailId(fSession);
String mailFileName = String.format("%08X-%04X-%04X", System.currentTimeMillis(), mailId[3], mailId[4]);
// create the meta-data for the mail content file
MailMetaData postedMetaData = new MailMetaData();
postedMetaData.sender.from(sender);
for (int i = 0; i < recipients.size(); i++) {
postedMetaData.recipients.add(recipients.get(i));
}
postedMetaData.contentsType.set(contentsType);
postedMetaData.mailboxReferences.set(recipients.size());
UninterpretedAttribute postedMetaDataAttr = new UninterpretedAttribute(atPostedMetaData);
postedMetaData.to(postedMetaDataAttr);
// create the mail content file
FileEntry mailFile = fSession.createFile(// . parentId
mailfilesFolder.getFileID(), // ....................... isDirectory
false, // ................ name
mailFileName, // ........................... version
1, // .................. type
ftMailFile, // ......... creatingUser
this.serviceNameFqn, Arrays.asList(fe -> fe.getUninterpretedAttributes().add(postedMetaDataAttr)), source);
// create the envelope
EncodedList env = EncodedList.make();
env.add(Attribute.make().set(MailingCommon.atMtPostmark, Postmark::make, a -> {
a.server.from(this.chsDatabase.getMailServiceFqn());
a.time.fromUnixMillisecs(System.currentTimeMillis());
}));
env.add(Attribute.make().set(MailingCommon.atMtMessageID, MessageID::make, a -> {
for (int i = 0; i < mailId.length; i++) {
a.get(i).set(mailId[i]);
}
}));
env.add(Attribute.make().setAsLongCardinal(MailingCommon.atMtContentsType, contentsType));
env.add(Attribute.make().setAsLongCardinal(MailingCommon.atMtContentsSize, mailFile.getDataSize()));
env.add(Attribute.make().setAsChsName(MailingCommon.atMtOriginator, sender));
env.add(Attribute.make().setAsChsName(MailingCommon.atMtReturnToName, sender));
ValueContentSource envelopeSource = new ValueContentSource(env);
// create the inbox-references in the mailboxes of all recipients
String inboxMailFileName = mailFileName + INBOX_SUFFIX_NEW;
for (int i = 0; i < recipients.size(); i++) {
Name rcpt = recipients.get(i);
FileEntry mailbox = this.mailboxes.get(rcpt.getLcFqn());
// should never happen...
if (mailbox == null) {
continue;
}
fSession.createFile(// ......... parentId
mailbox.getFileID(), // ....................... isDirectory
false, // ........... name
inboxMailFileName, // ........................... version
1, // ................. type
ftInboxMail, // ......... creatingUser
this.serviceNameFqn, Collections.emptyList(), envelopeSource.reset());
}
// done
return mailId;
} catch (IllegalStateException e) {
Log.C.printf("MS", "postMail() -> rejecting with ServiceError[serviceUnavailable], cause: %s\n", e.getMessage());
new ServiceErrorRecord(ServiceProblem.serviceUnavailable).raise();
} catch (InterruptedException e) {
Log.C.printf("MS", "postMail() -> rejecting with ServiceError[serviceUnavailable], cause: %s\n", e.getMessage());
new ServiceErrorRecord(ServiceProblem.serviceUnavailable).raise();
} catch (Exception e) {
Log.C.printf("MS", "postMail() -> rejecting with ServiceError[serviceUnavailable], cause: %s\n", e.getMessage());
new ServiceErrorRecord(ServiceProblem.serviceUnavailable).raise();
}
// keep the compiler happy (errors raised do not return)
return null;
}
use of dev.hawala.xns.level4.filing.fs.UninterpretedAttribute in project dodo by devhawala.
the class MailService method dropMail.
/**
* Delete the given mail in the given mail session.
*
* @param session the mail session for the mailbox where the mail is located
* @param mail the mail to be deleted
* @return {@code null} if deleting the mail in the mailbox was successful,
* otherwise the Courier error holding the problem to report to the client
*/
public synchronized ErrorRECORD dropMail(MailSession session, MailboxEntry mail) {
/*
* 1. in all other sessions for the same mailbox: .resetInboxEntry() for the same postboxId
* 2. delete the mailbox-file in this session
* 3. possibly delete the contentFile if the last mailbox-file referencing it was deleted
*/
// check if this mailbox-entry was already deleted (possibly in a different session)
FileEntry mailFile = mail.inboxEntry();
if (mailFile == null) {
// already deleted, not an error
return null;
}
// in all other sessions for the same mailbox: .resetInboxEntry() for the same postboxId
String mailboxName = session.getUserLcFqn();
String mailId = mail.postboxId();
for (MailSession candidate : this.activeSessions.values()) {
if (candidate == session) {
continue;
}
if (candidate.getUserLcFqn().equals(mailboxName)) {
continue;
}
for (int i = 0; i < candidate.getMailCount(); i++) {
MailboxEntry me = candidate.getMailEntry(i);
if (me.isMail(mailId)) {
me.resetInboxEntry();
continue;
}
}
}
// delete the file and possibly the contentFile
List<FileEntry> contentFiles = this.mailsVolume.findFiles(this.mailfilesFolder.getFileID(), f -> mailId.equalsIgnoreCase(f.getName()), // maxCount,
1, // maxDepth,
1, this.serviceNameFqn);
if (contentFiles.size() != 1) {
// there is nothing appropriate...
return new ServiceErrorRecord(ServiceProblem.serviceUnavailable);
}
FileEntry contentFile = contentFiles.get(0);
// get the meta-data for the mail content file
UninterpretedAttribute postedMetaDataAttr = contentFile.getUninterpretedAttribute(atPostedMetaData);
MailMetaData postedMetaData = MetaData.from(postedMetaDataAttr, MailMetaData::make);
// check if the posted mail has also to be deleted
int refCount = postedMetaData.mailboxReferences.get() - 1;
boolean deletePostedMail = (refCount < 1);
// drop resp. modify the file(s)
try (Session fSession = this.mailsVolume.startModificationSession()) {
if (deletePostedMail) {
fSession.deleteFile(contentFile, this.serviceNameFqn);
} else {
postedMetaData.mailboxReferences.set(refCount);
postedMetaData.to(postedMetaDataAttr);
fSession.updateFileAttributes(contentFile, Arrays.asList(fe -> {
}), this.serviceNameFqn);
}
fSession.deleteFile(mailFile, this.serviceNameFqn);
} catch (IllegalStateException e) {
Log.C.printf("MS", "dropMail() -> rejecting with ServiceError[serviceUnavailable], cause: %s\n", e.getMessage());
return new ServiceErrorRecord(ServiceProblem.serviceUnavailable);
} catch (InterruptedException e) {
Log.C.printf("MS", "dropMail() -> rejecting with ServiceError[serviceUnavailable], cause: %s\n", e.getMessage());
return new ServiceErrorRecord(ServiceProblem.serviceUnavailable);
} catch (Exception e) {
Log.C.printf("MS", "dropMail() -> rejecting with ServiceError[serviceUnavailable], cause: %s\n", e.getMessage());
return new ServiceErrorRecord(ServiceProblem.serviceUnavailable);
}
// successful
return null;
}
use of dev.hawala.xns.level4.filing.fs.UninterpretedAttribute in project dodo by devhawala.
the class MailService method allocateMailId.
/**
* Allocate a new mail-id for this mail-service by updating
* the file attribute on the mailfiles folder, where the
* last mail-id is persisted.
*
* @param session the Filing(!) session for saving the newly allocated id
* @return the 5 words holding the new file-id
*/
private int[] allocateMailId(Session session) {
// get the last mail-id
UninterpretedAttribute attr = this.mailfilesFolder.getUninterpretedAttribute(atLastMailId);
if (attr == null) {
throw new IllegalStateException("unable to allocate new mail-id: (null last-mail-id attribute)");
}
int[] mailId = new int[] { attr.get(0) & 0xFFFF, attr.get(1) & 0xFFFF, attr.get(2) & 0xFFFF, attr.get(3) & 0xFFFF, attr.get(4) & 0xFFFF };
// increment the running counter
long newId = ((mailId[3] << 16) | mailId[4]) + 1;
mailId[3] = (int) ((newId >> 16) & 0xFFFFL);
mailId[4] = (int) (newId & 0xFFFFL);
// update the mailfiles folder
try {
session.updateFileAttributes(this.mailfilesFolder, Arrays.asList(fe -> {
attr.clear().add(mailId[0]).add(mailId[1]).add(mailId[2]).add(mailId[3]).add(mailId[4]);
}), this.serviceNameFqn);
} catch (Exception e) {
throw new IllegalStateException("unable to allocate new mail-id: " + e.getMessage());
}
// done
return mailId;
}
use of dev.hawala.xns.level4.filing.fs.UninterpretedAttribute in project dodo by devhawala.
the class AttributeUtils method file2courier_uninterpreted.
public static void file2courier_uninterpreted(AttributeSequence s, long atCode, FileEntry fe) {
UninterpretedAttribute a = fe.getUninterpretedAttribute(atCode);
Attribute attr = s.value.add();
attr.type.set(atCode);
if (a == null) {
return;
}
for (int i = 0; i < a.size(); i++) {
attr.value.add().set(a.get(i));
}
}
Aggregations