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(); } }
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 DataObject with a javaType as specified, or null if no DataObject was found in this * project. * * @param javaType The javaType to search for. * @return */ public DataObject findDataObjectFromJavaType(String javaType) { for (DataObject dataobject : getLocalDataObjects()) { if (dataobject.getJavaType().equals(javaType)) { return dataobject; } } return null; }
/** * Get a list of service types that belong to any service except for the one specified in the * argument. * * @param serviceId * @return */ public List<String> getExcludeTypeNames(String serviceId) { List<String> excludeTypeNames = new ArrayList<String>(); Collection<String> serviceIds = getServiceIds(); for (String id : serviceIds) { if (serviceId.equals(id)) { // ignore this services' types } else { List<DataObject> dos = getLocalDataObjects(id); for (DataObject d : dos) { excludeTypeNames.add(d.getJavaType()); } } } return excludeTypeNames; }
private boolean isDeletedSFDataObject(DataObject obj) { // salesforce Collection<String> deletedSFDataObjects = this.cfg.getDeletedSFDataObjects(); for (String name : deletedSFDataObjects) { String src = StringUtils.classNameToSrcFilePath(obj.getJavaType()); if (src.equals(name)) { return true; } } return false; }
/** * 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); } } } } }