public void removeAccessibility(AccessibilityBean access, Sample sample) throws SampleException, NoAccessException { if (!isOwnerByCreatedBy(sample.getCreatedBy())) { throw new NoAccessException(); } String sampleId = sample.getId().toString(); try { super.deleteAccessibility(access, sampleId); // fully load sample sample = this.findFullyLoadedSampleByName(sample.getName()); // keep POC public // remove characterization accessibility if (sample.getCharacterizationCollection() != null) { for (Characterization achar : sample.getCharacterizationCollection()) { accessUtils.removeAccessibility(access, achar, false); } } // remove composition accessibility if (sample.getSampleComposition() != null) { accessUtils.removeAccessibility(access, sample.getSampleComposition(), false); } } catch (NoAccessException e) { throw e; } catch (Exception e) { String err = "Error in deleting the access for sample " + sampleId; logger.error(err, e); throw new SampleException(err, e); } }
public void assignAccessibility(AccessibilityBean access, Sample sample) throws SampleException, NoAccessException { if (!isOwnerByCreatedBy(sample.getCreatedBy())) { throw new NoAccessException(); } String sampleId = sample.getId().toString(); try { if (!isOwnerByCreatedBy(sample.getCreatedBy())) { throw new NoAccessException(); } // get existing accessibilities List<AccessibilityBean> groupAccesses = this.findGroupAccessibilities(sampleId); List<AccessibilityBean> userAccesses = this.findUserAccessibilities(sampleId); // if access is Public, remove all other access except Public // Curator and owner if (access.getGroupName().equals(AccessibilityBean.CSM_PUBLIC_GROUP)) { for (AccessibilityBean acc : groupAccesses) { // remove group accesses that are not public or curator if (!acc.getGroupName().equals(AccessibilityBean.CSM_PUBLIC_GROUP) && !acc.getGroupName().equals((AccessibilityBean.CSM_DATA_CURATOR))) { this.removeAccessibility(acc, sample); } } SecuredDataBean securedDataBean = new SecuredDataBean(); for (AccessibilityBean acc : userAccesses) { // remove accesses that are not owner if (!securedDataBean.retrieveUserIsOwner(acc.getUserBean(), sample.getCreatedBy())) { this.removeAccessibility(acc, sample); } } } // if sample is already public, retract from public else { if (groupAccesses.contains(AccessibilityBean.CSM_PUBLIC_ACCESS)) { this.removeAccessibility(AccessibilityBean.CSM_PUBLIC_ACCESS, sample); } } super.saveAccessibility(access, sampleId); // fully load sample sample = this.findFullyLoadedSampleByName(sample.getName()); // assign POC to public is handled when adding POC // TODO check this logic when working with COPPA on organization // assign characterization accessibility if (sample.getCharacterizationCollection() != null) { for (Characterization achar : sample.getCharacterizationCollection()) { accessUtils.assignAccessibility(access, achar); } } // assign composition accessibility if (sample.getSampleComposition() != null) { accessUtils.assignAccessibility(access, sample.getSampleComposition()); } } catch (NoAccessException e) { throw e; } catch (Exception e) { String err = "Error in assigning accessibility to the sample " + sampleId; logger.error(err, e); throw new SampleException(err, e); } }