예제 #1
0
 @Override
 public void saveWsdl(SubsystemId subsystemId, ServiceId serviceId, String wsdlString) {
   Assert.notNull(subsystemId);
   Assert.notNull(serviceId);
   Service oldService;
   // bit ugly this one, would be a little cleaner if
   // https://jira.spring.io/browse/DATAJPA-209 was resolved
   if (serviceId.getServiceVersion() == null) {
     oldService =
         serviceRepository.findActiveNullVersionByNaturalKey(
             subsystemId.getXRoadInstance(),
             subsystemId.getMemberClass(),
             subsystemId.getMemberCode(),
             subsystemId.getSubsystemCode(),
             serviceId.getServiceCode());
   } else {
     oldService =
         serviceRepository.findActiveByNaturalKey(
             subsystemId.getXRoadInstance(),
             subsystemId.getMemberClass(),
             subsystemId.getMemberCode(),
             subsystemId.getSubsystemCode(),
             serviceId.getServiceCode(),
             serviceId.getServiceVersion());
   }
   if (oldService == null) {
     throw new IllegalStateException("service " + serviceId + " not found!");
   }
   LocalDateTime now = LocalDateTime.now();
   Wsdl wsdl = new Wsdl();
   wsdl.setData(wsdlString);
   Wsdl oldWsdl = oldService.getWsdl();
   if (oldWsdl == null) {
     wsdl.initializeExternalId();
     wsdl.getStatusInfo().setTimestampsForNew(now);
     oldService.setWsdl(wsdl);
     wsdl.setService(oldService);
     wsdlRepository.save(wsdl);
   } else {
     if (oldWsdl.getStatusInfo().isRemoved()) {
       // resurrect
       oldWsdl.setData(wsdl.getData());
       oldWsdl.getStatusInfo().setChanged(now);
       oldWsdl.getStatusInfo().setRemoved(null);
       oldWsdl.getStatusInfo().setFetched(now);
     } else {
       // update existing
       boolean wsdlChanged = !oldWsdl.getData().equals(wsdl.getData());
       if (wsdlChanged) {
         oldWsdl.getStatusInfo().setChanged(now);
         oldWsdl.setData(wsdl.getData());
       }
       oldWsdl.getStatusInfo().setFetched(now);
     }
   }
 }
예제 #2
0
 @Override
 public Wsdl getWsdl(String externalId) {
   List<Wsdl> matches = wsdlRepository.findAnyByExternalId(externalId);
   if (matches.size() > 1) {
     throw new IllegalStateException("multiple matches found to " + externalId + ": " + matches);
   } else if (matches.size() == 1) {
     return matches.iterator().next();
   } else {
     return null;
   }
 }