Ejemplo n.º 1
0
 private void handleOldMember(LocalDateTime now, Member member, Member oldMember) {
   oldMember.updateWithDataFrom(member, now);
   // process subsystems for the old member
   Map<SubsystemId, Subsystem> unprocessedOldSubsystems = new HashMap<>();
   for (Subsystem subsystem : oldMember.getAllSubsystems()) {
     unprocessedOldSubsystems.put(subsystem.createKey(), subsystem);
   }
   for (Subsystem subsystem : member.getAllSubsystems()) {
     Subsystem oldSubsystem = unprocessedOldSubsystems.get(subsystem.createKey());
     if (oldSubsystem == null) {
       // brand new item, add it
       subsystem.getStatusInfo().setTimestampsForNew(now);
       subsystem.setMember(oldMember);
       oldMember.getAllSubsystems().add(subsystem);
     } else {
       oldSubsystem.getStatusInfo().setTimestampsForFetched(now);
     }
     unprocessedOldSubsystems.remove(subsystem.createKey());
   }
   // remaining old subsystems - that were not included in member.subsystems -
   // are removed (if not already)
   for (Subsystem oldToRemove : unprocessedOldSubsystems.values()) {
     StatusInfo status = oldToRemove.getStatusInfo();
     if (!status.isRemoved()) {
       status.setTimestampsForRemoved(now);
     }
   }
 }
Ejemplo n.º 2
0
 private void removeUnprocessedOldMembers(
     LocalDateTime now, Map<MemberId, Member> unprocessedOldMembers) {
   for (Member oldToRemove : unprocessedOldMembers.values()) {
     StatusInfo status = oldToRemove.getStatusInfo();
     if (!status.isRemoved()) {
       status.setTimestampsForRemoved(now);
     }
     for (Subsystem subsystem : oldToRemove.getAllSubsystems()) {
       if (!subsystem.getStatusInfo().isRemoved()) {
         subsystem.getStatusInfo().setTimestampsForRemoved(now);
       }
     }
   }
 }
Ejemplo n.º 3
0
  @Override
  public void saveServices(SubsystemId subsystemId, Collection<Service> services) {
    assert subsystemId != null;
    Subsystem oldSubsystem =
        subsystemRepository.findActiveByNaturalKey(
            subsystemId.getXRoadInstance(),
            subsystemId.getMemberClass(),
            subsystemId.getMemberCode(),
            subsystemId.getSubsystemCode());
    if (oldSubsystem == null) {
      throw new IllegalStateException("subsystem " + subsystemId + " not found!");
    }

    LocalDateTime now = LocalDateTime.now();

    Map<ServiceId, Service> unprocessedOldServices = new HashMap<>();
    oldSubsystem
        .getAllServices()
        .stream()
        .forEach(s -> unprocessedOldServices.put(s.createKey(), s));

    for (Service service : services) {
      Service oldService = unprocessedOldServices.get(service.createKey());
      if (oldService == null) {
        // brand new item, add it
        service.getStatusInfo().setTimestampsForNew(now);
        service.setSubsystem(oldSubsystem);
        oldSubsystem.getAllServices().add(service);
      } else {
        oldService.getStatusInfo().setTimestampsForFetched(now);
      }
      unprocessedOldServices.remove(service.createKey());
    }

    // now unprocessedOldServices should all be removed (either already removed, or will be now)
    for (Service oldToRemove : unprocessedOldServices.values()) {
      StatusInfo status = oldToRemove.getStatusInfo();
      if (!status.isRemoved()) {
        status.setTimestampsForRemoved(now);
      }
    }
  }