예제 #1
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());
 }
예제 #2
0
 /** {@inheritDoc} */
 @Override
 public void disableGroup(String groupName) {
   if (groupName == null || groupName.isEmpty()) {
     throw new IllegalArgumentException("Groupname cannot be null nor empty");
   }
   if (!existGroup(groupName)) {
     throw new GroupNotFoundException(groupName);
   }
   for (DBObject dbObject : collection.find(BUILDER.getGroupName(groupName))) {
     Object enabledd = BUILDER.getEnable(false);
     collection.update(dbObject, BasicDBObjectBuilder.start(MONGO_SET, enabledd).get());
   }
 }
예제 #3
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)));
 }
예제 #4
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());
 }
예제 #5
0
 /** {@inheritDoc} */
 @Override
 public boolean existGroup(String groupName) {
   if (groupName == null || groupName.isEmpty()) {
     throw new IllegalArgumentException("Groupname cannot be null nor empty");
   }
   return collection.count(BUILDER.getGroupName(groupName)) > 0;
 }
예제 #6
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));
 }
예제 #7
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);
 }
예제 #8
0
 /** {@inheritDoc} */
 @Override
 public Map<String, Feature> readGroup(String groupName) {
   if (groupName == null || groupName.isEmpty()) {
     throw new IllegalArgumentException("Groupname cannot be null nor empty");
   }
   if (!existGroup(groupName)) {
     throw new GroupNotFoundException(groupName);
   }
   LinkedHashMap<String, Feature> mapFP = new LinkedHashMap<String, Feature>();
   for (DBObject dbObject : collection.find(BUILDER.getGroupName(groupName))) {
     Feature feature = MAPPER.mapFeature(dbObject);
     mapFP.put(feature.getUid(), feature);
   }
   return mapFP;
 }
예제 #9
0
 /** {@inheritDoc} */
 @Override
 public boolean exist(String featId) {
   Util.assertHasLength(featId);
   return 1 == collection.count(BUILDER.getFeatUid(featId));
 }