package com.stardust.easyassess.track.services;


import com.stardust.easyassess.track.dao.repositories.*;
import com.stardust.easyassess.track.models.Owner;
import com.stardust.easyassess.track.models.plan.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
@Scope("request")
public class IQCPlanGroupServiceImpl extends AbstractEntityService<IQCPlanGroup> implements IQCPlanGroupService {

    @Autowired
    private IQCPlanGroupRepository iqcPlanGroupRepository;

    @Autowired
    private IQCPlanRepository iqcPlanRepository;

    @Override
    public void updateOwnerName(Owner owner) {
        List<IQCPlanGroup> groups = iqcPlanGroupRepository.findGroupsByOwnerId(owner.getId());
        for (IQCPlanGroup group : groups) {
            group.getOwner().setName(owner.getName());
            iqcPlanGroupRepository.save(group);
        }
    }

    @Override
    protected DataRepository<IQCPlanGroup, String> getRepository() {
        return iqcPlanGroupRepository;
    }

    @Override
    public void remove(String id) {
        IQCPlanGroup group = this.get(id);
        for (IQCPlan plan : group.getPlans()) {
            iqcPlanRepository.delete(plan);
        }
        super.remove(id);
    }
}

@@ -1208,24 +1208,68 @@
 is.get(id);%0A
+        if (group.getPlans() != null) %7B%0A    
         for 
@@ -1312,24 +1312,28 @@
             
+   
+ 
 iqcPlanRepos
@@ -1352,16 +1352,30 @@
 (plan);%0A
+            %7D%0A
         

Fix NPE