/** * Perform the actual insertion of data into the userprofile database. * @return The object that represents the database record for this bag. * @throws ObjectStoreException If we cannot store the bag. */ protected SavedBag storeSavedBag() throws ObjectStoreException { SavedBag savedBag = new SavedBag(); savedBag.setId(getSavedBagId()); if (profileId != null) { savedBag.setName(getName()); savedBag.setType(getType()); savedBag.setDescription(getDescription()); savedBag.setDateCreated(getDateCreated()); savedBag.proxyUserProfile(new ProxyReference(null, profileId, UserProfile.class)); savedBag.setOsbId(getOsb().getBagId()); savedBag.setState(getState()); getUserProfileWriter().store(savedBag); } else if (savedBag.getId() == null) { // Even if the list is not saved because we're using an anonymous profile, still // give it an ID so that calling code can manipulate all lists by ID savedBag.setId(getUserProfileWriter().getSerial()); } return savedBag; }
/** * Loads an InterMineBag from the UserProfile database. * * @param os the production ObjectStore * @param savedBagId the ID of the bag in the userprofile database * @param uosw the ObjectStoreWriter of the userprofile database * @param classDescriptor if true the classDescriptor will be set * @throws UnknownBagTypeException if the type bag is unknown * @throws ObjectStoreException if something goes wrong */ public InterMineBag(ObjectStore os, Integer savedBagId, ObjectStoreWriter uosw, boolean classDescriptor) throws UnknownBagTypeException, ObjectStoreException { this.os = os; this.uosw = uosw; this.savedBagId = savedBagId; ObjectStore uos = uosw.getObjectStore(); SavedBag savedBag = (SavedBag) uos.getObjectById(savedBagId, SavedBag.class); checkAndSetName(savedBag.getName()); this.type = TypeUtil.unqualifiedName(savedBag.getType()); this.description = savedBag.getDescription(); this.dateCreated = savedBag.getDateCreated(); this.profileId = savedBag.proxGetUserProfile().getId(); setState(savedBag.getState()); this.osb = new ObjectStoreBag(savedBag.getOsbId()); if (classDescriptor) { setClassDescriptors(); } }
/** * Constructor with the actual objects we are trying to link. * @param bag The SavedBag we are trying to share * @param up The UserProfile we are trying to share this with. */ public UserAlreadyShareBagException(SavedBag bag, UserProfile up) { super(String.format("This bag (%s:%d) is already shared with this user (%s:%d)", bag.getName(), bag.getId(), up.getUsername(), up.getId())); } }
/** * Perform a query to retrieve a bag's backing SavedBag * @param bagName the bagName * @param dateCreated the date when the bag has been created * @return the relevant SavedBag */ public SavedBag getSavedBag(String bagName, String dateCreated) { SavedBag bag = new SavedBag(); bag.setName(bagName); bag.setDateCreated(new Date(Long.parseLong(dateCreated))); Set<String> fieldNames = new HashSet<String>(); fieldNames.add("name"); fieldNames.add("dateCreated"); try { bag = uosw.getObjectByExample(bag, fieldNames); } catch (ObjectStoreException e) { throw new RuntimeException("Unable to load user profile", e); } return bag; }
/** * Constructor callable by the ProfileManager. * @param savedBag The saved bag retrieved from the DB. * @param profileId The id of the user profile. * @param os The production object store. * @param userprofileObjectStore The userprofile object store. * @throws ObjectStoreException If there is a problem creating an ObjectStoreBag. */ protected InvalidBag(SavedBag savedBag, Integer profileId, ObjectStore os, ObjectStoreWriter userprofileObjectStore) throws ObjectStoreException { this.type = TypeUtil.unqualifiedName(savedBag.getType()); this.name = savedBag.getName(); this.description = savedBag.getDescription(); this.dateCreated = savedBag.getDateCreated(); checkArguments(os, userprofileObjectStore); this.os = os; this.osb = os.createObjectStoreBag(); this.uosw = userprofileObjectStore; this.profileId = profileId; this.savedBagId = savedBag.getId(); }
@Override public boolean equals(Object o) { return (o instanceof SavedBag && id != null) ? id.equals(((SavedBag)o).getId()) : this == o; } @Override public int hashCode() { return (id != null) ? id.hashCode() : super.hashCode(); }
/** * Delete all bags having as a type one of the classes deleted */ public void deleteBags() { Query q = new Query(); QueryClass qc = new QueryClass(SavedBag.class); q.addToSelect(qc); q.addFrom(qc); QueryField typeField = new QueryField(qc, "type"); BagConstraint constraint = new BagConstraint(typeField, ConstraintOp.IN, deletedClasses); q.setConstraint(constraint); Results bagsToDelete = uosw.execute(q, 1000, false, false, true); for (Iterator<?> i = bagsToDelete.iterator(); i.hasNext();) { ResultsRow<?> row = (ResultsRow<?>) i.next(); SavedBag savedBag = (SavedBag) row.get(0); Profile profile = pm.getProfile(savedBag.getUserProfile().getUsername()); try { profile.deleteBag(savedBag.getName()); System .out.println("Deleted the list: " + savedBag.getName() + " having type " + savedBag.getType()); } catch (ObjectStoreException ose) { System .out.println("Problems deleting bag: " + savedBag.getName()); } } }
Integer bagId = (Integer) row.get(0); SavedBag savedBag = (SavedBag) row.get(1); String bagName = savedBag.getName(); if (StringUtils.isBlank(bagName)) { LOG.warn("Failed to load bag with blank name on login for user: " LOG.warn("The bag '" + bagName + "' for user '" + userProfile.getUsername() + "'" + " with type: " + savedBag.getType() + " is not in the model. It will be saved into invalidBags" , e);
private static SharingInvite restoreFromRow( ProfileManager pm, BagManager bm, IntermediateRepresentation rep) throws ObjectStoreException { ObjectStore os = pm.getProfileObjectStoreWriter(); Profile inviter = pm.getProfile(rep.inviterId); SavedBag savedBag = (SavedBag) os.getObjectById(rep.bagId, SavedBag.class); InterMineBag bag = bm.getBag(inviter, savedBag.getName()); return new SharingInvite(bag, rep.invitee, rep.token, rep.createdAt, rep.acceptedAt, rep.accepted); }
ResultsRow row = (ResultsRow) i.next(); SavedBag savedBag = (SavedBag) row.get(0); osbids.append(savedBag.getOsbId() + ",");
/** * Constructor callable by the ProfileManager. * @param savedBag The saved bag retrieved from the DB. * @param profileId The id of the user profile. * @param os The production object store. * @param userprofileObjectStore The userprofile object store. * @throws ObjectStoreException If there is a problem creating an ObjectStoreBag. */ protected InvalidBag(SavedBag savedBag, Integer profileId, ObjectStore os, ObjectStoreWriter userprofileObjectStore) throws ObjectStoreException { this.type = TypeUtil.unqualifiedName(savedBag.getType()); this.name = savedBag.getName(); this.description = savedBag.getDescription(); this.dateCreated = savedBag.getDateCreated(); checkArguments(os, userprofileObjectStore); this.os = os; this.osb = os.createObjectStoreBag(); this.uosw = userprofileObjectStore; this.profileId = profileId; this.savedBagId = savedBag.getId(); }
/** * Constructor with the actual objects we are trying to link. * @param bag The SavedBag we are trying to share * @param up The UserProfile we are trying to share this with. */ public UserAlreadyShareBagException(SavedBag bag, UserProfile up) { super(String.format("This bag (%s:%d) is already shared with this user (%s:%d)", bag.getName(), bag.getId(), up.getUsername(), up.getId())); } }
@Override public boolean equals(Object o) { return (o instanceof SavedBag && id != null) ? id.equals(((SavedBag)o).getId()) : this == o; } @Override public int hashCode() { return (id != null) ? id.hashCode() : super.hashCode(); }
ResultsRow<?> row = (ResultsRow<?>) i.next(); SavedBag savedBag = (SavedBag) row.get(0); String type = savedBag.getType(); String newType = renamedClasses.get(type); Profile profile = pm.getProfile(savedBag.getUserProfile().getUsername()); try { if (newType != null) { profile.updateBagType(savedBag.getName(), newType); System .out.println("Updated the type of the list: " + savedBag.getName()); System .out.println("Problems updating savedBag " + savedBag.getName() + ose.getMessage()); } catch (UnknownBagTypeException e) {
/** * Perform a query to retrieve a bag's backing SavedBag * @param bagName the bagName * @param dateCreated the date when the bag has been created * @return the relevant SavedBag */ public SavedBag getSavedBag(String bagName, String dateCreated) { SavedBag bag = new SavedBag(); bag.setName(bagName); bag.setDateCreated(new Date(Long.parseLong(dateCreated))); Set<String> fieldNames = new HashSet<String>(); fieldNames.add("name"); fieldNames.add("dateCreated"); try { bag = uosw.getObjectByExample(bag, fieldNames); } catch (ObjectStoreException e) { throw new RuntimeException("Unable to load user profile", e); } return bag; }
Integer bagId = (Integer) row.get(0); SavedBag savedBag = (SavedBag) row.get(1); String bagName = savedBag.getName(); if (StringUtils.isBlank(bagName)) { LOG.warn("Failed to load bag with blank name on login for user: " LOG.warn("The bag '" + bagName + "' for user '" + userProfile.getUsername() + "'" + " with type: " + savedBag.getType() + " is not in the model. It will be saved into invalidBags" , e);
private static SharingInvite restoreFromRow( ProfileManager pm, BagManager bm, IntermediateRepresentation rep) throws ObjectStoreException { ObjectStore os = pm.getProfileObjectStoreWriter(); Profile inviter = pm.getProfile(rep.inviterId); SavedBag savedBag = (SavedBag) os.getObjectById(rep.bagId, SavedBag.class); InterMineBag bag = bm.getBag(inviter, savedBag.getName()); return new SharingInvite(bag, rep.invitee, rep.token, rep.createdAt, rep.acceptedAt, rep.accepted); }
ResultsRow row = (ResultsRow) i.next(); SavedBag savedBag = (SavedBag) row.get(0); osbids.append(savedBag.getOsbId() + ",");
/** * Perform the actual insertion of data into the userprofile database. * @return The object that represents the database record for this bag. * @throws ObjectStoreException If we cannot store the bag. */ protected SavedBag storeSavedBag() throws ObjectStoreException { SavedBag savedBag = new SavedBag(); savedBag.setId(getSavedBagId()); if (profileId != null) { savedBag.setName(getName()); savedBag.setType(getType()); savedBag.setDescription(getDescription()); savedBag.setDateCreated(getDateCreated()); savedBag.proxyUserProfile(new ProxyReference(null, profileId, UserProfile.class)); savedBag.setOsbId(getOsb().getBagId()); savedBag.setState(getState()); getUserProfileWriter().store(savedBag); } else if (savedBag.getId() == null) { // Even if the list is not saved because we're using an anonymous profile, still // give it an ID so that calling code can manipulate all lists by ID savedBag.setId(getUserProfileWriter().getSerial()); } return savedBag; }
/** * Loads an InterMineBag from the UserProfile database. * * @param os the production ObjectStore * @param savedBagId the ID of the bag in the userprofile database * @param uosw the ObjectStoreWriter of the userprofile database * @param classDescriptor if true the classDescriptor will be set * @throws UnknownBagTypeException if the type bag is unknown * @throws ObjectStoreException if something goes wrong */ public InterMineBag(ObjectStore os, Integer savedBagId, ObjectStoreWriter uosw, boolean classDescriptor) throws UnknownBagTypeException, ObjectStoreException { this.os = os; this.uosw = uosw; this.savedBagId = savedBagId; ObjectStore uos = uosw.getObjectStore(); SavedBag savedBag = (SavedBag) uos.getObjectById(savedBagId, SavedBag.class); checkAndSetName(savedBag.getName()); this.type = TypeUtil.unqualifiedName(savedBag.getType()); this.description = savedBag.getDescription(); this.dateCreated = savedBag.getDateCreated(); this.profileId = savedBag.proxGetUserProfile().getId(); setState(savedBag.getState()); this.osb = new ObjectStoreBag(savedBag.getOsbId()); if (classDescriptor) { setClassDescriptors(); } }