/** * Updates the organisation reference and also any SubOrg links * * @param newParent * @param session */ public void setOrganisation(Organisation newParent, Session session) { log.info("setOrganisation: this=" + getOrgId()); Organisation oldParent = this.getOrganisation(); if (oldParent != null) { oldParent.getChildOrgs().remove(this); } if (newParent != null) { if (newParent.getChildOrgs() == null) { newParent.setChildOrgs(new ArrayList<Organisation>()); } newParent.getChildOrgs().add(this); } this.organisation = newParent; if (oldParent != null && oldParent != newParent) { log.info("update subs"); SubOrg.updateSubOrgs(this, SessionManager.session()); } if (oldParent != null) { session.save(oldParent); } if (newParent != null) { session.save(newParent); } session.save(this); log.info("finished move"); }
/** * Is the given entity a member of this group, regardless of organisation * * @param entity * @return */ public boolean isMember(BaseEntity entity) { Criteria crit = SessionManager.session().createCriteria(GroupMembership.class); crit.setCacheable(true); crit.add(Restrictions.eq("member", entity)); crit.add(Restrictions.eq("groupEntity", this)); boolean b = !DbUtils.toList(crit, GroupMembership.class).isEmpty(); return b; }
private RootFolder resolve(String host) { if (host.contains(":")) { host = host.substring(0, host.indexOf(":")); } System.out.println("resolve: " + host); Session session = SessionManager.session(); String primaryDomainSuffix = "." + primaryDomain; if (host.endsWith(primaryDomainSuffix)) { String subdomain = Utils.stripSuffix(host, primaryDomainSuffix); System.out.println("subdoman: " + subdomain); // If starts with admin. then look for an organisation, will go to admin console if (subdomain.startsWith("admin.")) { String orgName = Utils.stripPrefix(subdomain, "admin."); System.out.println("look for org: " + orgName); Organisation org = Organisation.findByOrgId(orgName, session); if (org != null) { System.out.println("found: " + org.getName()); return new OrganisationRootFolder(applicationManager, org); } } // otherwise, look for a website with a name that matches the subdomain Website website = Website.findByName(subdomain, session); if (website != null) { System.out.println("found website: " + website.getName()); return new WebsiteRootFolder(applicationManager, website); } } // Didnt find anything matching primary domain, so look for an exact match on website Website website = Website.findByDomainName(host, session); if (website != null) { return new WebsiteRootFolder(applicationManager, website); } // Still nothing found, so drop to root org admin console Organisation org = OrganisationDao.getRootOrg(SessionManager.session()); if (org == null) { throw new RuntimeException("No root organisation"); } System.out.println("fall through to rootorg: " + org.getOrgId()); return new OrganisationRootFolder(applicationManager, org); }
@Override public Resource getResource(String host, String sPath) throws NotAuthorizedException, BadRequestException { Path p = Path.path(sPath); if (p.getName().startsWith("alt-")) { Resource r = wrapped.getResource(host, p.getParent().toString()); if (r instanceof FileResource) { FileResource fr = (FileResource) r; String sourceHash = fr.getHash(); String formatName = p.getName().replace("alt-", ""); AltFormat f = AltFormat.find(sourceHash, formatName, SessionManager.session()); FormatSpec format = altFormatGenerator.findFormat(formatName); if (f != null) { return new AltFormatResource((FileResource) r, p.getName(), f, format); } else { log.warn( "getResource: pre-generated alt format not found: " + sourceHash + " - " + p.getName()); // if the format is valid then create a resource which will generate on demand if (format != null) { System.out.println("created resource for format: " + format); return new AltFormatResource((FileResource) r, p.getName(), format); } else { log.warn("getResource: unrecognised format: " + formatName); } return null; } } else { return null; } } else { return wrapped.getResource(host, sPath); } }
/** * Find any GroupInWebsite records for this group. This is a fairly inefficient call, so you * should probably cache results if it will be called repeatedly * * @param session * @return */ public List<GroupInWebsite> groupInWebsites(Session session) { return GroupInWebsite.findByGroup(this, SessionManager.session()); }
@Transient public long getNumMembers() { return GroupMembership.count(this, SessionManager.session()); }
/** * @param add * @return * @throws NotAuthorizedException * @throws BadRequestException */ private Profile findUserFromMailto(MailboxAddress add) throws NotAuthorizedException, BadRequestException { return Profile.findByEmail(add.toPlainAddress(), SessionManager.session()); }
@Delete public void deleteAttendeeRequest(AttendeeRequest ar) { log.info("deleteAttendeeRequest"); ar.setAcknowledged(true); // dont delete, just mark as acknowledged so will be hidden SessionManager.session().save(ar); }
public boolean isInGroup(Group group) { List<GroupMembership> list = GroupMembership.find(group, this, SessionManager.session()); return !list.isEmpty(); }
@Override public void sendContent( OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException, NotAuthorizedException, BadRequestException, NotFoundException { MediaMetaData mmd = MediaMetaData.find(rPrimary.getHash(), SessionManager.session()); if (mmd != null) { Integer durationSecs = mmd.getDurationSecs(); if (durationSecs != null) { Response resp = HttpManager.response(); if (resp != null) { System.out.println("set duration header: " + durationSecs); resp.setNonStandardHeader("X-Content-Duration", durationSecs.toString()); } } } else { System.out.println("no metadata for: " + rPrimary.getHash()); } try { boolean force = params.containsKey("force"); if (altFormat == null || force) { // hack start if (params.containsKey("args")) { List<String> args = new ArrayList<>(); for (String s : params.get("args").split(",")) { args.add(s); } String[] arr = new String[args.size()]; args.toArray(arr); formatSpec.setConverterArgs(arr); System.out.println("set args: " + arr); } // hack end System.out.println("generate: " + getName()); GenerateJob j = altFormatGenerator.getOrEnqueueJob( rPrimary.getHash(), rPrimary.getName(), formatSpec); System.out.println("got job: " + j); // Wait until the file exists int cnt = 0; System.out.println("check if exists..."); while (!j.getDestFile().exists() && !j.done()) { cnt++; System.out.println( "sleep..." + cnt + " .. " + j.getDestFile().exists() + " - " + j.done()); doSleep(cnt++, 200, 70); } System.out.println("finished sleepy check"); if (!j.getDestFile().exists()) { throw new RuntimeException( "Job did not create a destination file: " + j.getDestFile().getAbsolutePath()); } System.out.println( "use dest file: " + j.getDestFile().getAbsolutePath() + " size: " + j.getDestFile().length()); FileInputStream fin = new FileInputStream(j.getDestFile()); byte[] buf = new byte[1024]; System.out.println("send file..."); // Read the file until the job is done, or we run out of bytes int s = fin.read(buf); System.out.println("send file... " + s); long bytes = 0; while (!j.done() || s > 0) { if (s < 0) { // no bytes available, but job is not done, so wait System.out.println("sleep..."); doSleep(100); } else { System.out.println("write bytes: " + s); bytes += s; out.write(buf, 0, s); } s = fin.read(buf); } System.out.println("finished sending file: " + bytes); } else { System.out.println("using pre-existing al-format"); Combiner combiner = new Combiner(); List<String> fanoutCrcs = getFanout().getHashes(); combiner.combine(fanoutCrcs, hashStore, blobStore, out); out.flush(); } } catch (Throwable e) { log.error("Exception sending content", e); throw new IOException("Exception sending content"); } }
/** * Get all linked memberships. Uses SessionManager.session * * @return */ @Transient public List<GroupMembership> getMembers() { return GroupMembership.find(this, SessionManager.session()); }