/** * 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); } Document target = BUILDER.getFeatUid(uid); Object enabledd = BUILDER.getEnable(enable); collection.updateOne(target, new Document(MONGO_SET, enabledd)); }
/** {@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 (Document document : collection.find(BUILDER.getGroupName(groupName))) { Object enabled = BUILDER.getEnable(false); collection.updateOne(document, new Document(MONGO_SET, enabled)); } }
/** {@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.updateOne( BUILDER.getFeatUid(uid), new Document("$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); } Document target = BUILDER.getFeatUid(uid); Document nGroupName = BUILDER.getGroupName(groupName); collection.updateOne(target, new Document(MONGO_SET, nGroupName)); }
/** {@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; }
/** {@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.deleteOne(BUILDER.getFeatUid(uid)); }
/** {@inheritDoc} */ @Override public Feature read(String uid) { if (uid == null || uid.isEmpty()) { throw new IllegalArgumentException("Feature identifier cannot be null nor empty"); } Document object = collection.find(BUILDER.getFeatUid(uid)).first(); if (object == null) { throw new FeatureNotFoundException(uid); } return MAPPER.mapFeature(object); }
/** {@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 (Document document : collection.find(BUILDER.getGroupName(groupName))) { Feature feature = MAPPER.mapFeature(document); mapFP.put(feature.getUid(), feature); } return mapFP; }
/** {@inheritDoc} */ @Override public void update(Feature fp) { if (fp == null) { throw new IllegalArgumentException("Feature cannot be null nor empty"); } Feature fpExist = read(fp.getUid()); collection.updateOne( BUILDER.getFeatUid(fp.getUid()), new Document(MONGO_SET, MAPPER.toDocument(fp))); // enable/disable if (fp.isEnable() != fpExist.isEnable()) { if (fp.isEnable()) { enable(fp.getUid()); } else { disable(fp.getUid()); } } }
/** {@inheritDoc} */ @Override public boolean exist(String featId) { Util.assertHasLength(featId); return 1 == collection.count(BUILDER.getFeatUid(featId)); }