private Either<SubCategoryDefinition, ResponseFormat> createSubCategorieDeo(Map.Entry<String, List<CategoryDefinition>> entry, CategoryDefinition newcategory, SubCategoryDefinition subcategory, NodeTypeEnum nodeTypeSubCategory) {
log.debug("createSubCategorieDeo: creating subcategory {}", subcategory);
Either<SubCategoryDefinition, ActionStatus> createdSubCategory = elementOperation.createSubCategory(newcategory.getUniqueId(), subcategory, nodeTypeSubCategory);
+ if (createdSubCategory.isRight() && ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY == createdSubCategory.right().value()) {
+ log.debug(" create subcategory for {} category {} subcategory {} already exists, updating", entry.getKey(), newcategory.getName(), subcategory.getName());
+ String subCategoryId = UniqueIdBuilder.buildSubCategoryUid(newcategory.getUniqueId(), subcategory.getNormalizedName());
+ createdSubCategory = elementOperation.updateSubCategory(subCategoryId, subcategory, nodeTypeSubCategory);
+ }
if (createdSubCategory.isRight()) {
- if (ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY == createdSubCategory.right().value()) {
- log.debug(" create subcategory for {} category {} subcategory {} already exists retrieving", entry.getKey(), newcategory.getName(), subcategory.getName());
- String subCategoryId = UniqueIdBuilder.buildSubCategoryUid(newcategory.getUniqueId(), subcategory.getNormalizedName());
- createdSubCategory = elementOperation.getSubCategory(nodeTypeSubCategory, subCategoryId);
- if (createdSubCategory.isRight()) {
- log.debug("failed to get sub category that exists subCategoryId: {} type: {}", subCategoryId, nodeTypeSubCategory);
- return Either.right(componentsUtils.getResponseFormat(createdSubCategory.right().value()));
- }
- } else {
- log.debug("Failed to create subcategory for {} category: {} subcategory: {} error {}", entry.getKey(), newcategory.getName(), subcategory.getName(), createdSubCategory.right().value());
- return Either.right(componentsUtils.getResponseFormat(createdSubCategory.right().value()));
- }
+ log.debug("Failed to create subcategory for {} category: {} subcategory: {} error {}", entry.getKey(), newcategory.getName(), subcategory.getName(), createdSubCategory.right().value());
+ return Either.right(componentsUtils.getResponseFormat(createdSubCategory.right().value()));
} else {
log.debug("createSubCategorieDeo: create subcategory was successful {}", createdSubCategory.left().value());
}
private Either<CategoryDefinition, ResponseFormat> createCategorieDeo(Map.Entry<String, List<CategoryDefinition>> entry, CategoryDefinition category, NodeTypeEnum nodeTypeCategory) {
log.debug("createCategorieDeo: creating category {}", category);
Either<CategoryDefinition, ActionStatus> createdCategory = elementOperation.createCategory(category, nodeTypeCategory);
+ if (createdCategory.isRight() && ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS == createdCategory.right().value()) {
+ log.debug("createCategorieDeo: already exists, updating {}", category);
+ createdCategory = elementOperation.updateCategory(category, nodeTypeCategory);
+ }
+
if (createdCategory.isRight()) {
log.debug("Failed to create category for {} {} error {}", entry.getKey(), category.getName(), createdCategory.right().value());
- if (ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS != createdCategory.right().value()) {
- return Either.right(componentsUtils.getResponseFormat(createdCategory.right().value()));
- } else {
- log.debug("createCategorieDeo: category exists {} retriving.", category);
- String categoryId = UniqueIdBuilder.buildCategoryUid(category.getNormalizedName(), nodeTypeCategory);
- createdCategory = elementOperation.getCategory(nodeTypeCategory, categoryId);
- if (createdCategory.isRight()) {
- log.debug("failed to get category that exists categoryId: {} type: {}", categoryId, nodeTypeCategory);
- return Either.right(componentsUtils.getResponseFormat(createdCategory.right().value()));
- }
- }
+ return Either.right(componentsUtils.getResponseFormat(createdCategory.right().value()));
} else {
log.debug("createCategorieDeo: create category was successful {}", createdCategory.left().value());
}
// TODO Auto-generated method stub
return null;
}
+
+ @Override
+ public Either<CategoryDefinition, ActionStatus> updateCategory(CategoryDefinition category, NodeTypeEnum nodeType) {
+ // TODO Auto-generated method stub
+ return null;
+ }
@Override
public Either<CategoryDefinition, ActionStatus> deleteCategory(NodeTypeEnum nodeType, String categoryId) {
// TODO Auto-generated method stub
return null;
}
+
+ @Override
+ public Either<SubCategoryDefinition, ActionStatus> updateSubCategory(String subCategoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType) {
+ // TODO Auto-generated method stub
+ return null;
+ }
@Override
public Either<List<CategoryDefinition>, ActionStatus> getAllCategories(NodeTypeEnum nodeType, boolean inTransaction) {
// TODO Auto-generated method stub
return null;
}
+
+ @Override
+ public Either<CategoryDefinition, ActionStatus> updateCategory(CategoryDefinition category, NodeTypeEnum nodeType, boolean inTransaction) {
+ // TODO Auto-generated method stub
+ return null;
+ }
@Override
public Either<SubCategoryDefinition, ActionStatus> createSubCategory(String categoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType, boolean inTransaction) {
// TODO Auto-generated method stub
return null;
}
+
+ @Override
+ public Either<SubCategoryDefinition, ActionStatus> updateSubCategory(String subCategoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType, boolean inTransaction) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
Either<CategoryDefinition, ActionStatus> createCategory(CategoryDefinition category, NodeTypeEnum nodeType);
Either<CategoryDefinition, ActionStatus> createCategory(CategoryDefinition category, NodeTypeEnum nodeType, boolean inTransaction);
+
+ Either<CategoryDefinition, ActionStatus> updateCategory(CategoryDefinition category, NodeTypeEnum nodeType);
+
+ Either<CategoryDefinition, ActionStatus> updateCategory(CategoryDefinition category, NodeTypeEnum nodeType, boolean inTransaction);
Either<CategoryDefinition, ActionStatus> deleteCategory(NodeTypeEnum nodeType, String categoryId);
Either<SubCategoryDefinition, ActionStatus> createSubCategory(String categoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType);
Either<SubCategoryDefinition, ActionStatus> createSubCategory(String categoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType, boolean inTransaction);
+
+ Either<SubCategoryDefinition, ActionStatus> updateSubCategory(String subCategoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType);
+
+ Either<SubCategoryDefinition, ActionStatus> updateSubCategory(String subCategoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType, boolean inTransaction);
Either<List<CategoryDefinition>, ActionStatus> getAllCategories(NodeTypeEnum nodeType, boolean inTransaction);
}
}
}
+
+ @Override
+ public Either<CategoryDefinition, ActionStatus> updateCategory(CategoryDefinition category, NodeTypeEnum nodeType) {
+ return updateCategory(category, nodeType, false);
+ }
+
+ @Override
+ public Either<CategoryDefinition, ActionStatus> updateCategory(CategoryDefinition category, NodeTypeEnum nodeType, boolean inTransaction) {
+ Either<CategoryDefinition, ActionStatus> result = null;
+ category.setUniqueId(UniqueIdBuilder.buildCategoryUid(category.getNormalizedName(), nodeType));
+ CategoryData categoryData = new CategoryData(nodeType, category);
+
+ try {
+ Either<CategoryData, JanusGraphOperationStatus> updatedNode = janusGraphGenericDao
+ .updateNode(categoryData, CategoryData.class);
+ if (updatedNode.isRight()) {
+ JanusGraphOperationStatus value = updatedNode.right().value();
+ ActionStatus actionStatus = ActionStatus.GENERAL_ERROR;
+ log.debug("Problem while creating category, reason {}", value);
+ result = Either.right(actionStatus);
+ return result;
+ }
+ CategoryDefinition created = new CategoryDefinition(updatedNode.left().value().getCategoryDataDefinition());
+ result = Either.left(created);
+ return result;
+ } finally {
+ if (!inTransaction) {
+ if (result != null && result.isLeft()) {
+ janusGraphGenericDao.commit();
+ } else {
+ janusGraphGenericDao.rollback();
+ }
+ }
+ }
+ }
@Override
public Either<SubCategoryDefinition, ActionStatus> createSubCategory(String categoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType) {
CategoryDataDefinition categoryDataDefinition = categoryNode.left().value().getCategoryDataDefinition();
subCategory.setUniqueId(UniqueIdBuilder.buildSubCategoryUid(categoryDataDefinition.getUniqueId(), subCategory.getNormalizedName()));
SubCategoryData subCategoryData = new SubCategoryData(nodeType, subCategory);
-
+
Either<SubCategoryData, JanusGraphOperationStatus> subCategoryNode = janusGraphGenericDao
.createNode(subCategoryData, SubCategoryData.class);
+
if (subCategoryNode.isRight()) {
JanusGraphOperationStatus janusGraphOperationStatus = subCategoryNode.right().value();
log.debug("Problem while creating category, reason {}", janusGraphOperationStatus);
result = Either.right(actionStatus);
return result;
}
-
+
Either<GraphRelation, JanusGraphOperationStatus> relation = janusGraphGenericDao
.createRelation(categoryNode.left().value(), subCategoryNode.left().value(), GraphEdgeLabels.SUB_CATEGORY, null);
if (relation.isRight()) {
result = Either.right(actionStatus);
return result;
}
+
SubCategoryDefinition subCategoryCreated = new SubCategoryDefinition(subCategoryNode.left().value().getSubCategoryDataDefinition());
result = Either.left(subCategoryCreated);
return result;
}
}
}
+
+ @Override
+ public Either<SubCategoryDefinition, ActionStatus> updateSubCategory(String subCategoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType) {
+ return updateSubCategory(subCategoryId, subCategory, nodeType, false);
+ }
+
+ @Override
+ public Either<SubCategoryDefinition, ActionStatus> updateSubCategory(String subCategoryId, SubCategoryDefinition subCategory, NodeTypeEnum nodeType, boolean inTransaction) {
+
+ Either<SubCategoryDefinition, ActionStatus> result = null;
+ try {
+ subCategory.setUniqueId(subCategoryId);
+ SubCategoryData subCategoryData = new SubCategoryData(nodeType, subCategory);
+
+ Either<SubCategoryData, JanusGraphOperationStatus> subCategoryNode = janusGraphGenericDao
+ .updateNode(subCategoryData, SubCategoryData.class);
+
+ if (subCategoryNode.isRight()) {
+ JanusGraphOperationStatus janusGraphOperationStatus = subCategoryNode.right().value();
+ log.debug("Problem while updating sub category, reason {}", janusGraphOperationStatus);
+ result = Either.right(ActionStatus.GENERAL_ERROR);
+ return result;
+ }
+
+ SubCategoryDefinition subCategoryUpdated = new SubCategoryDefinition(subCategoryNode.left().value().getSubCategoryDataDefinition());
+ result = Either.left(subCategoryUpdated);
+ return result;
+ } finally {
+ if (!inTransaction) {
+ if (result != null && result.isLeft()) {
+ janusGraphGenericDao.commit();
+ } else {
+ janusGraphGenericDao.rollback();
+ }
+ }
+ }
+ }
@Override
public Either<GroupingDefinition, ActionStatus> createGrouping(String subCategoryId, GroupingDefinition grouping, NodeTypeEnum nodeType) {