public void saveServiceDefinition(String serviceId) { Resource serviceDefFile = getServiceDefXml(serviceId, false); Service service = getCurrentServiceDefinition(serviceId); Service oldService = null; if (serviceId.equals(CommonConstants.SALESFORCE_SERVICE)) { // For salesforceService, we need to retain service definitions in // the old service definition file. oldService = loadServiceDefinition(serviceId); if (oldService != null) { for (Operation op : oldService.getOperation()) { if (isDeletedQuery(op)) { this.cfg.removeDeletedSFQueries(op.getName()); continue; } service.addOperation(op); } List<DataObject> dataObjects = service.getDataobjects().getDataobject(); for (DataObject dobj : oldService.getDataobjects().getDataobject()) { if (isDeletedSFDataObject(dobj)) { this.cfg.removeDeletedSFDataObjects(dobj.getName()); continue; } dataObjects.add(dobj); } service.setType(oldService.getType()); service.setCRUDService(oldService.getCRUDService()); } } // salesforce try { Marshaller marshaller = definitionsContext.createMarshaller(); marshaller.setProperty("jaxb.formatted.output", true); OutputStream outputStream = this.fileSystem.getOutputStream(serviceDefFile); try { marshaller.marshal(service, outputStream); } finally { try { outputStream.close(); } catch (IOException e) { throw new IllegalStateException("Unable to close service def file", e); } } // XXX MAV-569 should do a real build here, or actually outside // this method maybe SortedSet<Service> s = new TreeSet<Service>(new ServiceComparator()); s.add(service); generateRuntimeConfiguration(s); } catch (JAXBException e) { throw new WMRuntimeException(e); } catch (IOException e) { throw new WMRuntimeException(e); } catch (NoSuchMethodException e) { throw new WMRuntimeException(e); } }
/** * Return the dataobjects specific to the specified service. * * @param serviceId * @return */ public List<DataObject> getLocalDataObjects(String serviceId) { Service service = getService(serviceId); if (service.getDataobjects() != null) { return service.getDataobjects().getDataobject(); } else { return new ArrayList<DataObject>(); } }
/** * Return data objects specific to this project's services. * * @return */ public List<DataObject> getLocalDataObjects() { Set<DataObject> ret = new HashSet<DataObject>(); Collection<Service> services = getServices(); for (Service service : services) { if (service.getDataobjects() != null) { List<DataObject> serviceObjects = service.getDataobjects().getDataobject(); ret.addAll(serviceObjects); } } return new ArrayList<DataObject>(ret); }
public DesignServiceManager() throws JAXBException, IOException { this.serviceDefinitions = new HashMap<Project, Map<String, Service>>(); Unmarshaller unmarshaller = definitionsContext.createUnmarshaller(); ClassPathResource primitiveServiceFile = new ClassPathResource("com/wavemaker/tools/service/primitive_types.xml"); InputStream inputStream = primitiveServiceFile.getInputStream(); try { Service primitiveService = (Service) unmarshaller.unmarshal(inputStream); this.primitiveTypes = Collections.unmodifiableList(primitiveService.getDataobjects().getDataobject()); Map<String, String> m = new TreeMap<String, String>(); for (DataObject o : this.primitiveTypes) { if (!o.isInternal()) { m.put(o.getName(), o.getJavaType()); } } this.primitivesMap = Collections.unmodifiableMap(m); } finally { inputStream.close(); } }
/** * Update the types associated with a given service. Currently, this will clobber all types * associated with the given service. * * @param service * @param serviceDef */ public void updateServiceTypes( Service service, ServiceDefinition serviceDef, String username, String password) { // salesforce if (service.getDataobjects() == null) { service.setDataobjects(new DataObjects()); } List<DataObject> dos = service.getDataobjects().getDataobject(); dos.clear(); List<TypeDefinition> elementTypes; if (service.getId().equals(CommonConstants.SALESFORCE_SERVICE)) { elementTypes = serviceDef.getLocalTypes(username, password); } else { elementTypes = serviceDef.getLocalTypes(); } for (TypeDefinition et : elementTypes) { // No need to check the existence of the types in other services as there is no problem if // there are two services using same dataObjects. /*if (findDataObjectFromJavaType(et.getTypeName()) != null) { throw new WMRuntimeException("Conflicting java type: " + et.getTypeName()); }*/ DataObject dso = new DataObject(); dos.add(dso); dso.setJavaType(et.getTypeName()); dso.setName(et.getShortName()); dso.setSupportsQuickData(et.isLiveService()); if (et instanceof ObjectTypeDefinition) { ObjectTypeDefinition otd = (ObjectTypeDefinition) et; List<Element> dsoelems = dso.getElement(); for (Map.Entry<String, FieldDefinition> entry : otd.getFields().entrySet()) { Element e = new Element(); dsoelems.add(e); if (0 != entry.getKey().compareTo(entry.getValue().getName())) { throw new WMRuntimeException( "key: " + entry.getKey() + " != " + entry.getValue().getName()); } // key or value.name? e.setName(entry.getKey()); if (entry.getValue().getTypeDefinition() != null) { e.setTypeRef(entry.getValue().getTypeDefinition().getTypeName()); } e.setIsList(entry.getValue().getDimensions() > 0); e.setAllowNull(entry.getValue().isAllowNull()); e.setSubType(entry.getValue().getSubType()); // salesforce for (OperationEnumeration oe : entry.getValue().getRequire()) { e.getRequire().add(oe); } for (OperationEnumeration oe : entry.getValue().getExclude()) { e.getExclude().add(oe); } for (OperationEnumeration oe : entry.getValue().getNoChange()) { e.getNoChange().add(oe); } } } } }