/** {@inheritDoc} */ @Override public void delete(String uid) { if (uid == null || uid.isEmpty()) { throw new IllegalArgumentException("Feature identifier cannot be null nor empty"); } if (!exist(uid)) { throw new FeatureNotFoundException(uid); } collection.remove(BUILDER.getFeatUid(uid)); }
/** * Update status of feature. * * @param uid feature id * @param enable enabler */ private void updateStatus(String uid, boolean enable) { if (uid == null || uid.isEmpty()) { throw new IllegalArgumentException("Feature identifier cannot be null nor empty"); } if (!exist(uid)) { throw new FeatureNotFoundException(uid); } DBObject target = BUILDER.getFeatUid(uid); Object enabledd = BUILDER.getEnable(enable); collection.update(target, BasicDBObjectBuilder.start(MONGO_SET, enabledd).get()); }
/** {@inheritDoc} */ @Override public Feature read(String uid) { if (uid == null || uid.isEmpty()) { throw new IllegalArgumentException("Feature identifier cannot be null nor empty"); } DBObject object = collection.findOne(BUILDER.getFeatUid(uid)); if (object == null) { throw new FeatureNotFoundException(uid); } return MAPPER.mapFeature(object); }
/** {@inheritDoc} */ @Override public void removeRoleFromFeature(String uid, String roleName) { if (uid == null || uid.isEmpty()) { throw new IllegalArgumentException("Feature identifier cannot be null nor empty"); } if (roleName == null || roleName.isEmpty()) { throw new IllegalArgumentException("roleName cannot be null nor empty"); } if (!exist(uid)) { throw new FeatureNotFoundException(uid); } collection.update( BUILDER.getFeatUid(uid), new BasicDBObject("$pull", BUILDER.getRoles(roleName))); }
/** {@inheritDoc} */ @Override public void addToGroup(String uid, String groupName) { if (uid == null || uid.isEmpty()) { throw new IllegalArgumentException("Feature identifier cannot be null nor empty"); } if (groupName == null || groupName.isEmpty()) { throw new IllegalArgumentException("Groupname cannot be null nor empty"); } if (!exist(uid)) { throw new FeatureNotFoundException(uid); } DBObject target = BUILDER.getFeatUid(uid); DBObject nGroupName = BUILDER.getGroupName(groupName); collection.update(target, BasicDBObjectBuilder.start(MONGO_SET, nGroupName).get()); }
/** {@inheritDoc} */ @Override public boolean exist(String featId) { Util.assertHasLength(featId); return 1 == collection.count(BUILDER.getFeatUid(featId)); }