Exemplo n.º 1
0
 /** {@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));
 }
Exemplo n.º 2
0
 /**
  * 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());
 }
Exemplo n.º 3
0
 /** {@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);
 }
Exemplo n.º 4
0
 /** {@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)));
 }
Exemplo n.º 5
0
 /** {@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());
 }
Exemplo n.º 6
0
 /** {@inheritDoc} */
 @Override
 public boolean exist(String featId) {
   Util.assertHasLength(featId);
   return 1 == collection.count(BUILDER.getFeatUid(featId));
 }