├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── install.baratine ├── logging.properties └── src ├── main ├── java │ └── examples │ │ └── auction │ │ ├── AbstractAuctionSession.java │ │ ├── Auction.java │ │ ├── AuctionAbstractVault.java │ │ ├── AuctionAdminSession.java │ │ ├── AuctionAdminSessionImpl.java │ │ ├── AuctionBid.java │ │ ├── AuctionData.java │ │ ├── AuctionDataInit.java │ │ ├── AuctionEvents.java │ │ ├── AuctionImpl.java │ │ ├── AuctionSession.java │ │ ├── AuctionSettlement.java │ │ ├── AuctionSettlementImpl.java │ │ ├── AuctionSettlementVault.java │ │ ├── AuctionUserSession.java │ │ ├── AuctionUserSessionImpl.java │ │ ├── AuctionVault.java │ │ ├── AuditService.java │ │ ├── AuditServiceImpl.java │ │ ├── CreditCard.java │ │ ├── Main.java │ │ ├── PayPal.java │ │ ├── PayPalAuth.java │ │ ├── PayPalImpl.java │ │ ├── PayPalRestLink.java │ │ ├── Payment.java │ │ ├── PaymentImpl.java │ │ ├── Refund.java │ │ ├── RefundImpl.java │ │ ├── SettlementTransactionState.java │ │ ├── User.java │ │ ├── UserAbstractVault.java │ │ ├── UserData.java │ │ ├── UserImpl.java │ │ └── UserVault.java └── resources │ ├── payment.template.json │ ├── paypal.properties.template │ └── web │ ├── app │ ├── admin-main.js │ ├── admin-main.js.map │ ├── admin-main.ts │ ├── app.component.css │ ├── app.component.js │ ├── app.component.js.map │ ├── app.component.ts │ ├── auction-admin.component.html │ ├── auction-admin.component.js │ ├── auction-admin.component.js.map │ ├── auction-admin.component.ts │ ├── auction.js │ ├── auction.js.map │ ├── auction.service.js │ ├── auction.service.js.map │ ├── auction.service.ts │ ├── auction.ts │ ├── auctions.component.html │ ├── auctions.component.js │ ├── auctions.component.js.map │ ├── auctions.component.ts │ ├── baseurl.js │ ├── baseurl.js.map │ ├── baseurl.ts │ ├── bids.component.html │ ├── bids.component.js │ ├── bids.component.js.map │ ├── bids.component.ts │ ├── login.component.html │ ├── login.component.js │ ├── login.component.js.map │ ├── login.component.ts │ ├── new-auction.component.html │ ├── new-auction.component.js │ ├── new-auction.component.js.map │ ├── new-auction.component.ts │ ├── user-main.js │ ├── user-main.js.map │ ├── user-main.ts │ ├── user.js │ ├── user.js.map │ ├── user.service.js │ ├── user.service.js.map │ ├── user.service.ts │ └── user.ts │ ├── bootstrap.min.css │ ├── index-admin.html │ ├── index.html │ ├── js │ ├── Rx.js │ ├── angular2-polyfills.js │ ├── angular2.dev.js │ ├── es6-shim.min.js │ ├── http.dev.js │ ├── router.dev.js │ ├── system-polyfills.js │ └── system.src.js │ ├── package.json │ ├── styles.css │ ├── tsconfig.json │ └── typings.json └── test └── java └── examples └── auction ├── AuctionReplayTest.java ├── AuctionSettleRejectAuctionTest.java ├── AuctionSettleRejectUserTest.java ├── AuctionSettleResumeTest.java ├── AuctionSettleRollbackTest.java ├── AuctionSettleTest.java ├── AuctionSettlementEnsureTest.java ├── AuctionSettlementSync.java ├── AuctionSync.java ├── AuctionTest.java ├── AuctionUserSessionWebTest.java ├── AuctionVaultSync.java ├── PayPalSync.java ├── UserReplayTest.java ├── UserSync.java ├── UserTest.java ├── UserVaultSync.java └── mock ├── MockPayPal.java ├── MockPayment.java └── MockRefund.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | .idea 4 | 5 | # Mobile Tools for Java (J2ME) 6 | .mtj.tmp/ 7 | 8 | # Package Files # 9 | *.jar 10 | *.war 11 | *.ear 12 | 13 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 14 | hs_err_pid* 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Baratine™ Auction 2 | 3 | *** 4 | 5 | ##### Auction application demonstrates how to use Baratine™ to build a Single Page Web Application. 6 | 7 | The application uses the following Baratine provided services 8 | * DatabaseService 9 | * Store (key - value) 10 | * Timer 11 | * Event 12 | * WebSocket 13 | 14 | ##### The main interfaces are 15 | 16 | Java: 17 | 18 | * AuctionSession, AuctionUserSession, AuctionAdminSession 19 | * User 20 | * UserVault 21 | * Auction 22 | * AuctionVault 23 | * WebAuctionUpdates 24 | 25 | HTML, JavaScript: 26 | * index.html 27 | 28 | ##### The main classes are 29 | 30 | Java: 31 | 32 | * AbstractAuctionSession, AuctionUserSessionImpl - implements a user session; invoked by the UI (index.html) 33 | * UserImpl - implements User; manages UserDataPublic class which contains user detail 34 | * UserVault - creates and manages users 35 | * AuctionImpl - implements Auction; manages AuctionDataPublic class which contains Auction detail 36 | * AuctionVault - creates and manages auctions 37 | 38 | ##### Building the Auction application 39 | 40 | ##### Running the Auction application 41 | 42 | execute `gradle clean jar run` 43 | 44 | For additional documentaton on Baratine™ visit [Baratine Home] 45 | [Baratine Home]: http://baratine.io 46 | 47 | 48 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'application' 2 | apply plugin: 'java' 3 | 4 | mainClassName = 'examples.auction.Main' 5 | 6 | repositories { 7 | mavenLocal(); 8 | mavenCentral(); 9 | } 10 | 11 | configurations { 12 | provided 13 | compile.extendsFrom provided 14 | } 15 | 16 | sourceSets { 17 | main { 18 | resources { 19 | srcDir 'src/main/resources' 20 | } 21 | } 22 | } 23 | 24 | sourceSets.main.resources.exclude 'web/node_modules/**'; 25 | sourceSets.main.resources.exclude 'web/typings/**'; 26 | 27 | dependencies { 28 | compile 'io.baratine:baratine:1.0.1'; 29 | compile 'javax.json:javax.json-api:1.0'; 30 | compile 'org.glassfish:javax.json:1.0.4'; 31 | 32 | testCompile 'junit:junit:4.12' 33 | } 34 | 35 | jar { 36 | dependsOn configurations.compile 37 | } 38 | 39 | task wrapper(type: Wrapper) { 40 | gradleVersion = '2.11' 41 | } 42 | -------------------------------------------------------------------------------- /install.baratine: -------------------------------------------------------------------------------- 1 | mvn install:install-file -Dfile=/Users/alex/projects/caucho/5.0/baratine/build/libs/baratine-0.11-SNAPSHOT.jar -DgroupId=io.baratine -DartifactId=baratine -Dversion=0.11.4 -Dpackaging=jar 2 | -------------------------------------------------------------------------------- /logging.properties: -------------------------------------------------------------------------------- 1 | ############################################################ 2 | # Default Logging Configuration File 3 | # 4 | # You can use a different file by specifying a filename 5 | # with the java.util.logging.config.file system property. 6 | # For example java -Djava.util.logging.config.file=myfile 7 | ############################################################ 8 | 9 | ############################################################ 10 | # Global properties 11 | ############################################################ 12 | 13 | # "handlers" specifies a comma separated list of log Handler 14 | # classes. These handlers will be installed during VM startup. 15 | # Note that these classes must be on the system classpath. 16 | # By default we only configure a ConsoleHandler, which will only 17 | # show messages at the INFO and above levels. 18 | handlers= java.util.logging.ConsoleHandler 19 | 20 | # To also add the FileHandler, use the following line instead. 21 | #handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler 22 | 23 | # Default global logging level. 24 | # This specifies which kinds of events are logged across 25 | # all loggers. For any given facility this global level 26 | # can be overriden by a facility specific level 27 | # Note that the ConsoleHandler also has a separate level 28 | # setting to limit messages printed to the console. 29 | .level= INFO 30 | 31 | ############################################################ 32 | # Handler specific properties. 33 | # Describes specific configuration info for Handlers. 34 | ############################################################ 35 | 36 | # default file output is in user's home directory. 37 | java.util.logging.FileHandler.pattern = %h/java%u.log 38 | java.util.logging.FileHandler.limit = 50000 39 | java.util.logging.FileHandler.count = 1 40 | java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter 41 | 42 | # Limit the message that are printed on the console to INFO and above. 43 | java.util.logging.ConsoleHandler.level = INFO 44 | java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter 45 | 46 | # Example to customize the SimpleFormatter output format 47 | # to print one-line log message like this: 48 | # : [] 49 | # 50 | # java.util.logging.SimpleFormatter.format=%4$s: %5$s [%1$tc]%n 51 | java.util.logging.SimpleFormatter.format=%3$s %1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s%n%4$s: %5$s%6$s%n 52 | 53 | ############################################################ 54 | # Facility specific properties. 55 | # Provides extra control for each logger. 56 | ############################################################ 57 | 58 | # For example, set the com.xyz.foo logger to only log SEVERE 59 | # messages: 60 | com.xyz.foo.level = SEVERE 61 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AbstractAuctionSession.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.io.IOException; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Objects; 7 | import java.util.logging.Level; 8 | import java.util.logging.Logger; 9 | import java.util.stream.Collectors; 10 | 11 | import javax.inject.Inject; 12 | 13 | import io.baratine.event.Events; 14 | import io.baratine.service.OnDestroy; 15 | import io.baratine.service.OnInit; 16 | import io.baratine.service.Result; 17 | import io.baratine.service.Service; 18 | import io.baratine.service.Services; 19 | import io.baratine.vault.Id; 20 | import io.baratine.web.Body; 21 | import io.baratine.web.Get; 22 | import io.baratine.web.Post; 23 | import io.baratine.web.Query; 24 | import io.baratine.web.RequestWeb; 25 | import io.baratine.web.ServiceWebSocket; 26 | import io.baratine.web.WebSocket; 27 | import io.baratine.web.WebSocketPath; 28 | 29 | public class AbstractAuctionSession implements AuctionSession 30 | { 31 | private final static Logger log 32 | = Logger.getLogger(AbstractAuctionSession.class.getName()); 33 | 34 | @Id 35 | protected String _id; 36 | 37 | @Inject 38 | protected Services _manager; 39 | 40 | @Inject 41 | @Service("/Auction") 42 | protected AuctionAbstractVault _auctions; 43 | protected User _user; 44 | protected String _userId; 45 | @Inject 46 | @Service("/User") 47 | private UserAbstractVault _users; 48 | @Inject 49 | @Service("event:") 50 | private Events _events; 51 | 52 | private HashMap _listenerMap = new HashMap<>(); 53 | 54 | private WebAuctionUpdates _updates; 55 | 56 | @OnInit 57 | public void init() 58 | { 59 | } 60 | 61 | @Post("/createUser") 62 | public void createUser(@Body AuctionUserSession.UserInitData user, 63 | Result result) 64 | { 65 | _users.create(user, result.then((id, r) -> 66 | getUserService(id.toString()).get(r.then(u -> WebUser 67 | .of(u))))); 68 | } 69 | 70 | public User getUserService(String id) 71 | { 72 | return _manager.service(User.class, id); 73 | } 74 | 75 | @Post("/login") 76 | public void login(@Body("u") String user, 77 | @Body("p") String password, 78 | Result result) 79 | { 80 | if (user == null || password == null) { 81 | result.ok(false); 82 | } 83 | else { 84 | _users.findByName(user, 85 | result.then((u, r) -> authenticate(u, 86 | password, 87 | r))); 88 | } 89 | } 90 | 91 | private void authenticate(User user, String password, Result result) 92 | { 93 | if (user == null) { 94 | result.ok(false); 95 | } 96 | else { 97 | user.authenticate(password, 98 | false, 99 | result.then((x, r) -> completeLogin(x, user, r))); 100 | } 101 | } 102 | 103 | private void completeLogin(boolean isLoggedIn, 104 | User user, 105 | Result result) 106 | { 107 | if (isLoggedIn) { 108 | _user = user; 109 | 110 | user.get(result.then(u -> { 111 | _userId = u.getEncodedId(); 112 | return true; 113 | })); 114 | } 115 | else { 116 | result.ok(false); 117 | } 118 | } 119 | 120 | /** 121 | * returns logged in user 122 | */ 123 | public void getUser(Result result) 124 | { 125 | validateSession(); 126 | 127 | _user.get(result.then(u -> WebUser.of(u))); 128 | } 129 | 130 | protected void validateSession() 131 | { 132 | if (_user == null) 133 | throw new IllegalStateException("not logged in"); 134 | } 135 | 136 | public void getAuction(String id, 137 | Result result) 138 | { 139 | validateSession(); 140 | 141 | if (id == null) { 142 | throw new IllegalArgumentException(); 143 | } 144 | 145 | getAuctionService(id).get(result.then(a -> WebAuction.of(a))); 146 | } 147 | 148 | protected Auction getAuctionService(String id) 149 | { 150 | Auction auction = _manager.service(Auction.class, id); 151 | 152 | return auction; 153 | } 154 | 155 | public void findAuction(String title, 156 | Result result) 157 | { 158 | validateSession(); 159 | 160 | _auctions.findByTitle(title, result); 161 | } 162 | 163 | @Get("/searchAuctions") 164 | public void searchAuctions(@Query("q") String query, 165 | Result> result) 166 | { 167 | validateSession(); 168 | 169 | AbstractAuctionSession.log.info(String.format("search %1$s", query)); 170 | 171 | _auctions.findAuctionDataByTitle(query, result.then(l -> asWebAuctions(l))); 172 | } 173 | 174 | private List asWebAuctions(List auctions) 175 | { 176 | return auctions.stream() 177 | .map(a -> WebAuction.of(a)) 178 | .collect(Collectors.toList()); 179 | } 180 | 181 | @WebSocketPath("/auction-updates") 182 | public void updates(RequestWeb request) 183 | { 184 | _updates = new WebAuctionUpdates(); 185 | 186 | request.upgrade(_updates); 187 | } 188 | 189 | @Post("/addAuctionListener") 190 | public void addAuctionListener(@Body String id, Result result) 191 | { 192 | validateSession(); 193 | 194 | if (_listenerMap.containsKey(id)) { 195 | result.ok(true); 196 | 197 | return; 198 | } 199 | 200 | Objects.requireNonNull(id); 201 | 202 | try { 203 | addAuctionListenerImpl(id); 204 | 205 | result.ok(true); 206 | } catch (Throwable t) { 207 | log.log(Level.WARNING, t.getMessage(), t); 208 | 209 | if (t instanceof RuntimeException) 210 | throw (RuntimeException) t; 211 | else 212 | throw new RuntimeException(t); 213 | } 214 | } 215 | 216 | private void addAuctionListenerImpl(String id) 217 | { 218 | if (_listenerMap.containsKey(id)) 219 | return; 220 | 221 | log.finer("add auction events listener for auction: " + id); 222 | 223 | AuctionEventsImpl auctionListener = new AuctionEventsImpl(); 224 | 225 | _events.subscriber(id, auctionListener, (c, e) -> {}); 226 | 227 | auctionListener.subscribe(); 228 | 229 | _listenerMap.put(id, auctionListener); 230 | } 231 | 232 | public void addEvent(AuctionData event) 233 | { 234 | if (_updates != null) 235 | _updates.next(WebAuction.of(event)); 236 | } 237 | 238 | public void logout(Result result) 239 | { 240 | _user = null; 241 | _userId = null; 242 | 243 | unsubscribe(); 244 | 245 | result.ok(true); 246 | } 247 | 248 | private void unsubscribe() 249 | { 250 | for (AuctionEventsImpl events : _listenerMap.values()) { 251 | events.unsubscribe(); 252 | } 253 | 254 | _listenerMap.clear(); 255 | } 256 | 257 | @OnDestroy 258 | public void destroy() 259 | { 260 | AbstractAuctionSession.log.finer("destroy auction channel: " + this); 261 | 262 | unsubscribe(); 263 | } 264 | 265 | @Override 266 | public String toString() 267 | { 268 | return this.getClass().getSimpleName() 269 | + '[' 270 | + _id 271 | + ", " 272 | + _userId 273 | + "]@" + System.identityHashCode(this); 274 | } 275 | 276 | class WebAuctionUpdates implements ServiceWebSocket 277 | { 278 | private WebSocket _updatesSocket; 279 | 280 | @Override 281 | public void open(WebSocket webSocket) 282 | { 283 | _updatesSocket = webSocket; 284 | } 285 | 286 | @Override 287 | public void next(WebAuction auction, 288 | WebSocket webSocket) 289 | throws IOException 290 | { 291 | 292 | } 293 | 294 | public void next(WebAuction auction) 295 | { 296 | _updatesSocket.next(auction); 297 | } 298 | } 299 | 300 | private class AuctionEventsImpl implements AuctionEvents 301 | { 302 | AuctionEventsImpl() 303 | { 304 | } 305 | 306 | public void subscribe() 307 | { 308 | 309 | } 310 | 311 | public void unsubscribe() 312 | { 313 | 314 | } 315 | 316 | @Override 317 | public void onBid(AuctionData auctionData) 318 | { 319 | log.finer("on bid event for auction: " + auctionData); 320 | 321 | addEvent(auctionData); 322 | } 323 | 324 | @Override 325 | public void onClose(AuctionData auctionData) 326 | { 327 | log.finer("on close event for auction: " + auctionData); 328 | 329 | addEvent(auctionData); 330 | } 331 | 332 | @Override 333 | public void onSettled(AuctionData auctionData) 334 | { 335 | addEvent(auctionData); 336 | } 337 | 338 | @Override 339 | public void onRolledBack(AuctionData auctionData) 340 | { 341 | addEvent(auctionData); 342 | } 343 | } 344 | } 345 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/Auction.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import io.baratine.service.Api; 4 | import io.baratine.service.Modify; 5 | import io.baratine.service.Result; 6 | import io.baratine.vault.Asset; 7 | import io.baratine.vault.IdAsset; 8 | 9 | @Asset 10 | @Api 11 | public interface Auction 12 | { 13 | @Modify 14 | void create(AuctionDataInit initData, 15 | Result auctionId); 16 | 17 | @Modify 18 | void open(Result result); 19 | 20 | @Modify 21 | void bid(AuctionBid bid, Result result) 22 | throws IllegalStateException; 23 | 24 | @Modify 25 | void setAuctionWinner(String user, Result result); 26 | 27 | @Modify 28 | void clearAuctionWinner(String user, Result result); 29 | 30 | @Modify 31 | void setSettled(Result result); 32 | 33 | @Modify 34 | void setRolledBack(Result result); 35 | 36 | void get(Result result); 37 | 38 | @Modify 39 | void close(Result result); 40 | 41 | @Modify 42 | void refund(Result result); 43 | 44 | void getSettlementId(Result result); 45 | 46 | enum State 47 | { 48 | INIT, 49 | OPEN, 50 | CLOSED, 51 | SETTLED, 52 | ROLLED_BACK 53 | } 54 | 55 | interface Bid 56 | { 57 | String getAuctionId(); 58 | 59 | String getUserId(); 60 | 61 | int getBid(); 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuctionAbstractVault.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.util.List; 4 | 5 | import io.baratine.service.Result; 6 | import io.baratine.service.Service; 7 | import io.baratine.vault.IdAsset; 8 | import io.baratine.vault.Vault; 9 | 10 | @Service("/Auction") 11 | public interface AuctionAbstractVault 12 | extends Vault 13 | { 14 | void create(AuctionDataInit data, Result id); 15 | 16 | void findByTitle(String title, Result auction); 17 | 18 | void findAuctionDataByTitle(String title, 19 | Result> auction); 20 | 21 | void findIdsByTitle(String title, Result> auction); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuctionAdminSession.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import io.baratine.service.Result; 4 | 5 | /** 6 | * Admin visible channel facade at session://web/auction-session 7 | */ 8 | public interface AuctionAdminSession extends AuctionSession 9 | { 10 | void getWinner(String auctionId, Result result); 11 | 12 | void getSettlementState(String auctionId, 13 | Result result); 14 | 15 | void refund(String id, Result result); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuctionAdminSessionImpl.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.util.logging.Logger; 4 | 5 | import io.baratine.service.Result; 6 | import io.baratine.service.Service; 7 | import io.baratine.web.Body; 8 | import io.baratine.web.Get; 9 | import io.baratine.web.Path; 10 | import io.baratine.web.Post; 11 | import io.baratine.web.Query; 12 | import io.baratine.web.cors.CrossOrigin; 13 | 14 | /** 15 | * User visible channel facade at session://web/auction-admin-session. 16 | */ 17 | @Service("session:") 18 | @CrossOrigin(value = "*", allowCredentials = true) 19 | //@Api(AuctionAdminSession.class) 20 | @Path("/admin") 21 | public class AuctionAdminSessionImpl extends AbstractAuctionSession 22 | implements AuctionAdminSession 23 | { 24 | private final static Logger log 25 | = Logger.getLogger(AuctionAdminSessionImpl.class.getName()); 26 | 27 | @Override 28 | @Get("/winner") 29 | public void getWinner(@Query("id") String auctionId, Result result) 30 | { 31 | validateSession(); 32 | 33 | Auction auction = getAuctionService(auctionId); 34 | 35 | auction.get(result.then((a, r) -> { 36 | getUserService(a.getLastBidder()) 37 | .get(r.then(u -> WebUser.of(u))); 38 | })); 39 | } 40 | 41 | @Override 42 | @Get("/settlement") 43 | public void getSettlementState(@Query("id") String auctionId, 44 | Result result) 45 | { 46 | validateSession(); 47 | 48 | getAuctionSettlementService(auctionId, 49 | result.then((s, r) -> s.getTransactionState(r))); 50 | } 51 | 52 | private void getAuctionSettlementService(String auctionId, 53 | Result result) 54 | { 55 | getAuctionService(auctionId).getSettlementId(result.then(sid -> { 56 | return _manager.service(AuctionSettlement.class, sid); 57 | })); 58 | } 59 | 60 | @Override 61 | @Post("/refund") 62 | public void refund(@Body String id, Result result) 63 | { 64 | validateSession(); 65 | 66 | Auction auction = getAuctionService(id); 67 | 68 | auction.refund(result); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuctionBid.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.io.Serializable; 4 | 5 | public class AuctionBid implements Serializable 6 | { 7 | private String _user; 8 | private int _bid; 9 | 10 | public AuctionBid() 11 | { 12 | } 13 | 14 | public AuctionBid(String user, int bid) 15 | { 16 | _user = user; 17 | _bid = bid; 18 | } 19 | 20 | public String getUser() 21 | { 22 | return _user; 23 | } 24 | 25 | public int getBid() 26 | { 27 | return _bid; 28 | } 29 | 30 | public String toString() 31 | { 32 | return String.format("Bid[%1$s, %2$s]", _user, _bid); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuctionData.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.io.Serializable; 4 | import java.time.ZonedDateTime; 5 | import java.util.ArrayList; 6 | 7 | import static examples.auction.Auction.State; 8 | 9 | /** 10 | * 11 | */ 12 | public class AuctionData implements Serializable 13 | { 14 | private String encodedId; 15 | private String title; 16 | private int startingBid; 17 | 18 | private ZonedDateTime dateToClose; 19 | 20 | private String ownerId; 21 | 22 | private ArrayList bids; 23 | 24 | private AuctionImpl.BidImpl lastBid; 25 | 26 | private State state; 27 | 28 | //user id 29 | private String winnerId; 30 | private String settlementId; 31 | 32 | public AuctionData() 33 | { 34 | } 35 | 36 | public AuctionData(String encodedId, 37 | String title, 38 | int startingBid, 39 | ZonedDateTime dateToClose, 40 | String ownerId, 41 | ArrayList bids, 42 | AuctionImpl.BidImpl lastBid, 43 | State state, 44 | String winner, 45 | String settlementId) 46 | { 47 | this.encodedId = encodedId; 48 | this.title = title; 49 | this.startingBid = startingBid; 50 | this.dateToClose = dateToClose; 51 | this.ownerId = ownerId; 52 | this.bids = bids; 53 | this.lastBid = lastBid; 54 | this.state = state; 55 | this.winnerId = winner; 56 | this.settlementId = settlementId; 57 | } 58 | 59 | public String getEncodedId() 60 | { 61 | return encodedId; 62 | } 63 | 64 | public String getTitle() 65 | { 66 | return title; 67 | } 68 | 69 | public void setTitle(String title) 70 | { 71 | this.title = title; 72 | } 73 | 74 | public int getStartingBid() 75 | { 76 | return startingBid; 77 | } 78 | 79 | public void setStartingBid(int startingBid) 80 | { 81 | this.startingBid = startingBid; 82 | } 83 | 84 | public ZonedDateTime getDateToClose() 85 | { 86 | return dateToClose; 87 | } 88 | 89 | public String getOwnerId() 90 | { 91 | return ownerId; 92 | } 93 | 94 | public String getLastBidder() 95 | { 96 | Auction.Bid lastBid = getLastBid(); 97 | 98 | if (lastBid != null) { 99 | return lastBid.getUserId(); 100 | } 101 | else { 102 | return null; 103 | } 104 | } 105 | 106 | public Auction.Bid getLastBid() 107 | { 108 | return lastBid; 109 | } 110 | 111 | public String getWinnerId() 112 | { 113 | return winnerId; 114 | } 115 | 116 | public void setWinnerId(String winnerId) 117 | { 118 | this.winnerId = winnerId; 119 | } 120 | 121 | public State getState() 122 | { 123 | return state; 124 | } 125 | 126 | @Override 127 | public String toString() 128 | { 129 | String toString 130 | = String.format("%1$s@%2$d[%3$s, %4$s, %5$s, %6$s, %7$s]", 131 | getClass().getSimpleName(), 132 | System.identityHashCode(this), 133 | encodedId, 134 | title, 135 | lastBid, 136 | winnerId, 137 | state); 138 | return toString; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuctionDataInit.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.io.Serializable; 4 | 5 | public class AuctionDataInit implements Serializable 6 | { 7 | private String _userId; 8 | private String _title; 9 | private int _startingBid; 10 | 11 | public AuctionDataInit() 12 | { 13 | } 14 | 15 | public AuctionDataInit(String userId, String title, int startingBid) 16 | { 17 | _userId = userId; 18 | _title = title; 19 | _startingBid = startingBid; 20 | } 21 | 22 | public String getUserId() 23 | { 24 | return _userId; 25 | } 26 | 27 | public String getTitle() 28 | { 29 | return _title; 30 | } 31 | 32 | public int getStartingBid() 33 | { 34 | return _startingBid; 35 | } 36 | 37 | @Override 38 | public String toString() 39 | { 40 | return "AuctionDataInit[" + _title + ", " + _startingBid + ']'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuctionEvents.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | public interface AuctionEvents 4 | { 5 | void onBid(AuctionData auctionData); 6 | 7 | void onClose(AuctionData auctionData); 8 | 9 | void onSettled(AuctionData auctionData); 10 | 11 | void onRolledBack(AuctionData auctionData); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuctionSession.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.util.List; 4 | 5 | import io.baratine.service.Result; 6 | import io.baratine.web.Body; 7 | 8 | public interface AuctionSession 9 | { 10 | void createUser(@Body UserInitData user, Result result); 11 | 12 | void login(String user, String password, Result result); 13 | 14 | void getUser(Result result); 15 | 16 | void getAuction(String id, Result result); 17 | 18 | void findAuction(String title, Result result); 19 | 20 | void searchAuctions(String query, Result> result); 21 | 22 | void addAuctionListener(String idAuction, 23 | Result result); 24 | 25 | void logout(Result result); 26 | 27 | interface WebAuctionUpdateListener 28 | { 29 | void auctionUpdated(WebAuction auction); 30 | } 31 | 32 | public static class WebAuction 33 | { 34 | private String id; 35 | private String title; 36 | private long bid; 37 | private String state; 38 | 39 | public WebAuction() 40 | { 41 | } 42 | 43 | private WebAuction(String id, String title, long bid, String state) 44 | { 45 | this.id = id; 46 | this.title = title; 47 | this.bid = bid; 48 | this.state = state; 49 | } 50 | 51 | public static WebAuction of(AuctionData auction) 52 | { 53 | Auction.Bid bid = auction.getLastBid(); 54 | int price = bid != null ? bid.getBid() : auction.getStartingBid(); 55 | 56 | WebAuction webAuction 57 | = new WebAuction(auction.getEncodedId(), 58 | auction.getTitle(), 59 | price, 60 | auction.getState().toString()); 61 | 62 | return webAuction; 63 | } 64 | 65 | public String getId() 66 | { 67 | return id; 68 | } 69 | 70 | public String getTitle() 71 | { 72 | return title; 73 | } 74 | 75 | public long getBid() 76 | { 77 | return bid; 78 | } 79 | 80 | public String getState() 81 | { 82 | return state; 83 | } 84 | 85 | @Override 86 | public String toString() 87 | { 88 | return this.getClass().getSimpleName() + "[" 89 | + title 90 | + ", " 91 | + bid 92 | + ", " 93 | + state 94 | + ']'; 95 | } 96 | } 97 | 98 | class UserInitData 99 | { 100 | private String user; 101 | private String password; 102 | 103 | private boolean isAdmin; 104 | 105 | public UserInitData() 106 | { 107 | } 108 | 109 | public UserInitData(String user, String password, boolean isAdmin) 110 | { 111 | this.user = user; 112 | this.password = password; 113 | this.isAdmin = isAdmin; 114 | } 115 | 116 | public String getUser() 117 | { 118 | return user; 119 | } 120 | 121 | public String getPassword() 122 | { 123 | return password; 124 | } 125 | 126 | public boolean isAdmin() 127 | { 128 | return isAdmin; 129 | } 130 | 131 | @Override 132 | public String toString() 133 | { 134 | return this.getClass().getSimpleName() + "[" 135 | + user 136 | + ", " 137 | + password 138 | + ']'; 139 | } 140 | } 141 | 142 | class WebUser 143 | { 144 | private String id; 145 | private String user; 146 | 147 | public WebUser() 148 | { 149 | } 150 | 151 | private WebUser(String id, String user) 152 | { 153 | this.id = id; 154 | this.user = user; 155 | } 156 | 157 | public static WebUser of(UserData user) 158 | { 159 | return new WebUser(user.getEncodedId(), user.getName()); 160 | } 161 | 162 | public String getName() 163 | { 164 | return user; 165 | } 166 | 167 | @Override 168 | public String toString() 169 | { 170 | return this.getClass().getSimpleName() + "[" 171 | + user 172 | + ", " 173 | + id 174 | + ']'; 175 | } 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuctionSettlement.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import io.baratine.service.Api; 4 | import io.baratine.service.Result; 5 | import io.baratine.service.Service; 6 | import io.baratine.vault.Asset; 7 | 8 | @Service 9 | @Asset 10 | @Api 11 | public interface AuctionSettlement 12 | { 13 | void settle(Auction.Bid bid, Result result); 14 | 15 | void settleResume(Result result); 16 | 17 | void refund(Result status); 18 | 19 | void settleStatus(Result status); 20 | 21 | void refundStatus(Result status); 22 | 23 | void getTransactionState(Result result); 24 | 25 | enum Status 26 | { 27 | NONE, 28 | SETTLING, 29 | SETTLED, 30 | SETTLE_FAILED, 31 | ROLLING_BACK, 32 | ROLLED_BACK, 33 | ROLLBACK_FAILED 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuctionSettlementVault.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import io.baratine.service.Ensure; 4 | import io.baratine.service.Result; 5 | import io.baratine.service.Service; 6 | import io.baratine.service.Services; 7 | import io.baratine.vault.IdAsset; 8 | import io.baratine.vault.Vault; 9 | 10 | @Service("/AuctionSettlement") 11 | public interface AuctionSettlementVault 12 | extends Vault 13 | { 14 | void create(AuctionData data, Result result); 15 | 16 | @Ensure 17 | default void settle(String id, 18 | Auction.Bid bid, 19 | Result result) 20 | { 21 | System.out.println("AuctionSettlementVault.settle"); 22 | Services.current().service(AuctionSettlementImpl.class, id) 23 | .settle(bid, result.then()); 24 | } 25 | 26 | @Ensure 27 | default void refund(String id, Result result) 28 | { 29 | Services.current().service(AuctionSettlementImpl.class, id) 30 | .refund(result.then()); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuctionUserSession.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import io.baratine.service.Result; 4 | 5 | /** 6 | * User visible channel facade at session://web/auction-session 7 | */ 8 | public interface AuctionUserSession extends AuctionSession 9 | { 10 | void createAuction(String title, int price, Result result); 11 | 12 | void bidAuction(WebBid bid, Result result); 13 | 14 | class WebBid 15 | { 16 | private String auction; 17 | private int bid; 18 | 19 | public WebBid() 20 | { 21 | } 22 | 23 | public WebBid(String auction, int bid) 24 | { 25 | this.auction = auction; 26 | this.bid = bid; 27 | } 28 | 29 | public String getAuction() 30 | { 31 | return auction; 32 | } 33 | 34 | public int getBid() 35 | { 36 | return bid; 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuctionUserSessionImpl.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.util.logging.Logger; 4 | 5 | import io.baratine.service.Result; 6 | import io.baratine.service.Service; 7 | import io.baratine.web.Body; 8 | import io.baratine.web.Path; 9 | import io.baratine.web.Post; 10 | import io.baratine.web.cors.CrossOrigin; 11 | 12 | /** 13 | * User visible channel facade at session:///auction-session. 14 | */ 15 | @Service("session:///user") 16 | @CrossOrigin(value = "*", allowCredentials = true) 17 | @Path("/user") 18 | public class AuctionUserSessionImpl extends AbstractAuctionSession 19 | implements AuctionUserSession 20 | { 21 | private final static Logger log 22 | = Logger.getLogger(AuctionUserSessionImpl.class.getName()); 23 | 24 | @Post("/createAuction") 25 | public void createAuction(@Body("t") String title, 26 | @Body("b") int price, 27 | Result result) 28 | { 29 | validateSession(); 30 | 31 | _auctions.create(new AuctionDataInit(_userId, title, price), 32 | result.then((id, r) -> afterCreateAuction(id.toString(), 33 | r))); 34 | } 35 | 36 | private void afterCreateAuction(String auctionId, Result result) 37 | { 38 | Auction auction = _manager.service(Auction.class, auctionId); 39 | 40 | auction.open(result.then((b, r) -> getAuction(auctionId, r))); 41 | } 42 | 43 | /** 44 | * Bid on an auction. 45 | * 46 | * @param bid the new bid 47 | * @param result true for successful auction. 48 | */ 49 | @Post("/bidAuction") 50 | public void bidAuction(@Body WebBid bid, Result result) 51 | { 52 | validateSession(); 53 | 54 | getAuctionService(bid.getAuction()) 55 | .bid(new AuctionBid(_userId, bid.getBid()), result); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuctionVault.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import io.baratine.service.Service; 4 | 5 | @Service("/Auction") 6 | public interface AuctionVault extends AuctionAbstractVault 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuditService.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import io.baratine.service.Result; 4 | 5 | public interface AuditService 6 | { 7 | void auctionCreate(AuctionDataInit initData, Result ignore); 8 | 9 | void auctionLoad(AuctionData auction, Result ignore); 10 | 11 | void auctionSave(AuctionData auction, Result ignore); 12 | 13 | void auctionToOpen(AuctionData auction, Result ignore); 14 | 15 | void auctionToClose(AuctionData auction, Result ignore); 16 | 17 | void auctionBid(AuctionData auction, 18 | AuctionBid bid, 19 | Result ignore); 20 | 21 | void auctionBidAccept(AuctionBid bid, Result ignore); 22 | 23 | void auctionBidReject(AuctionBid bid, Result ignore); 24 | 25 | void settlementRequestAccepted(String auctionId, Result ignore); 26 | 27 | void settlementRequestPersisted(String settlementId, 28 | String auctionId, 29 | Result ignore); 30 | 31 | void settlementAuctionWillSettle(String settlementId, 32 | AuctionData auction, 33 | Auction.Bid bid, 34 | Result ignore); 35 | 36 | void settlementCompletingWithPayment(String settlementId, 37 | String auctionId, 38 | Payment payment, 39 | Result ignore); 40 | 41 | void payPalReceivePaymentResponse(String settlementId, 42 | AuctionData auction, 43 | Payment payment, 44 | Result ignore); 45 | 46 | void payPalSendPaymentRequest(String settlementId, 47 | AuctionData auction, 48 | Auction.Bid bid, 49 | String userId, 50 | Result ignore); 51 | 52 | void payPalSendRefund(String settlementId, 53 | String saleId, 54 | Result ignore); 55 | 56 | void payPalReceiveRefundResponse(String settlementId, 57 | String saleId, 58 | Refund refund, 59 | Result ignore); 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/AuditServiceImpl.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.util.logging.Logger; 4 | 5 | import io.baratine.service.Result; 6 | import io.baratine.service.Service; 7 | 8 | @Service("/Audit") 9 | public class AuditServiceImpl implements AuditService 10 | { 11 | public final static Logger log 12 | = Logger.getLogger(AuditServiceImpl.class.getName()); 13 | 14 | @Override 15 | public void auctionCreate(AuctionDataInit initData, Result ignore) 16 | { 17 | String message = String.format("auction create %1$s", initData); 18 | log.info(message); 19 | 20 | ignore.ok(null); 21 | } 22 | 23 | @Override 24 | public void auctionLoad(AuctionData auction, Result ignore) 25 | { 26 | String message = String.format("auction load %1$s", auction); 27 | log.info(message); 28 | 29 | ignore.ok(null); 30 | } 31 | 32 | @Override 33 | public void auctionSave(AuctionData auction, Result ignore) 34 | { 35 | String message = String.format("auction save %1$s", auction); 36 | log.info(message); 37 | 38 | ignore.ok(null); 39 | } 40 | 41 | @Override 42 | public void auctionToOpen(AuctionData auction, Result ignore) 43 | { 44 | String message = String.format("auction open %1$s", auction); 45 | log.info(message); 46 | 47 | ignore.ok(null); 48 | } 49 | 50 | @Override 51 | public void auctionToClose(AuctionData auction, Result ignore) 52 | { 53 | String message = String.format("auction close %1$s", auction); 54 | log.info(message); 55 | 56 | ignore.ok(null); 57 | } 58 | 59 | @Override 60 | public void auctionBid(AuctionData auction, 61 | AuctionBid bid, 62 | Result ignore) 63 | { 64 | String message = String.format("auction %1$s bid %2$s", auction, bid); 65 | log.info(message); 66 | 67 | ignore.ok(null); 68 | } 69 | 70 | @Override 71 | public void auctionBidAccept(AuctionBid bid, Result ignore) 72 | { 73 | String message = String.format("bid accepted %1$s", bid); 74 | log.info(message); 75 | 76 | ignore.ok(null); 77 | } 78 | 79 | @Override 80 | public void auctionBidReject(AuctionBid bid, Result ignore) 81 | { 82 | String message = String.format("bid rejected %1$s", bid); 83 | log.info(message); 84 | 85 | ignore.ok(null); 86 | } 87 | 88 | @Override 89 | public void settlementRequestAccepted(String auctionId, Result ignore) 90 | { 91 | String message 92 | = String.format("accepting settle request for auction %1$s", auctionId); 93 | 94 | log.info(message); 95 | 96 | ignore.ok(null); 97 | } 98 | 99 | @Override 100 | public void settlementRequestPersisted(String settlementId, 101 | String auctionId, 102 | Result ignore) 103 | { 104 | String message 105 | = String.format( 106 | "settlement request for auction %2$s persisted with settlement id %1$s", 107 | settlementId); 108 | 109 | log.info(message); 110 | 111 | ignore.ok(null); 112 | 113 | } 114 | 115 | @Override 116 | public void settlementAuctionWillSettle(String settlementId, 117 | AuctionData auction, 118 | Auction.Bid bid, 119 | Result ignore) 120 | { 121 | String message 122 | = String.format("%1$s: auction %2$s will settle with bid %3$s", 123 | settlementId, 124 | auction, 125 | bid); 126 | 127 | log.info(message); 128 | 129 | ignore.ok(null); 130 | } 131 | 132 | @Override 133 | public void settlementCompletingWithPayment(String settlementId, 134 | String auctionId, 135 | Payment payment, 136 | Result ignore) 137 | { 138 | String message 139 | = String.format( 140 | "%1$s: settlement for auction %2$s completing with payment %3$s", 141 | settlementId, 142 | auctionId, 143 | payment); 144 | 145 | log.info(message); 146 | 147 | ignore.ok(null); 148 | } 149 | 150 | @Override 151 | public void payPalReceivePaymentResponse(String settlementId, 152 | AuctionData auction, 153 | Payment payment, 154 | Result ignore) 155 | { 156 | String message 157 | = String.format( 158 | "%1$s: pay pal payment response %2$s received for auction %3$s", 159 | settlementId, 160 | payment, 161 | auction); 162 | 163 | log.info(message); 164 | 165 | ignore.ok(null); 166 | 167 | } 168 | 169 | @Override 170 | public void payPalSendPaymentRequest(String settlementId, 171 | AuctionData auction, 172 | Auction.Bid bid, 173 | String userId, 174 | Result ignore) 175 | { 176 | String message 177 | = String.format( 178 | "%1$s: pay pal send payment request for auction %2$s, bid %3$s, user %4$s", 179 | settlementId, 180 | auction, 181 | bid, 182 | userId); 183 | 184 | log.info(message); 185 | 186 | ignore.ok(null); 187 | } 188 | 189 | @Override 190 | public void payPalSendRefund(String settlementId, 191 | String saleId, 192 | Result ignore) 193 | { 194 | String message = String.format( 195 | "%1$s: pay pal send refund request for saleId %2$s", 196 | settlementId, 197 | saleId); 198 | 199 | log.info(message); 200 | 201 | ignore.ok(null); 202 | } 203 | 204 | @Override 205 | public void payPalReceiveRefundResponse(String settlementId, 206 | String saleId, 207 | Refund refund, 208 | Result ignore) 209 | { 210 | String message = String.format( 211 | "%1$s: pay pal refund response %2$s for saleId %3$s", 212 | settlementId, 213 | refund, 214 | saleId); 215 | 216 | log.info(message); 217 | 218 | ignore.ok(null); 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/CreditCard.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | public class CreditCard 4 | { 5 | private String _type; 6 | private String _num; 7 | private String _cvv; 8 | private int _expMonth; 9 | private int _expYear; 10 | 11 | public CreditCard(String type, 12 | String num, 13 | String cvv, 14 | int expMonth, 15 | int expYear) 16 | { 17 | _type = type; 18 | _num = num; 19 | _cvv = cvv; 20 | _expMonth = expMonth; 21 | _expYear = expYear; 22 | } 23 | 24 | public String getType() 25 | { 26 | return _type; 27 | } 28 | 29 | public String getNum() 30 | { 31 | return _num; 32 | } 33 | 34 | public String getCvv() 35 | { 36 | return _cvv; 37 | } 38 | 39 | public int getExpMonth() 40 | { 41 | return _expMonth; 42 | } 43 | 44 | public int getExpYear() 45 | { 46 | return _expYear; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/Main.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.io.File; 4 | import java.util.logging.Level; 5 | import java.util.logging.Logger; 6 | 7 | import static io.baratine.web.Web.*; 8 | 9 | public class Main 10 | { 11 | public static void main(String[] args) 12 | { 13 | if (new File("src/main/resources/web/index.htmlx").exists()) 14 | property("server.file", "src/main/resources/web"); 15 | else 16 | property("server.file", "classpath:/web"); 17 | 18 | include(AuctionAdminSessionImpl.class); 19 | include(AuctionUserSessionImpl.class); 20 | 21 | include(AuctionSettlementVault.class); 22 | include(AuditServiceImpl.class); 23 | include(PayPalImpl.class); 24 | 25 | include(UserVault.class); 26 | include(AuctionVault.class); 27 | 28 | Level level = Level.FINEST; 29 | 30 | Logger.getLogger("com.caucho").setLevel(level); 31 | Logger.getLogger("examples").setLevel(level); 32 | Logger.getLogger("core").setLevel(level); 33 | 34 | try { 35 | start(); 36 | } catch (Exception e) { 37 | e.printStackTrace(); 38 | } 39 | 40 | Logger.getLogger("com.caucho").setLevel(level); 41 | Logger.getLogger("examples").setLevel(level); 42 | Logger.getLogger("core").setLevel(level); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/PayPal.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import io.baratine.service.Result; 4 | 5 | public interface PayPal 6 | { 7 | void settle(AuctionData auction, 8 | Auction.Bid bid, 9 | CreditCard creditCard, 10 | String payPalRequestId, 11 | Result result); 12 | 13 | void refund(String settlementId, 14 | String payPalRequestId, 15 | String sale, 16 | Result result); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/PayPalAuth.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.io.StringReader; 4 | 5 | import javax.json.Json; 6 | import javax.json.JsonObject; 7 | import javax.json.JsonReader; 8 | 9 | public class PayPalAuth 10 | { 11 | private String _token; 12 | private String _auth; 13 | 14 | public PayPalAuth() 15 | { 16 | } 17 | 18 | public PayPalAuth(String token, String auth) 19 | { 20 | _token = token; 21 | _auth = auth; 22 | } 23 | 24 | public PayPalAuth(String response) 25 | { 26 | _auth = _auth; 27 | 28 | JsonReader reader = Json.createReader(new StringReader(response)); 29 | JsonObject json = reader.readObject(); 30 | 31 | String token = json.getString("access_token"); 32 | 33 | _token = token; 34 | } 35 | 36 | public String getToken() 37 | { 38 | return _token; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/PayPalImpl.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.util.logging.Level; 4 | import java.util.logging.Logger; 5 | 6 | import javax.inject.Inject; 7 | 8 | import io.baratine.service.Result; 9 | import io.baratine.service.Service; 10 | import io.baratine.service.Workers; 11 | 12 | @Service("/PayPal") 13 | @Workers(20) 14 | public class PayPalImpl implements PayPal 15 | { 16 | private static final Logger log 17 | = Logger.getLogger(PayPalImpl.class.getName()); 18 | 19 | @Inject 20 | private PayPalRestLink _rest; 21 | 22 | @Inject 23 | @Service("/Audit") 24 | private AuditService _audit; 25 | 26 | @Override 27 | public void settle(AuctionData auction, 28 | Auction.Bid bid, 29 | CreditCard creditCard, 30 | String payPalRequestId, 31 | Result result) 32 | { 33 | try { 34 | log.log(Level.FINER, String.format("settle payment for auction %1$s", 35 | auction)); 36 | 37 | PayPalAuth auth = _rest.auth(); 38 | 39 | String amount = String.format("%1$d.00", bid.getBid()); 40 | 41 | _audit.payPalSendPaymentRequest(payPalRequestId, 42 | auction, 43 | bid, 44 | bid.getUserId(), 45 | Result.ignore()); 46 | 47 | Payment payment = _rest.pay(auth.getToken(), 48 | payPalRequestId, 49 | creditCard.getNum(), 50 | creditCard.getType(), 51 | creditCard.getExpMonth(), 52 | creditCard.getExpYear(), 53 | creditCard.getCvv(), 54 | "John", 55 | "Doe", 56 | amount, 57 | "USD", 58 | auction.getTitle()); 59 | 60 | _audit.payPalReceivePaymentResponse(payPalRequestId, 61 | auction, 62 | payment, 63 | Result.ignore()); 64 | 65 | log.log(Level.FINER, String.format( 66 | "payment recieved for auction %1$s -> %2$s ", 67 | auction.getEncodedId(), 68 | payment)); 69 | 70 | result.ok(payment); 71 | } catch (Throwable t) { 72 | log.log(Level.WARNING, t.getMessage(), t); 73 | 74 | result.fail(t); 75 | } 76 | } 77 | 78 | @Override 79 | public void refund(String settlementId, 80 | String payPalRequestId, 81 | String salesId, 82 | Result result) 83 | { 84 | try { 85 | _audit.payPalSendRefund(settlementId, salesId, Result.ignore()); 86 | PayPalAuth auth = _rest.auth(); 87 | Refund refund = _rest.refund(auth.getToken(), payPalRequestId, salesId); 88 | 89 | result.ok(refund); 90 | 91 | _audit.payPalReceiveRefundResponse(settlementId, 92 | salesId, 93 | refund, 94 | Result.ignore()); 95 | } catch (Throwable e) { 96 | result.fail(e); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/PayPalRestLink.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.io.OutputStream; 9 | import java.io.UnsupportedEncodingException; 10 | import java.net.HttpURLConnection; 11 | import java.net.URL; 12 | import java.nio.charset.StandardCharsets; 13 | import java.util.Base64; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | import java.util.Properties; 17 | import java.util.logging.Level; 18 | import java.util.logging.Logger; 19 | 20 | import javax.inject.Singleton; 21 | 22 | @Singleton 23 | public class PayPalRestLink 24 | { 25 | private static final Logger log 26 | = Logger.getLogger(PayPalRestLink.class.getName()); 27 | 28 | private String _app; 29 | private String _account; 30 | private String _clientId; 31 | private String _secret; 32 | private String _endpoint; 33 | private boolean _isActive; 34 | 35 | public PayPalRestLink() throws IOException 36 | { 37 | InputStream in = null; 38 | 39 | try { 40 | in = PayPalRestLink.class.getResourceAsStream("/paypal.properties"); 41 | } catch (Throwable t) { 42 | log.log(Level.WARNING, t.getMessage(), t); 43 | } 44 | 45 | try { 46 | if (in == null) { 47 | in = new FileInputStream(System.getProperty("user.home") 48 | + File.separator 49 | + ".paypal.properties"); 50 | } 51 | 52 | Properties p = new Properties(); 53 | 54 | p.load(in); 55 | _app = p.getProperty("app"); 56 | _account = p.getProperty("account"); 57 | _clientId = p.getProperty("client-id").trim(); 58 | _secret = p.getProperty("secret").trim(); 59 | _endpoint = p.getProperty("endpoint"); 60 | 61 | _isActive = true; 62 | } catch (java.io.FileNotFoundException e) { 63 | log.log(Level.INFO, 64 | "paypal.properties is not found, PayPal will not be available"); 65 | } finally { 66 | if (in != null) 67 | in.close(); 68 | } 69 | } 70 | 71 | public PayPalAuth auth() throws IOException 72 | { 73 | if (!_isActive) 74 | return new DummyPayPalAuth(); 75 | 76 | Map headers = new HashMap<>(); 77 | 78 | headers.put("Authorization", "Basic " + getBA()); 79 | headers.put("Accept", "application/json"); 80 | headers.put("Accept-Language", "en_US"); 81 | headers.put("Content-Type", "application/x-www-form-urlencoded"); 82 | 83 | String reply = send("/v1/oauth2/token", 84 | "POST", 85 | headers, 86 | "grant_type=client_credentials".getBytes()); 87 | 88 | return new PayPalAuth(reply); 89 | } 90 | 91 | private String getBA() throws UnsupportedEncodingException 92 | { 93 | String auth = _clientId + ':' + _secret; 94 | byte[] bytes = Base64.getEncoder().encode(auth.getBytes("UTF-8")); 95 | 96 | return new String(bytes, "UTF-8"); 97 | } 98 | 99 | private String send(String subUrl, 100 | String method, 101 | Map headers, 102 | byte[] body) 103 | throws IOException 104 | { 105 | if (!subUrl.startsWith("/")) 106 | throw new IllegalArgumentException(); 107 | 108 | URL url = new URL(String.format("https://%1$s", _endpoint) + subUrl); 109 | 110 | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 111 | connection.setRequestMethod(method); 112 | 113 | connection.setDoInput(true); 114 | connection.setDoOutput(true); 115 | 116 | for (Map.Entry entry : headers.entrySet()) { 117 | connection.setRequestProperty(entry.getKey(), entry.getValue()); 118 | } 119 | 120 | if (body != null) { 121 | OutputStream out = connection.getOutputStream(); 122 | 123 | out.write(body); 124 | 125 | out.flush(); 126 | } 127 | 128 | int responseCode = connection.getResponseCode(); 129 | 130 | if (responseCode == 200 || responseCode == 201) { 131 | InputStream in = connection.getInputStream(); 132 | ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 133 | byte[] temp = new byte[1024]; 134 | int l; 135 | 136 | while ((l = in.read(temp)) > 0) 137 | buffer.write(temp, 0, l); 138 | 139 | return new String(buffer.toByteArray()); 140 | } 141 | else { 142 | log.warning(String.format("error response %1$d", responseCode)); 143 | 144 | StringBuilder error = new StringBuilder(); 145 | 146 | InputStream err = connection.getErrorStream(); 147 | int i; 148 | while ((i = err.read()) > 0) 149 | error.append((char) i); 150 | 151 | throw new IllegalStateException(responseCode 152 | + ": " 153 | + connection.getResponseMessage() 154 | + ": " 155 | + error); 156 | } 157 | } 158 | 159 | /** 160 | * @param payPalRequestId 161 | * @return 162 | * @throws IOException 163 | */ 164 | public Payment pay(String securityToken, 165 | String payPalRequestId, 166 | String ccNumber, 167 | String ccType, 168 | int ccExpireM, 169 | int ccExpireY, 170 | String ccv2, 171 | String firstName, 172 | String lastName, 173 | String total, 174 | String currency, 175 | String description 176 | ) throws IOException 177 | { 178 | if (!_isActive) 179 | return new DummyPayment(); 180 | 181 | final String payment; 182 | 183 | try (InputStream in 184 | = PayPalRestLink.class.getResourceAsStream("/payment.template.json")) { 185 | ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 186 | 187 | byte[] bytes = new byte[512]; 188 | 189 | int l; 190 | 191 | while ((l = in.read(bytes)) > 0) 192 | buffer.write(bytes, 0, l); 193 | 194 | payment = String.format(new String(buffer.toByteArray(), "UTF-8"), 195 | ccNumber, 196 | ccType, 197 | ccExpireM, 198 | ccExpireY, 199 | ccv2, 200 | firstName, 201 | lastName, 202 | total, 203 | currency, 204 | description); 205 | 206 | log.finer(payment); 207 | } 208 | 209 | Map headers = new HashMap<>(); 210 | headers.put("Content-Type", "application/json"); 211 | headers.put("Authorization", "Bearer " + securityToken); 212 | headers.put("PayPal-Request-Id", payPalRequestId); 213 | 214 | String response = send("/v1/payments/payment", "POST", headers, 215 | payment.getBytes("UTF-8")); 216 | 217 | return new PaymentImpl(response); 218 | } 219 | 220 | public String list(String token) throws IOException 221 | { 222 | Map headers = new HashMap<>(); 223 | 224 | headers.put("Content-Type", "application/json"); 225 | headers.put("Authorization", "Bearer " + token); 226 | 227 | return send("/v1/payments/payment?count=20", "GET", headers, null); 228 | } 229 | 230 | public Refund refund(String securityToken, 231 | String payPalRequestId, 232 | String saleId) 233 | throws IOException 234 | { 235 | if (!_isActive) 236 | return new DummyRefund(); 237 | 238 | Map headers = new HashMap<>(); 239 | 240 | headers.put("Content-Type", "application/json"); 241 | headers.put("Authorization", "Bearer " + securityToken); 242 | headers.put("PayPal-Request-Id", payPalRequestId); 243 | 244 | String response = send("/v1/payments/sale/" + saleId + "/refund", 245 | "POST", 246 | headers, 247 | "{}".getBytes(StandardCharsets.UTF_8)); 248 | 249 | return new RefundImpl(response); 250 | } 251 | 252 | @Override 253 | public String toString() 254 | { 255 | return "TestLogin[" 256 | + _app + ", " 257 | + _account + ", " 258 | + _clientId + ", " 259 | + _secret + ", " 260 | + _endpoint 261 | + ']'; 262 | } 263 | 264 | public static class DummyPayment implements Payment 265 | { 266 | @Override 267 | public PaymentState getState() 268 | { 269 | return PaymentState.approved; 270 | } 271 | 272 | @Override 273 | public String getSaleId() 274 | { 275 | return ""; 276 | } 277 | } 278 | 279 | public static class DummyRefund implements Refund 280 | { 281 | @Override 282 | public RefundState getStatus() 283 | { 284 | return RefundState.completed; 285 | } 286 | } 287 | 288 | public static class DummyPayPalAuth extends PayPalAuth 289 | { 290 | public DummyPayPalAuth() 291 | { 292 | super("", ""); 293 | } 294 | } 295 | } 296 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/Payment.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | public interface Payment 4 | { 5 | PaymentState getState(); 6 | 7 | String getSaleId(); 8 | 9 | enum PaymentState 10 | { 11 | created, approved, failed, canceled, expired, pending; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/PaymentImpl.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.io.StringReader; 4 | 5 | import javax.json.JsonObject; 6 | 7 | /** 8 | * Class payment encapsulates PayPal reply 9 | */ 10 | public class PaymentImpl implements Payment 11 | { 12 | private String _payment; 13 | 14 | private PaymentState _state; 15 | 16 | private String _saleId; 17 | 18 | public PaymentImpl() 19 | { 20 | } 21 | 22 | public PaymentImpl(String payment) 23 | { 24 | _payment = payment; 25 | 26 | JsonObject jsonObject 27 | = javax.json.Json.createReader(new StringReader(payment)).readObject(); 28 | 29 | String state = jsonObject.getString("state"); 30 | 31 | _state = Enum.valueOf(PaymentState.class, state); 32 | 33 | _saleId = jsonObject.getJsonArray("transactions").getJsonObject(0) 34 | .getJsonArray("related_resources").getJsonObject(0) 35 | .getJsonObject("sale").getString("id"); 36 | } 37 | 38 | @Override 39 | public PaymentState getState() 40 | { 41 | return _state; 42 | } 43 | 44 | @Override 45 | public String getSaleId() 46 | { 47 | return _saleId; 48 | } 49 | 50 | @Override 51 | public String toString() 52 | { 53 | return PaymentImpl.class.getSimpleName() + "[" + _payment + "]"; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/Refund.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | public interface Refund 4 | { 5 | RefundState getStatus(); 6 | 7 | public enum RefundState 8 | { 9 | pending, completed, failed 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/RefundImpl.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.io.StringReader; 4 | 5 | import javax.json.JsonObject; 6 | 7 | /** 8 | * { 9 | * "id": "9JU80416NM254722B", 10 | * "create_time": "2015-11-20T17:33:02Z", 11 | * "update_time": "2015-11-20T17:33:02Z", 12 | * "state": "completed", 13 | * "amount": { 14 | * "total": "6.00", 15 | * "currency": "USD" 16 | * }, 17 | * "sale_id": "6W4936389X1091947", 18 | * "parent_payment": "PAY-2X7976490R398621MKZB6KSQ", 19 | * "links": [ 20 | * { 21 | * "href": "https://api.sandbox.paypal.com/v1/payments/refund/9JU80416NM254722B", 22 | * "rel": "self", 23 | * "method": "GET" 24 | * }, 25 | * { 26 | * "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-2X7976490R398621MKZB6KSQ", 27 | * "rel": "parent_payment", 28 | * "method": "GET" 29 | * }, 30 | * { 31 | * "href": "https://api.sandbox.paypal.com/v1/payments/sale/6W4936389X1091947", 32 | * "rel": "sale", 33 | * "method": "GET" 34 | * } 35 | * ] 36 | * } 37 | */ 38 | public class RefundImpl implements Refund 39 | { 40 | private String _refund; 41 | private RefundState _status; 42 | 43 | public RefundImpl() 44 | { 45 | } 46 | 47 | public RefundImpl(String refund) 48 | { 49 | _refund = refund; 50 | 51 | JsonObject jsonObject 52 | = javax.json.Json.createReader(new StringReader(refund)).readObject(); 53 | 54 | String state = jsonObject.getString("state"); 55 | 56 | _status = Enum.valueOf(RefundState.class, state); 57 | } 58 | 59 | @Override 60 | public RefundState getStatus() 61 | { 62 | return _status; 63 | } 64 | 65 | @Override 66 | public String toString() 67 | { 68 | return String.format("%1$s@%2$d: %3$s", 69 | this.getClass().getSimpleName(), 70 | System.identityHashCode(this), 71 | _refund); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/SettlementTransactionState.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | public class SettlementTransactionState 4 | { 5 | private Intent _intent = Intent.SETTLE; 6 | 7 | private AuctionSettlement.Status _settleStatus 8 | = AuctionSettlement.Status.SETTLING; 9 | 10 | private AuctionSettlement.Status _refundStatus 11 | = AuctionSettlement.Status.NONE; 12 | 13 | private UserUpdateState _userSettleState = UserUpdateState.NONE; 14 | private UserUpdateState _userResetState = UserUpdateState.NONE; 15 | 16 | private AuctionWinnerUpdateState 17 | _auctionWinnerUpdateState = AuctionWinnerUpdateState.NONE; 18 | private AuctionWinnerUpdateState 19 | _auctionWinnerResetState = AuctionWinnerUpdateState.NONE; 20 | 21 | private PaymentTxState _paymentState = PaymentTxState.NONE; 22 | 23 | private AuctionUpdateState _auctionStateUpdateState = AuctionUpdateState.NONE; 24 | 25 | private PaymentTxState _refundState = PaymentTxState.NONE; 26 | 27 | private Payment _payment; 28 | 29 | private Refund _refund; 30 | 31 | public SettlementTransactionState() 32 | { 33 | } 34 | 35 | public void toRefund() 36 | { 37 | _intent = Intent.REFUND; 38 | } 39 | 40 | public UserUpdateState getUserSettleState() 41 | { 42 | return _userSettleState; 43 | } 44 | 45 | public void setUserSettleState(UserUpdateState userSettleState) 46 | { 47 | _userSettleState = userSettleState; 48 | } 49 | 50 | public AuctionWinnerUpdateState getAuctionWinnerUpdateState() 51 | { 52 | return _auctionWinnerUpdateState; 53 | } 54 | 55 | public void setAuctionWinnerUpdateState(AuctionWinnerUpdateState auctionWinnerUpdateState) 56 | { 57 | _auctionWinnerUpdateState = auctionWinnerUpdateState; 58 | } 59 | 60 | public PaymentTxState getPaymentState() 61 | { 62 | return _paymentState; 63 | } 64 | 65 | public void setPaymentState(PaymentTxState paymentState) 66 | { 67 | _paymentState = paymentState; 68 | } 69 | 70 | public UserUpdateState getUserResetState() 71 | { 72 | return _userResetState; 73 | } 74 | 75 | public void setUserResetState(UserUpdateState userResetState) 76 | { 77 | _userResetState = userResetState; 78 | } 79 | 80 | public AuctionWinnerUpdateState getAuctionWinnerResetState() 81 | { 82 | return _auctionWinnerResetState; 83 | } 84 | 85 | public void setAuctionWinnerResetState(AuctionWinnerUpdateState auctionWinnerResetState) 86 | { 87 | _auctionWinnerResetState = auctionWinnerResetState; 88 | } 89 | 90 | public PaymentTxState getRefundState() 91 | { 92 | return _refundState; 93 | } 94 | 95 | public void setRefundState(PaymentTxState refundState) 96 | { 97 | _refundState = refundState; 98 | } 99 | 100 | public AuctionUpdateState getAuctionStateUpdateState() 101 | { 102 | return _auctionStateUpdateState; 103 | } 104 | 105 | public void setAuctionStateUpdateState(AuctionUpdateState auctionStateUpdateState) 106 | { 107 | _auctionStateUpdateState = auctionStateUpdateState; 108 | } 109 | 110 | public boolean isSettled() 111 | { 112 | boolean isSettled = _intent == Intent.SETTLE; 113 | 114 | isSettled &= _userSettleState == UserUpdateState.SUCCESS; 115 | 116 | isSettled &= _auctionWinnerUpdateState 117 | == AuctionWinnerUpdateState.SUCCESS; 118 | 119 | isSettled &= _paymentState == PaymentTxState.SUCCESS; 120 | 121 | return isSettled; 122 | } 123 | 124 | public boolean isCommitting() 125 | { 126 | return _intent == Intent.SETTLE; 127 | } 128 | 129 | public boolean isRefunded() 130 | { 131 | boolean isRefunded = _intent == Intent.REFUND; 132 | 133 | isRefunded &= (_userSettleState == UserUpdateState.REJECTED 134 | || _userResetState == UserUpdateState.ROLLED_BACK); 135 | 136 | isRefunded &= (_auctionWinnerUpdateState 137 | == AuctionWinnerUpdateState.REJECTED 138 | || _auctionWinnerResetState 139 | == AuctionWinnerUpdateState.ROLLED_BACK); 140 | 141 | isRefunded &= (_paymentState == PaymentTxState.FAILED 142 | || _refundState == PaymentTxState.REFUNDED); 143 | 144 | return isRefunded; 145 | } 146 | 147 | public boolean isRefunding() 148 | { 149 | return _intent == Intent.REFUND; 150 | } 151 | 152 | public Payment getPayment() 153 | { 154 | return _payment; 155 | } 156 | 157 | public void setPayment(Payment payment) 158 | { 159 | _payment = payment; 160 | } 161 | 162 | public Refund getRefund() 163 | { 164 | return _refund; 165 | } 166 | 167 | public void setRefund(Refund refund) 168 | { 169 | _refund = refund; 170 | } 171 | 172 | public AuctionSettlement.Status getSettleStatus() 173 | { 174 | return _settleStatus; 175 | } 176 | 177 | public void setSettleStatus(AuctionSettlement.Status commitStatus) 178 | { 179 | _settleStatus = commitStatus; 180 | } 181 | 182 | public AuctionSettlement.Status getRefundStatus() 183 | { 184 | return _refundStatus; 185 | } 186 | 187 | public void setRefundStatus(AuctionSettlement.Status refundStatus) 188 | { 189 | _refundStatus = refundStatus; 190 | } 191 | 192 | @Override 193 | public String toString() 194 | { 195 | return this.getClass().getSimpleName() 196 | + "[" 197 | + _intent 198 | + ", " 199 | + _userSettleState + ", " 200 | + _auctionWinnerUpdateState + ", " 201 | + _paymentState 202 | + "]"; 203 | } 204 | 205 | enum Intent 206 | { 207 | SETTLE, 208 | REFUND 209 | } 210 | 211 | enum UserUpdateState 212 | { 213 | SUCCESS, 214 | REJECTED, 215 | ROLLED_BACK, 216 | NONE 217 | } 218 | 219 | enum AuctionWinnerUpdateState 220 | { 221 | SUCCESS, 222 | REJECTED, 223 | ROLLED_BACK, 224 | NONE 225 | } 226 | 227 | enum AuctionUpdateState 228 | { 229 | SUCCESS, 230 | ROLLED_BACK, 231 | NONE 232 | } 233 | 234 | enum PaymentTxState 235 | { 236 | SUCCESS, 237 | PENDING, 238 | FAILED, 239 | REFUNDED, 240 | NONE 241 | } 242 | } 243 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/User.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import io.baratine.service.Api; 4 | import io.baratine.service.Modify; 5 | import io.baratine.service.Result; 6 | import io.baratine.vault.Asset; 7 | import io.baratine.vault.IdAsset; 8 | 9 | @Asset 10 | @Api 11 | public interface User 12 | { 13 | @Modify 14 | void create(AuctionUserSessionImpl.UserInitData user, 15 | Result userId); 16 | 17 | void authenticate(String password, 18 | boolean isAdmin, 19 | Result result); 20 | 21 | void get(Result user); 22 | 23 | void getCreditCard(Result creditCard); 24 | 25 | void addWonAuction(String auction, Result result); 26 | 27 | void removeWonAuction(String auction, Result result); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/UserAbstractVault.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import io.baratine.service.Result; 4 | import io.baratine.service.Service; 5 | import io.baratine.vault.IdAsset; 6 | import io.baratine.vault.Vault; 7 | 8 | @Service("/User") 9 | public interface UserAbstractVault extends Vault 10 | { 11 | void create(AuctionUserSession.UserInitData userInitData, 12 | Result result); 13 | 14 | void findByName(String name, Result result); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/UserData.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.util.Set; 4 | 5 | public class UserData 6 | { 7 | private String _encodedId; 8 | 9 | private String _name; 10 | 11 | private Set _wonAuctions; 12 | 13 | public UserData() 14 | { 15 | } 16 | 17 | public UserData(String userId, 18 | String name, 19 | Set wonAuctions) 20 | { 21 | _encodedId = userId; 22 | _name = name; 23 | _wonAuctions = wonAuctions; 24 | } 25 | 26 | public String getEncodedId() 27 | { 28 | return _encodedId; 29 | } 30 | 31 | public String getName() 32 | { 33 | return _name; 34 | } 35 | 36 | public Set getWonAuctions() 37 | { 38 | return _wonAuctions; 39 | } 40 | 41 | @Override 42 | public String toString() 43 | { 44 | return getClass().getSimpleName() + "[" + _encodedId + "," + _name + "]"; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/UserImpl.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.nio.charset.StandardCharsets; 4 | import java.security.MessageDigest; 5 | import java.security.NoSuchAlgorithmException; 6 | import java.util.Base64; 7 | import java.util.HashSet; 8 | import java.util.logging.Logger; 9 | 10 | import io.baratine.service.Modify; 11 | import io.baratine.service.Result; 12 | import io.baratine.vault.Id; 13 | import io.baratine.vault.IdAsset; 14 | 15 | public class UserImpl implements User 16 | { 17 | private static final Logger log = Logger.getLogger(UserImpl.class.getName()); 18 | 19 | private transient MessageDigest _digest; 20 | 21 | @Id 22 | private IdAsset _id; 23 | 24 | private String _encodedId; 25 | 26 | private String _name; 27 | 28 | private String _password; 29 | private boolean _isAdmin; 30 | 31 | private HashSet _wonAuctions; 32 | 33 | public UserImpl() 34 | { 35 | } 36 | 37 | @Override 38 | @Modify 39 | public void create(AuctionUserSession.UserInitData userInitData, 40 | Result userId) 41 | { 42 | log.finer(String.format("create new user: %1$s", userInitData.getUser())); 43 | 44 | _name = userInitData.getUser(); 45 | _password = digest(userInitData.getPassword()); 46 | _isAdmin = userInitData.isAdmin(); 47 | 48 | _encodedId = _id.toString(); 49 | 50 | userId.ok(_id); 51 | } 52 | 53 | public String digest(String password) 54 | { 55 | try { 56 | if (_digest == null) 57 | _digest = MessageDigest.getInstance("SHA-1"); 58 | 59 | _digest.reset(); 60 | 61 | if (password == null) 62 | password = ""; 63 | 64 | //for production add salt 65 | _digest.update(password.getBytes(StandardCharsets.UTF_8)); 66 | 67 | String digest = Base64.getEncoder().encodeToString(_digest.digest()); 68 | 69 | return digest; 70 | } catch (NoSuchAlgorithmException e) { 71 | throw new RuntimeException(e); 72 | } 73 | } 74 | 75 | @Override 76 | public void authenticate(String password, 77 | boolean isAdmin, 78 | Result result) 79 | { 80 | boolean isAuthenticated = _password.equals(digest(password)); 81 | isAuthenticated &= (isAdmin == _isAdmin); 82 | 83 | result.ok(isAuthenticated); 84 | } 85 | 86 | @Override 87 | public void get(Result user) 88 | { 89 | user.ok(new UserData(getEncodedId(), _name, _wonAuctions)); 90 | } 91 | 92 | private String getEncodedId() 93 | { 94 | return _encodedId; 95 | } 96 | 97 | @Override 98 | public void getCreditCard(Result creditCard) 99 | { 100 | creditCard.ok(new CreditCard("visa", "4214020540356393", "222", 10, 2020)); 101 | } 102 | 103 | @Override 104 | @Modify 105 | public void addWonAuction(String auctionId, Result result) 106 | { 107 | if (_wonAuctions == null) 108 | _wonAuctions = new HashSet<>(); 109 | 110 | _wonAuctions.add(auctionId); 111 | 112 | result.ok(true); 113 | } 114 | 115 | @Override 116 | @Modify 117 | public void removeWonAuction(String auctionId, Result result) 118 | { 119 | if (_wonAuctions == null) 120 | throw new IllegalStateException(); 121 | 122 | _wonAuctions.remove(_wonAuctions); 123 | 124 | result.ok(true); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/examples/auction/UserVault.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | public interface UserVault extends UserAbstractVault 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /src/main/resources/payment.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "intent": "sale", 3 | "payer": { 4 | "payment_method": "credit_card", 5 | "funding_instruments": [ 6 | { 7 | "credit_card": { 8 | "number": "%1$s", 9 | "type": "%2$s", 10 | "expire_month": %3$d, 11 | "expire_year": %4$d, 12 | "cvv2": %5$s, 13 | "first_name": "%6$s", 14 | "last_name": "%7$s" 15 | } 16 | } 17 | ] 18 | }, 19 | "transactions": [ 20 | { 21 | "amount": { 22 | "total": "%8$s", 23 | "currency": "%9$s" 24 | }, 25 | "description": "%10$s" 26 | } 27 | ] 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/main/resources/paypal.properties.template: -------------------------------------------------------------------------------- 1 | # Copy the file into paypal.properties and fill 2 | # out with your paypal account values. 3 | # 4 | # These properties are loaded by PayPalRestLink 5 | # 6 | # 7 | app= 8 | account= 9 | client-id= 10 | secret= 11 | endpoint=api.sandbox.paypal.com 12 | 13 | -------------------------------------------------------------------------------- /src/main/resources/web/app/admin-main.js: -------------------------------------------------------------------------------- 1 | System.register(['angular2/platform/browser', 'rxjs/Rx', './app.component'], function(exports_1) { 2 | var browser_1, app_component_1; 3 | return { 4 | setters:[ 5 | function (browser_1_1) { 6 | browser_1 = browser_1_1; 7 | }, 8 | function (_1) {}, 9 | function (app_component_1_1) { 10 | app_component_1 = app_component_1_1; 11 | }], 12 | execute: function() { 13 | browser_1.bootstrap(app_component_1.AdminAppComponent); 14 | } 15 | } 16 | }); 17 | //# sourceMappingURL=admin-main.js.map -------------------------------------------------------------------------------- /src/main/resources/web/app/admin-main.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"admin-main.js","sourceRoot":"","sources":["admin-main.ts"],"names":[],"mappings":";;;;;;;;;;;;YAMA,mBAAS,CAAC,iCAAiB,CAAC,CAAC"} -------------------------------------------------------------------------------- /src/main/resources/web/app/admin-main.ts: -------------------------------------------------------------------------------- 1 | import {bootstrap} from 'angular2/platform/browser'; 2 | 3 | import 'rxjs/Rx'; 4 | 5 | import {AdminAppComponent} from './app.component'; 6 | 7 | bootstrap(AdminAppComponent); 8 | -------------------------------------------------------------------------------- /src/main/resources/web/app/app.component.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | font-size: 1.2em; 3 | color: #999; 4 | margin-bottom: 0; 5 | } 6 | 7 | h2 { 8 | font-size: 2em; 9 | margin-top: 0; 10 | padding-top: 0; 11 | } 12 | 13 | nav a { 14 | padding: 5px 10px; 15 | text-decoration: none; 16 | margin-top: 10px; 17 | display: inline-block; 18 | background-color: #eee; 19 | border-radius: 4px; 20 | } 21 | 22 | nav a:visited, a:link { 23 | color: #607D8B; 24 | } 25 | 26 | nav a:hover { 27 | color: #039be5; 28 | background-color: #CFD8DC; 29 | } 30 | 31 | nav a.router-link-active { 32 | color: #039be5; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/resources/web/app/app.component.js: -------------------------------------------------------------------------------- 1 | System.register(['angular2/core', 'angular2/http', "angular2/router", "./baseurl", './login.component', "./new-auction.component", "./auctions.component", "./user.service", "./auction.service", "./bids.component", "./auction-admin.component"], function(exports_1) { 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | var __metadata = (this && this.__metadata) || function (k, v) { 9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 10 | }; 11 | var core_1, http_1, router_1, router_2, baseurl_1, login_component_1, new_auction_component_1, auctions_component_1, user_service_1, auction_service_1, bids_component_1, auction_admin_component_1; 12 | var UserAppComponent, AdminAppComponent; 13 | return { 14 | setters:[ 15 | function (core_1_1) { 16 | core_1 = core_1_1; 17 | }, 18 | function (http_1_1) { 19 | http_1 = http_1_1; 20 | }, 21 | function (router_1_1) { 22 | router_1 = router_1_1; 23 | router_2 = router_1_1; 24 | }, 25 | function (baseurl_1_1) { 26 | baseurl_1 = baseurl_1_1; 27 | }, 28 | function (login_component_1_1) { 29 | login_component_1 = login_component_1_1; 30 | }, 31 | function (new_auction_component_1_1) { 32 | new_auction_component_1 = new_auction_component_1_1; 33 | }, 34 | function (auctions_component_1_1) { 35 | auctions_component_1 = auctions_component_1_1; 36 | }, 37 | function (user_service_1_1) { 38 | user_service_1 = user_service_1_1; 39 | }, 40 | function (auction_service_1_1) { 41 | auction_service_1 = auction_service_1_1; 42 | }, 43 | function (bids_component_1_1) { 44 | bids_component_1 = bids_component_1_1; 45 | }, 46 | function (auction_admin_component_1_1) { 47 | auction_admin_component_1 = auction_admin_component_1_1; 48 | }], 49 | execute: function() { 50 | UserAppComponent = (function () { 51 | function UserAppComponent() { 52 | this.title = 'Baratine™ Auction Application'; 53 | } 54 | UserAppComponent = __decorate([ 55 | core_1.Component({ 56 | selector: 'user-app', 57 | template: "\n

{{title}}

\n
\n \n
\n
\n \n \n
\n
\n \n
\n ", 58 | styleUrls: ['./app/app.component.css'], 59 | providers: [http_1.HTTP_PROVIDERS, 60 | router_2.ROUTER_PROVIDERS, 61 | core_1.provide(baseurl_1.BaseUrlProvider, { useClass: baseurl_1.UserUrlProvider }), 62 | auction_service_1.AuctionService, 63 | user_service_1.UserService, 64 | auctions_component_1.AuctionsComponent], 65 | directives: [router_1.ROUTER_DIRECTIVES, login_component_1.LoginComponent, new_auction_component_1.NewAuctionComponent, auctions_component_1.AuctionsComponent, bids_component_1.BidsComponent], 66 | bindings: [], 67 | }), 68 | __metadata('design:paramtypes', []) 69 | ], UserAppComponent); 70 | return UserAppComponent; 71 | })(); 72 | exports_1("UserAppComponent", UserAppComponent); 73 | AdminAppComponent = (function () { 74 | function AdminAppComponent() { 75 | this.title = 'Baratine™ Auction Admin Application'; 76 | } 77 | AdminAppComponent = __decorate([ 78 | core_1.Component({ 79 | selector: 'admin-app', 80 | template: "\n

{{title}}

\n
\n \n
\n
\n \n
\n ", 81 | styleUrls: ['./app/app.component.css'], 82 | providers: [http_1.HTTP_PROVIDERS, 83 | router_2.ROUTER_PROVIDERS, 84 | core_1.provide(baseurl_1.BaseUrlProvider, { useClass: baseurl_1.AdminUrlProvider }), 85 | user_service_1.UserService, 86 | auction_service_1.AuctionService, 87 | auctions_component_1.AuctionsComponent], 88 | directives: [router_1.ROUTER_DIRECTIVES, login_component_1.LoginComponent, auction_admin_component_1.AuctionAdminComponent], 89 | bindings: [], 90 | }), 91 | __metadata('design:paramtypes', []) 92 | ], AdminAppComponent); 93 | return AdminAppComponent; 94 | })(); 95 | exports_1("AdminAppComponent", AdminAppComponent); 96 | } 97 | } 98 | }); 99 | //# sourceMappingURL=app.component.js.map -------------------------------------------------------------------------------- /src/main/resources/web/app/app.component.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.component.js","sourceRoot":"","sources":["app.component.ts"],"names":["UserAppComponent","UserAppComponent.constructor","AdminAppComponent","AdminAppComponent.constructor"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAgBA;gBA2BEA;oBAIAC,UAAKA,GAAGA,+BAA+BA,CAACA;gBAFxCA,CAACA;gBA7BHD;oBAACA,gBAASA,CAACA;wBACEA,QAAQA,EAAEA,UAAUA;wBACpBA,QAAQA,EAAEA,uXAYTA;wBACDA,SAASA,EAAEA,CAACA,yBAAyBA,CAACA;wBACtCA,SAASA,EAAEA,CAACA,qBAAcA;4BACdA,yBAAgBA;4BAChBA,cAAOA,CAACA,yBAAeA,EAAEA,EAACA,QAAQA,EAAEA,yBAAeA,EAACA,CAACA;4BACrDA,gCAAcA;4BACdA,0BAAWA;4BACXA,sCAAiBA,CAACA;wBAC9BA,UAAUA,EAAEA,CAACA,0BAAiBA,EAAEA,gCAAcA,EAAEA,2CAAmBA,EAAEA,sCAAiBA,EAAEA,8BAAaA,CAACA;wBACtGA,QAAQA,EAAEA,EAAEA;qBACbA,CAACA;;qCASZA;gBAADA,uBAACA;YAADA,CAACA,AAjCD,IAiCC;YAjCD,+CAiCC,CAAA;YAED;gBAuBEE;oBAIAC,UAAKA,GAAGA,qCAAqCA,CAACA;gBAF9CA,CAACA;gBAzBHD;oBAACA,gBAASA,CAACA;wBACEA,QAAQA,EAAEA,WAAWA;wBACrBA,QAAQA,EAAEA,+PAQTA;wBACDA,SAASA,EAAEA,CAACA,yBAAyBA,CAACA;wBACtCA,SAASA,EAAEA,CAACA,qBAAcA;4BACdA,yBAAgBA;4BAChBA,cAAOA,CAACA,yBAAeA,EAAEA,EAACA,QAAQA,EAAEA,0BAAgBA,EAACA,CAACA;4BACtDA,0BAAWA;4BACXA,gCAAcA;4BACdA,sCAAiBA,CAACA;wBAC9BA,UAAUA,EAAEA,CAACA,0BAAiBA,EAAEA,gCAAcA,EAAEA,+CAAqBA,CAACA;wBACtEA,QAAQA,EAAEA,EAAEA;qBACbA,CAACA;;sCASZA;gBAADA,wBAACA;YAADA,CAACA,AA7BD,IA6BC;YA7BD,iDA6BC,CAAA"} -------------------------------------------------------------------------------- /src/main/resources/web/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, provide } from 'angular2/core'; 2 | import { HTTP_PROVIDERS } from 'angular2/http'; 3 | 4 | import {ROUTER_DIRECTIVES} from "angular2/router"; 5 | import {ROUTER_PROVIDERS} from "angular2/router"; 6 | 7 | import {BaseUrlProvider,UserUrlProvider,AdminUrlProvider} from "./baseurl"; 8 | import {User} from "./user"; 9 | import {LoginComponent} from './login.component'; 10 | import {NewAuctionComponent} from "./new-auction.component"; 11 | import {AuctionsComponent} from "./auctions.component"; 12 | import {UserService} from "./user.service"; 13 | import {AuctionService} from "./auction.service"; 14 | import {BidsComponent} from "./bids.component"; 15 | import {AuctionAdminComponent} from "./auction-admin.component"; 16 | 17 | @Component({ 18 | selector: 'user-app', 19 | template: ` 20 |

{{title}}

21 |
22 | 23 |
24 |
25 | 26 | 27 |
28 |
29 | 30 |
31 | `, 32 | styleUrls: ['./app/app.component.css'], 33 | providers: [HTTP_PROVIDERS, 34 | ROUTER_PROVIDERS, 35 | provide(BaseUrlProvider, {useClass: UserUrlProvider}), 36 | AuctionService, 37 | UserService, 38 | AuctionsComponent], 39 | directives: [ROUTER_DIRECTIVES, LoginComponent, NewAuctionComponent, AuctionsComponent, BidsComponent], 40 | bindings: [], 41 | }) 42 | export class UserAppComponent 43 | { 44 | constructor() 45 | { 46 | } 47 | 48 | title = 'Baratine™ Auction Application'; 49 | user:User; 50 | } 51 | 52 | @Component({ 53 | selector: 'admin-app', 54 | template: ` 55 |

{{title}}

56 |
57 | 58 |
59 |
60 | 61 |
62 | `, 63 | styleUrls: ['./app/app.component.css'], 64 | providers: [HTTP_PROVIDERS, 65 | ROUTER_PROVIDERS, 66 | provide(BaseUrlProvider, {useClass: AdminUrlProvider}), 67 | UserService, 68 | AuctionService, 69 | AuctionsComponent], 70 | directives: [ROUTER_DIRECTIVES, LoginComponent, AuctionAdminComponent], 71 | bindings: [], 72 | }) 73 | export class AdminAppComponent 74 | { 75 | constructor() 76 | { 77 | } 78 | 79 | title = 'Baratine™ Auction Admin Application'; 80 | user:User; 81 | } 82 | -------------------------------------------------------------------------------- /src/main/resources/web/app/auction-admin.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Selected Auctions

3 | 4 |
5 |
6 | 7 | 8 |
9 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | 33 |
IDTitleCurrent BidPlace A BidState
{{auction.id}}{{auction.title}}{{auction.bid}} 28 | 29 | {{auction.state}}
34 |
35 | -------------------------------------------------------------------------------- /src/main/resources/web/app/auction-admin.component.js: -------------------------------------------------------------------------------- 1 | System.register(['angular2/core', "./auction.service"], function(exports_1) { 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | var __metadata = (this && this.__metadata) || function (k, v) { 9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 10 | }; 11 | var core_1, auction_service_1; 12 | var AuctionAdminComponent; 13 | return { 14 | setters:[ 15 | function (core_1_1) { 16 | core_1 = core_1_1; 17 | }, 18 | function (auction_service_1_1) { 19 | auction_service_1 = auction_service_1_1; 20 | }], 21 | execute: function() { 22 | AuctionAdminComponent = (function () { 23 | function AuctionAdminComponent(_auctionService) { 24 | this._auctionService = _auctionService; 25 | this.auctions = []; //[{"id":"laksdfj", "title":"j test ", "bid":3, "state":"open"}]; 26 | console.log("creating new AuctionAdminComponent"); 27 | } 28 | AuctionAdminComponent.prototype.ngOnInit = function () { 29 | this._auctionService.addAuctionListener(this); 30 | }; 31 | AuctionAdminComponent.prototype.push = function (auctions) { 32 | for (var _i = 0; _i < auctions.length; _i++) { 33 | var auction = auctions[_i]; 34 | var i = this.auctions.findIndex(function (x) { return x.id == auction.id; }); 35 | if (i > -1) 36 | this.auctions[i] = auction; 37 | } 38 | for (var _a = 0; _a < auctions.length; _a++) { 39 | var auction = auctions[_a]; 40 | var i = this.auctions.findIndex(function (x) { return x.id == auction.id; }); 41 | if (i == -1) { 42 | this.auctions.push(auction); 43 | this._auctionService.subscribe(auction).subscribe(function (subscribed) { 44 | console.log("auction subscribed: " 45 | + subscribed); 46 | }, function (error) { 47 | console.error(error); 48 | }); 49 | } 50 | } 51 | }; 52 | AuctionAdminComponent.prototype.refund = function (auction) { 53 | this._auctionService.refund(auction).subscribe(function (isSuccess) { 54 | console.log("refunded: " 55 | + isSuccess); 56 | }, function (error) { 57 | console.error(error); 58 | }); 59 | return false; 60 | }; 61 | AuctionAdminComponent.prototype.onNew = function (auction) { 62 | }; 63 | AuctionAdminComponent.prototype.onUpdate = function (auctions) { 64 | for (var _i = 0; _i < auctions.length; _i++) { 65 | var auction = auctions[_i]; 66 | var i = this.auctions.findIndex(function (x) { return x.id == auction.id; }); 67 | if (i > -1) 68 | this.auctions[i] = auction; 69 | } 70 | }; 71 | AuctionAdminComponent.prototype.search = function (query) { 72 | var _this = this; 73 | this._auctionService.searchAuctions(query) 74 | .subscribe(function (result) { 75 | _this.push(result); 76 | }, function (error) { 77 | console.error(error); 78 | }); 79 | }; 80 | AuctionAdminComponent = __decorate([ 81 | core_1.Component({ 82 | selector: 'auction-admin', 83 | templateUrl: 'app/auction-admin.component.html', 84 | styleUrls: [''], 85 | providers: [], 86 | bindings: [] 87 | }), 88 | __metadata('design:paramtypes', [auction_service_1.AuctionService]) 89 | ], AuctionAdminComponent); 90 | return AuctionAdminComponent; 91 | })(); 92 | exports_1("AuctionAdminComponent", AuctionAdminComponent); 93 | } 94 | } 95 | }); 96 | //# sourceMappingURL=auction-admin.component.js.map -------------------------------------------------------------------------------- /src/main/resources/web/app/auction-admin.component.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"auction-admin.component.js","sourceRoot":"","sources":["auction-admin.component.ts"],"names":["AuctionAdminComponent","AuctionAdminComponent.constructor","AuctionAdminComponent.ngOnInit","AuctionAdminComponent.push","AuctionAdminComponent.refund","AuctionAdminComponent.onNew","AuctionAdminComponent.onUpdate","AuctionAdminComponent.search"],"mappings":"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"} -------------------------------------------------------------------------------- /src/main/resources/web/app/auction-admin.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from 'angular2/core'; 2 | import { HTTP_PROVIDERS } from 'angular2/http'; 3 | import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from 'angular2/router'; 4 | 5 | import {AuctionService} from "./auction.service"; 6 | import {Auction} from "./auction"; 7 | import {OnInit} from "angular2/core"; 8 | import {subscribeToResult} from "rxjs/util/subscribeToResult"; 9 | import {AuctionListener} from "./auction"; 10 | 11 | @Component({ 12 | selector: 'auction-admin', 13 | templateUrl: 'app/auction-admin.component.html', 14 | styleUrls: [''], 15 | providers: [], 16 | bindings: [] 17 | }) 18 | export class AuctionAdminComponent implements OnInit, AuctionListener 19 | { 20 | public auctions:Auction[] = [];//[{"id":"laksdfj", "title":"j test ", "bid":3, "state":"open"}]; 21 | 22 | constructor(private _auctionService:AuctionService) 23 | { 24 | console.log("creating new AuctionAdminComponent"); 25 | } 26 | 27 | ngOnInit():any 28 | { 29 | this._auctionService.addAuctionListener(this); 30 | } 31 | 32 | push(auctions:Auction[]) 33 | { 34 | for (var auction of auctions) { 35 | var i = this.auctions.findIndex(x =>x.id == auction.id); 36 | if (i > -1) 37 | this.auctions[i] = auction; 38 | } 39 | 40 | for (var auction of auctions) { 41 | var i = this.auctions.findIndex(x => x.id == auction.id); 42 | if (i == -1) { 43 | this.auctions.push(auction); 44 | 45 | this._auctionService.subscribe(auction).subscribe(subscribed=> 46 | { 47 | console.log( 48 | "auction subscribed: " 49 | + subscribed); 50 | }, error=> 51 | { 52 | console.error(error); 53 | }); 54 | } 55 | } 56 | } 57 | 58 | public refund(auction:Auction) 59 | { 60 | this._auctionService.refund(auction).subscribe(isSuccess=> 61 | { 62 | console.log( 63 | "refunded: " 64 | + isSuccess); 65 | }, error=> 66 | { 67 | console.error(error); 68 | }); 69 | 70 | return false; 71 | } 72 | 73 | onNew(auction:Auction) 74 | { 75 | } 76 | 77 | onUpdate(auctions:Auction[]) 78 | { 79 | for (var auction of auctions) { 80 | var i = this.auctions.findIndex(x =>x.id == auction.id); 81 | if (i > -1) 82 | this.auctions[i] = auction; 83 | } 84 | } 85 | 86 | public search(query:string) 87 | { 88 | this._auctionService.searchAuctions(query) 89 | .subscribe(result=> 90 | { 91 | this.push(result); 92 | }, error => 93 | { 94 | console.error(error); 95 | }); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/resources/web/app/auction.js: -------------------------------------------------------------------------------- 1 | System.register([], function(exports_1) { 2 | return { 3 | setters:[], 4 | execute: function() { 5 | } 6 | } 7 | }); 8 | //# sourceMappingURL=auction.js.map -------------------------------------------------------------------------------- /src/main/resources/web/app/auction.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"auction.js","sourceRoot":"","sources":["auction.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /src/main/resources/web/app/auction.service.js: -------------------------------------------------------------------------------- 1 | System.register(['angular2/core', 'angular2/http', 'rxjs/Observable', './baseurl', "angular2/src/facade/lang"], function(exports_1) { 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | var __metadata = (this && this.__metadata) || function (k, v) { 9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 10 | }; 11 | var core_1, http_1, Observable_1, baseurl_1, lang_1; 12 | var AuctionService; 13 | return { 14 | setters:[ 15 | function (core_1_1) { 16 | core_1 = core_1_1; 17 | }, 18 | function (http_1_1) { 19 | http_1 = http_1_1; 20 | }, 21 | function (Observable_1_1) { 22 | Observable_1 = Observable_1_1; 23 | }, 24 | function (baseurl_1_1) { 25 | baseurl_1 = baseurl_1_1; 26 | }, 27 | function (lang_1_1) { 28 | lang_1 = lang_1_1; 29 | }], 30 | execute: function() { 31 | AuctionService = (function () { 32 | function AuctionService(http, _baseUrlProvider) { 33 | this.http = http; 34 | this._baseUrlProvider = _baseUrlProvider; 35 | this.auctionListeners = []; 36 | console.log("creating new AuctionService: " + http); 37 | this._createUrl = _baseUrlProvider.url + "createAuction"; 38 | this._searchUrl = _baseUrlProvider.url + "searchAuctions"; 39 | this._subscribeUrl = _baseUrlProvider.url + "addAuctionListener"; 40 | this._bidUrl = _baseUrlProvider.url + "bidAuction"; 41 | this._refundUrl = _baseUrlProvider.url + "refund"; 42 | //this._auctionUpdatesUrl = _baseUrlProvider.url + "auction-updates"; 43 | this._auctionUpdatesUrl = _baseUrlProvider.wsUrl + "auction-updates"; 44 | //this._auctionUpdatesUrl = "localhost:8080/user/auction-updates"; 45 | } 46 | AuctionService.prototype.create = function (title, bid) { 47 | var urlSearchParams = new http_1.URLSearchParams(); 48 | urlSearchParams.append('t', title); 49 | urlSearchParams.append('b', bid.toString()); 50 | var body = urlSearchParams.toString(); 51 | var headers = new http_1.Headers({ 52 | 'Content-Type': 'application/x-www-form-urlencoded' 53 | }); 54 | var options = new http_1.RequestOptions({ headers: headers }); 55 | return this.http.post(this._createUrl, body, options) 56 | .map(function (res) { return res.json(); }).catch(this.handleError); 57 | }; 58 | AuctionService.prototype.searchAuctions = function (query) { 59 | var _this = this; 60 | var urlSearchParams = new http_1.URLSearchParams(); 61 | urlSearchParams.append("q", query); 62 | var url = this._searchUrl + '?' + urlSearchParams.toString(); 63 | var headers = new http_1.Headers(); 64 | var options = new http_1.RequestOptions({ headers: headers }); 65 | return this.http.get(url, options) 66 | .map(function (res) { return _this.map(res); }).catch(this.handleError); 67 | }; 68 | AuctionService.prototype.addAuctionListener = function (listener) { 69 | this.auctionListeners.push(listener); 70 | }; 71 | AuctionService.prototype.onAuctionCreate = function (auction) { 72 | for (var _i = 0, _a = this.auctionListeners; _i < _a.length; _i++) { 73 | var listener = _a[_i]; 74 | listener.onNew(auction); 75 | } 76 | }; 77 | AuctionService.prototype.subscribe = function (auction) { 78 | var body = auction.id; 79 | var headers = new http_1.Headers({ 80 | 'Content-Type': 'application/x-www-form-urlencoded' 81 | }); 82 | var options = new http_1.RequestOptions({ headers: headers }); 83 | return this.http.post(this._subscribeUrl, body, options) 84 | .map(function (res) { return res.text(); }).catch(this.handleError); 85 | }; 86 | AuctionService.prototype.bid = function (auction) { 87 | var price = auction.bid + 1; 88 | var body = lang_1.Json.stringify({ "auction": auction.id, "bid": price }); 89 | var headers = new http_1.Headers({ 90 | 'Content-Type': 'application/json' 91 | }); 92 | var options = new http_1.RequestOptions({ headers: headers }); 93 | return this.http.post(this._bidUrl, body, options) 94 | .map(function (res) { return res.text(); }).catch(this.handleError); 95 | }; 96 | AuctionService.prototype.refund = function (auction) { 97 | var headers = new http_1.Headers(); 98 | var options = new http_1.RequestOptions({ headers: headers }); 99 | return this.http.post(this._refundUrl, auction.id, options) 100 | .map(function (res) { return res.text(); }).catch(this.handleError); 101 | }; 102 | AuctionService.prototype.update = function (auctions) { 103 | for (var _i = 0, _a = this.auctionListeners; _i < _a.length; _i++) { 104 | var listener = _a[_i]; 105 | listener.onUpdate(auctions); 106 | } 107 | }; 108 | AuctionService.prototype.registerForAuctionUpdates = function () { 109 | var websocket = new WebSocket(this._auctionUpdatesUrl); 110 | var self = this; 111 | websocket.addEventListener("message", function (e) { 112 | self.auctionUpdate(self, e); 113 | }); 114 | /* 115 | var self = this; 116 | var sock = new SockJS(this._auctionUpdatesUrl, ["ws", "http", "https"]); 117 | sock.onopen = function() { 118 | console.log('open'); 119 | }; 120 | sock.onmessage = function(e) { 121 | self.auctionUpdate(self, e); 122 | }; 123 | sock.onclose = function() { 124 | console.log('close'); 125 | }; 126 | */ 127 | }; 128 | AuctionService.prototype.auctionUpdate = function (self, e) { 129 | var auction = lang_1.Json.parse(e.data); 130 | var auctions = [auction]; 131 | self.update(auctions); 132 | }; 133 | AuctionService.prototype.map = function (res) { 134 | return res.json(); 135 | }; 136 | AuctionService.prototype.handleError = function (error) { 137 | console.error(error); 138 | return Observable_1.Observable.throw(error.json().error || 'Server error'); 139 | }; 140 | AuctionService = __decorate([ 141 | core_1.Injectable(), 142 | __metadata('design:paramtypes', [http_1.Http, baseurl_1.BaseUrlProvider]) 143 | ], AuctionService); 144 | return AuctionService; 145 | })(); 146 | exports_1("AuctionService", AuctionService); 147 | } 148 | } 149 | }); 150 | //# sourceMappingURL=auction.service.js.map -------------------------------------------------------------------------------- /src/main/resources/web/app/auction.service.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"auction.service.js","sourceRoot":"","sources":["auction.service.ts"],"names":["AuctionService","AuctionService.constructor","AuctionService.create","AuctionService.searchAuctions","AuctionService.addAuctionListener","AuctionService.onAuctionCreate","AuctionService.subscribe","AuctionService.bid","AuctionService.refund","AuctionService.update","AuctionService.registerForAuctionUpdates","AuctionService.auctionUpdate","AuctionService.map","AuctionService.handleError"],"mappings":"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"} -------------------------------------------------------------------------------- /src/main/resources/web/app/auction.service.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from 'angular2/core'; 2 | import {Http, Response, Headers, RequestOptions, URLSearchParams} from 'angular2/http'; 3 | import {Observable} from 'rxjs/Observable'; 4 | 5 | import {BaseUrlProvider} from './baseurl'; 6 | import {Auction, AuctionListener} from './auction'; 7 | import {Request} from "angular2/http"; 8 | import {Json} from "angular2/src/facade/lang"; 9 | import {OnInit} from "angular2/core"; 10 | 11 | @Injectable() 12 | export class AuctionService 13 | { 14 | private auctionListeners:AuctionListener[] = []; 15 | 16 | private _createUrl; 17 | private _searchUrl; 18 | private _subscribeUrl; 19 | private _bidUrl; 20 | private _refundUrl; 21 | private _auctionUpdatesUrl; 22 | 23 | constructor(private http:Http, private _baseUrlProvider:BaseUrlProvider) 24 | { 25 | console.log("creating new AuctionService: " + http); 26 | this._createUrl = _baseUrlProvider.url + "createAuction"; 27 | this._searchUrl = _baseUrlProvider.url + "searchAuctions"; 28 | this._subscribeUrl = _baseUrlProvider.url + "addAuctionListener"; 29 | this._bidUrl = _baseUrlProvider.url + "bidAuction"; 30 | this._refundUrl = _baseUrlProvider.url + "refund"; 31 | //this._auctionUpdatesUrl = _baseUrlProvider.url + "auction-updates"; 32 | this._auctionUpdatesUrl = _baseUrlProvider.wsUrl + "auction-updates"; 33 | //this._auctionUpdatesUrl = "localhost:8080/user/auction-updates"; 34 | } 35 | 36 | public create(title:string, bid:number) 37 | { 38 | let urlSearchParams = new URLSearchParams(); 39 | urlSearchParams.append('t', title); 40 | urlSearchParams.append('b', bid.toString()); 41 | 42 | let body = urlSearchParams.toString(); 43 | 44 | let headers = new Headers({ 45 | 'Content-Type': 'application/x-www-form-urlencoded' 46 | }); 47 | let options = new RequestOptions({headers: headers}); 48 | 49 | return this.http.post(this._createUrl, body, options) 50 | .map(res=>res.json()).catch(this.handleError); 51 | } 52 | 53 | public searchAuctions(query:string) 54 | { 55 | let urlSearchParams = new URLSearchParams(); 56 | urlSearchParams.append("q", query); 57 | let url = this._searchUrl + '?' + urlSearchParams.toString(); 58 | 59 | let headers = new Headers(); 60 | let options = new RequestOptions({headers: headers}); 61 | 62 | return this.http.get(url, options) 63 | .map(res=>this.map(res)).catch(this.handleError); 64 | } 65 | 66 | public addAuctionListener(listener:AuctionListener) 67 | { 68 | this.auctionListeners.push(listener); 69 | } 70 | 71 | public onAuctionCreate(auction:Auction) 72 | { 73 | for (var listener of this.auctionListeners) 74 | listener.onNew(auction); 75 | } 76 | 77 | public subscribe(auction:Auction) 78 | { 79 | let body = auction.id; 80 | 81 | let headers = new Headers({ 82 | 'Content-Type': 'application/x-www-form-urlencoded' 83 | }); 84 | let options = new RequestOptions({headers: headers}); 85 | 86 | return this.http.post(this._subscribeUrl, body, options) 87 | .map(res=>res.text()).catch(this.handleError); 88 | } 89 | 90 | public bid(auction:Auction) 91 | { 92 | let price = auction.bid + 1; 93 | let body = Json.stringify({"auction": auction.id, "bid": price}); 94 | 95 | let headers = new Headers({ 96 | 'Content-Type': 'application/json' 97 | }); 98 | let options = new RequestOptions({headers: headers}); 99 | 100 | return this.http.post(this._bidUrl, body, options) 101 | .map(res=>res.text()).catch(this.handleError); 102 | } 103 | 104 | public refund(auction:Auction) 105 | { 106 | let headers = new Headers(); 107 | let options = new RequestOptions({headers: headers}); 108 | 109 | return this.http.post(this._refundUrl, auction.id, options) 110 | .map(res=>res.text()).catch(this.handleError); 111 | } 112 | 113 | public update(auctions:Auction[]) 114 | { 115 | for (var listener of this.auctionListeners) 116 | listener.onUpdate(auctions); 117 | } 118 | 119 | public registerForAuctionUpdates() 120 | { 121 | var websocket = new WebSocket(this._auctionUpdatesUrl); 122 | 123 | var self = this; 124 | 125 | websocket.addEventListener("message", function (e:MessageEvent) 126 | { 127 | self.auctionUpdate(self, e); 128 | }); 129 | 130 | /* 131 | var self = this; 132 | var sock = new SockJS(this._auctionUpdatesUrl, ["ws", "http", "https"]); 133 | sock.onopen = function() { 134 | console.log('open'); 135 | }; 136 | sock.onmessage = function(e) { 137 | self.auctionUpdate(self, e); 138 | }; 139 | sock.onclose = function() { 140 | console.log('close'); 141 | }; 142 | */ 143 | } 144 | 145 | private auctionUpdate(self:AuctionService, e:MessageEvent) 146 | { 147 | var auction = Json.parse(e.data); 148 | var auctions:Auction[] = [auction]; 149 | 150 | self.update(auctions); 151 | } 152 | 153 | private map(res:Response) 154 | { 155 | return res.json(); 156 | } 157 | 158 | private handleError(error:Response) 159 | { 160 | console.error(error); 161 | return Observable.throw(error.json().error || 'Server error'); 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/main/resources/web/app/auction.ts: -------------------------------------------------------------------------------- 1 | export interface Auction 2 | { 3 | id: string; 4 | title: string; 5 | bid: number; 6 | state: string; 7 | } 8 | 9 | export interface AuctionListener 10 | { 11 | onNew(auction:Auction); 12 | 13 | onUpdate(auctions:Auction[]); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/main/resources/web/app/auctions.component.html: -------------------------------------------------------------------------------- 1 |
2 |

My Auctions

3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
IDTitleCurrent BidState
{{auction.id}}{{auction.title}}{{auction.bid}}{{auction.state}}
20 |
21 | -------------------------------------------------------------------------------- /src/main/resources/web/app/auctions.component.js: -------------------------------------------------------------------------------- 1 | System.register(['angular2/core', "./auction.service"], function(exports_1) { 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | var __metadata = (this && this.__metadata) || function (k, v) { 9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 10 | }; 11 | var core_1, auction_service_1; 12 | var AuctionsComponent; 13 | return { 14 | setters:[ 15 | function (core_1_1) { 16 | core_1 = core_1_1; 17 | }, 18 | function (auction_service_1_1) { 19 | auction_service_1 = auction_service_1_1; 20 | }], 21 | execute: function() { 22 | AuctionsComponent = (function () { 23 | function AuctionsComponent(_auctionService) { 24 | this._auctionService = _auctionService; 25 | this.auctions = []; 26 | console.log("creating new AuctionsComponent"); 27 | } 28 | AuctionsComponent.prototype.ngOnInit = function () { 29 | this._auctionService.addAuctionListener(this); 30 | }; 31 | AuctionsComponent.prototype.onNew = function (auction) { 32 | console.log(auction); 33 | this.auctions.push(auction); 34 | }; 35 | AuctionsComponent.prototype.onUpdate = function (auctions) { 36 | for (var _i = 0; _i < auctions.length; _i++) { 37 | var auction = auctions[_i]; 38 | var i = this.auctions.findIndex(function (x) { return x.id == auction.id; }); 39 | if (i > -1) 40 | this.auctions[i] = auction; 41 | } 42 | }; 43 | AuctionsComponent = __decorate([ 44 | core_1.Component({ 45 | selector: 'auctions', 46 | templateUrl: 'app/auctions.component.html', 47 | styleUrls: [''], 48 | providers: [], 49 | bindings: [] 50 | }), 51 | __metadata('design:paramtypes', [auction_service_1.AuctionService]) 52 | ], AuctionsComponent); 53 | return AuctionsComponent; 54 | })(); 55 | exports_1("AuctionsComponent", AuctionsComponent); 56 | } 57 | } 58 | }); 59 | //# sourceMappingURL=auctions.component.js.map -------------------------------------------------------------------------------- /src/main/resources/web/app/auctions.component.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"auctions.component.js","sourceRoot":"","sources":["auctions.component.ts"],"names":["AuctionsComponent","AuctionsComponent.constructor","AuctionsComponent.ngOnInit","AuctionsComponent.onNew","AuctionsComponent.onUpdate"],"mappings":";;;;;;;;;;;;;;;;;;;;;YASA;gBAWEA,2BAAoBA,eAA8BA;oBAA9BC,oBAAeA,GAAfA,eAAeA,CAAeA;oBAF3CA,aAAQA,GAAaA,EAAEA,CAACA;oBAI7BA,OAAOA,CAACA,GAAGA,CAACA,gCAAgCA,CAACA,CAACA;gBAChDA,CAACA;gBAEDD,oCAAQA,GAARA;oBAEEE,IAAIA,CAACA,eAAeA,CAACA,kBAAkBA,CAACA,IAAIA,CAACA,CAACA;gBAEhDA,CAACA;gBAEDF,iCAAKA,GAALA,UAAMA,OAAeA;oBAEnBG,OAAOA,CAACA,GAAGA,CAACA,OAAOA,CAACA,CAACA;oBACrBA,IAAIA,CAACA,QAAQA,CAACA,IAAIA,CAACA,OAAOA,CAACA,CAACA;gBAC9BA,CAACA;gBAEDH,oCAAQA,GAARA,UAASA,QAAkBA;oBAEzBI,GAAGA,CAACA,CAAgBA,UAAQA,EAAvBA,oBAAWA,EAAXA,IAAuBA,CAACA;wBAAxBA,IAAIA,OAAOA,GAAIA,QAAQA,IAAZA;wBACdA,IAAIA,CAACA,GAAGA,IAAIA,CAACA,QAAQA,CAACA,SAASA,CAACA,UAAAA,CAACA,IAAGA,OAAAA,CAACA,CAACA,EAAEA,IAAIA,OAAOA,CAACA,EAAEA,EAAlBA,CAAkBA,CAACA,CAACA;wBACxDA,EAAEA,CAACA,CAACA,CAACA,GAAGA,CAACA,CAACA,CAACA;4BACTA,IAAIA,CAACA,QAAQA,CAACA,CAACA,CAACA,GAAGA,OAAOA,CAACA;qBAC9BA;gBACHA,CAACA;gBAnCHJ;oBAACA,gBAASA,CAACA;wBACEA,QAAQA,EAAEA,UAAUA;wBACpBA,WAAWA,EAAEA,6BAA6BA;wBAC1CA,SAASA,EAAEA,CAACA,EAAEA,CAACA;wBACfA,SAASA,EAAEA,EAAEA;wBACbA,QAAQA,EAAEA,EAAEA;qBACbA,CAACA;;sCA8BZA;gBAADA,wBAACA;YAADA,CAACA,AApCD,IAoCC;YApCD,iDAoCC,CAAA"} -------------------------------------------------------------------------------- /src/main/resources/web/app/auctions.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from 'angular2/core'; 2 | import { HTTP_PROVIDERS } from 'angular2/http'; 3 | import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from 'angular2/router'; 4 | 5 | import {AuctionService} from "./auction.service"; 6 | import {Auction} from "./auction"; 7 | import {AuctionListener} from "./auction"; 8 | import {OnInit} from "angular2/core"; 9 | 10 | @Component({ 11 | selector: 'auctions', 12 | templateUrl: 'app/auctions.component.html', 13 | styleUrls: [''], 14 | providers: [], 15 | bindings: [] 16 | }) 17 | export class AuctionsComponent implements AuctionListener, OnInit 18 | { 19 | public auctions:Auction[] = []; 20 | 21 | constructor(private _auctionService:AuctionService) 22 | { 23 | console.log("creating new AuctionsComponent"); 24 | } 25 | 26 | ngOnInit():any 27 | { 28 | this._auctionService.addAuctionListener(this); 29 | 30 | } 31 | 32 | onNew(auction:Auction) 33 | { 34 | console.log(auction); 35 | this.auctions.push(auction); 36 | } 37 | 38 | onUpdate(auctions:Auction[]) 39 | { 40 | for (var auction of auctions) { 41 | var i = this.auctions.findIndex(x =>x.id == auction.id); 42 | if (i > -1) 43 | this.auctions[i] = auction; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/resources/web/app/baseurl.js: -------------------------------------------------------------------------------- 1 | System.register(['angular2/core'], function(exports_1) { 2 | var __extends = (this && this.__extends) || function (d, b) { 3 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; 4 | function __() { this.constructor = d; } 5 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 6 | }; 7 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 8 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 9 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 10 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 11 | return c > 3 && r && Object.defineProperty(target, key, r), r; 12 | }; 13 | var __metadata = (this && this.__metadata) || function (k, v) { 14 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 15 | }; 16 | var core_1; 17 | var BaseUrlProvider, UserUrlProvider, AdminUrlProvider; 18 | return { 19 | setters:[ 20 | function (core_1_1) { 21 | core_1 = core_1_1; 22 | }], 23 | execute: function() { 24 | BaseUrlProvider = (function () { 25 | function BaseUrlProvider() { 26 | } 27 | BaseUrlProvider.prototype.ngOnInit = function () { 28 | console.log("BaseUrlProvider Init " + window); 29 | }; 30 | BaseUrlProvider = __decorate([ 31 | core_1.Injectable(), 32 | __metadata('design:paramtypes', []) 33 | ], BaseUrlProvider); 34 | return BaseUrlProvider; 35 | })(); 36 | exports_1("BaseUrlProvider", BaseUrlProvider); 37 | UserUrlProvider = (function (_super) { 38 | __extends(UserUrlProvider, _super); 39 | function UserUrlProvider() { 40 | _super.call(this); 41 | this.url = "http://" + window.location.host + "/user/"; 42 | this.wsUrl = "ws://" + window.location.host + "/user/"; 43 | } 44 | UserUrlProvider = __decorate([ 45 | core_1.Injectable(), 46 | __metadata('design:paramtypes', []) 47 | ], UserUrlProvider); 48 | return UserUrlProvider; 49 | })(BaseUrlProvider); 50 | exports_1("UserUrlProvider", UserUrlProvider); 51 | AdminUrlProvider = (function (_super) { 52 | __extends(AdminUrlProvider, _super); 53 | function AdminUrlProvider() { 54 | _super.call(this); 55 | this.url = "http://" + window.location.host + "/admin/"; 56 | this.wsUrl = "ws://" + window.location.host + "/admin/"; 57 | } 58 | AdminUrlProvider = __decorate([ 59 | core_1.Injectable(), 60 | __metadata('design:paramtypes', []) 61 | ], AdminUrlProvider); 62 | return AdminUrlProvider; 63 | })(BaseUrlProvider); 64 | exports_1("AdminUrlProvider", AdminUrlProvider); 65 | } 66 | } 67 | }); 68 | //# sourceMappingURL=baseurl.js.map -------------------------------------------------------------------------------- /src/main/resources/web/app/baseurl.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"baseurl.js","sourceRoot":"","sources":["baseurl.ts"],"names":["BaseUrlProvider","BaseUrlProvider.constructor","BaseUrlProvider.ngOnInit","UserUrlProvider","UserUrlProvider.constructor","AdminUrlProvider","AdminUrlProvider.constructor"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;YAEA;gBAAAA;gBAUAC,CAACA;gBAJCD,kCAAQA,GAARA;oBAEEE,OAAOA,CAACA,GAAGA,CAACA,uBAAuBA,GAAGA,MAAMA,CAACA,CAACA;gBAChDA,CAACA;gBATHF;oBAACA,iBAAUA,EAAEA;;oCAUZA;gBAADA,sBAACA;YAADA,CAACA,AAVD,IAUC;YAVD,6CAUC,CAAA;YAED;gBACqCG,mCAAeA;gBAElDA;oBAEEC,iBAAOA,CAACA;oBAERA,IAAIA,CAACA,GAAGA,GAAGA,SAASA,GAAGA,MAAMA,CAACA,QAAQA,CAACA,IAAIA,GAAGA,QAAQA,CAACA;oBACvDA,IAAIA,CAACA,KAAKA,GAAGA,OAAOA,GAAGA,MAAMA,CAACA,QAAQA,CAACA,IAAIA,GAAGA,QAAQA,CAACA;gBACzDA,CAACA;gBATHD;oBAACA,iBAAUA,EAAEA;;oCAUZA;gBAADA,sBAACA;YAADA,CAACA,AAVD,EACqC,eAAe,EASnD;YAVD,6CAUC,CAAA;YAED;gBACsCE,oCAAeA;gBAEnDA;oBAEEC,iBAAOA,CAACA;oBAERA,IAAIA,CAACA,GAAGA,GAAGA,SAASA,GAAGA,MAAMA,CAACA,QAAQA,CAACA,IAAIA,GAAGA,SAASA,CAACA;oBACxDA,IAAIA,CAACA,KAAKA,GAAGA,OAAOA,GAAGA,MAAMA,CAACA,QAAQA,CAACA,IAAIA,GAAGA,SAASA,CAACA;gBAC1DA,CAACA;gBATHD;oBAACA,iBAAUA,EAAEA;;qCAUZA;gBAADA,uBAACA;YAADA,CAACA,AAVD,EACsC,eAAe,EASpD;YAVD,+CAUC,CAAA"} -------------------------------------------------------------------------------- /src/main/resources/web/app/baseurl.ts: -------------------------------------------------------------------------------- 1 | import {Injectable, OnInit} from 'angular2/core'; 2 | 3 | @Injectable() 4 | export class BaseUrlProvider 5 | { 6 | public url:string; 7 | public wsUrl:string; 8 | 9 | ngOnInit():any 10 | { 11 | console.log("BaseUrlProvider Init " + window); 12 | } 13 | } 14 | 15 | @Injectable() 16 | export class UserUrlProvider extends BaseUrlProvider 17 | { 18 | constructor() 19 | { 20 | super(); 21 | 22 | this.url = "http://" + window.location.host + "/user/"; 23 | this.wsUrl = "ws://" + window.location.host + "/user/"; 24 | } 25 | } 26 | 27 | @Injectable() 28 | export class AdminUrlProvider extends BaseUrlProvider 29 | { 30 | constructor() 31 | { 32 | super(); 33 | 34 | this.url = "http://" + window.location.host + "/admin/"; 35 | this.wsUrl = "ws://" + window.location.host + "/admin/"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/resources/web/app/bids.component.html: -------------------------------------------------------------------------------- 1 |
2 |

My Bids

3 | 4 |
5 |
6 | 7 | 8 |
9 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | 33 |
IDTitleCurrent BidPlace A BidState
{{bid.id}}{{bid.title}}{{bid.bid}} 28 | 29 | {{bid.state}}
34 |
35 | -------------------------------------------------------------------------------- /src/main/resources/web/app/bids.component.js: -------------------------------------------------------------------------------- 1 | System.register(['angular2/core', "./auction.service"], function(exports_1) { 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | var __metadata = (this && this.__metadata) || function (k, v) { 9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 10 | }; 11 | var core_1, auction_service_1; 12 | var BidsComponent; 13 | return { 14 | setters:[ 15 | function (core_1_1) { 16 | core_1 = core_1_1; 17 | }, 18 | function (auction_service_1_1) { 19 | auction_service_1 = auction_service_1_1; 20 | }], 21 | execute: function() { 22 | BidsComponent = (function () { 23 | function BidsComponent(_auctionService) { 24 | this._auctionService = _auctionService; 25 | this.bids = []; //[{"id":"laksdfj", "title":"j test ", "bid":3, "state":"open"}]; 26 | console.log("creating new BidsComponent"); 27 | } 28 | BidsComponent.prototype.ngOnInit = function () { 29 | this._auctionService.addAuctionListener(this); 30 | }; 31 | BidsComponent.prototype.push = function (bids) { 32 | for (var _i = 0; _i < bids.length; _i++) { 33 | var bid = bids[_i]; 34 | var i = this.bids.findIndex(function (x) { return x.id == bid.id; }); 35 | if (i > -1) 36 | this.bids[i] = bid; 37 | } 38 | for (var _a = 0; _a < bids.length; _a++) { 39 | var bid = bids[_a]; 40 | var i = this.bids.findIndex(function (x) { return x.id == bid.id; }); 41 | if (i == -1) 42 | this.bids.push(bid); 43 | } 44 | }; 45 | BidsComponent.prototype.placeBid = function (bid) { 46 | this._auctionService.subscribe(bid).subscribe(function (subscribed) { 47 | console.log("auction subscribed: " 48 | + subscribed); 49 | }, function (error) { 50 | console.error(error); 51 | }); 52 | this._auctionService.bid(bid).subscribe(function (isAccepted) { 53 | console.log("bid accepted: " 54 | + isAccepted); 55 | }, function (error) { 56 | console.error(error); 57 | }); 58 | return false; 59 | }; 60 | BidsComponent.prototype.onNew = function (auction) { 61 | }; 62 | BidsComponent.prototype.onUpdate = function (auctions) { 63 | for (var _i = 0; _i < auctions.length; _i++) { 64 | var bid = auctions[_i]; 65 | var i = this.bids.findIndex(function (x) { return x.id == bid.id; }); 66 | if (i > -1) 67 | this.bids[i] = bid; 68 | } 69 | }; 70 | BidsComponent.prototype.search = function (query) { 71 | var _this = this; 72 | this._auctionService.searchAuctions(query) 73 | .subscribe(function (result) { 74 | _this.push(result); 75 | }, function (error) { 76 | console.error(error); 77 | }); 78 | }; 79 | BidsComponent = __decorate([ 80 | core_1.Component({ 81 | selector: 'bids', 82 | templateUrl: 'app/bids.component.html', 83 | styleUrls: [''], 84 | providers: [], 85 | bindings: [] 86 | }), 87 | __metadata('design:paramtypes', [auction_service_1.AuctionService]) 88 | ], BidsComponent); 89 | return BidsComponent; 90 | })(); 91 | exports_1("BidsComponent", BidsComponent); 92 | } 93 | } 94 | }); 95 | //# sourceMappingURL=bids.component.js.map -------------------------------------------------------------------------------- /src/main/resources/web/app/bids.component.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"bids.component.js","sourceRoot":"","sources":["bids.component.ts"],"names":["BidsComponent","BidsComponent.constructor","BidsComponent.ngOnInit","BidsComponent.push","BidsComponent.placeBid","BidsComponent.onNew","BidsComponent.onUpdate","BidsComponent.search"],"mappings":";;;;;;;;;;;;;;;;;;;;;YAUA;gBAWEA,uBAAoBA,eAA8BA;oBAA9BC,oBAAeA,GAAfA,eAAeA,CAAeA;oBAF3CA,SAAIA,GAAaA,EAAEA,CAACA,CAAAA,iEAAiEA;oBAI1FA,OAAOA,CAACA,GAAGA,CAACA,4BAA4BA,CAACA,CAACA;gBAC5CA,CAACA;gBAEDD,gCAAQA,GAARA;oBAEEE,IAAIA,CAACA,eAAeA,CAACA,kBAAkBA,CAACA,IAAIA,CAACA,CAACA;gBAChDA,CAACA;gBAEDF,4BAAIA,GAAJA,UAAKA,IAAcA;oBAEjBG,GAAGA,CAACA,CAAYA,UAAIA,EAAfA,gBAAOA,EAAPA,IAAeA,CAACA;wBAAhBA,IAAIA,GAAGA,GAAIA,IAAIA,IAARA;wBACVA,IAAIA,CAACA,GAAGA,IAAIA,CAACA,IAAIA,CAACA,SAASA,CAACA,UAAAA,CAACA,IAAGA,OAAAA,CAACA,CAACA,EAAEA,IAAIA,GAAGA,CAACA,EAAEA,EAAdA,CAAcA,CAACA,CAACA;wBAChDA,EAAEA,CAACA,CAACA,CAACA,GAAGA,CAACA,CAACA,CAACA;4BACTA,IAAIA,CAACA,IAAIA,CAACA,CAACA,CAACA,GAAGA,GAAGA,CAACA;qBACtBA;oBAEDA,GAAGA,CAACA,CAAYA,UAAIA,EAAfA,gBAAOA,EAAPA,IAAeA,CAACA;wBAAhBA,IAAIA,GAAGA,GAAIA,IAAIA,IAARA;wBACVA,IAAIA,CAACA,GAAGA,IAAIA,CAACA,IAAIA,CAACA,SAASA,CAACA,UAAAA,CAACA,IAAIA,OAAAA,CAACA,CAACA,EAAEA,IAAIA,GAAGA,CAACA,EAAEA,EAAdA,CAAcA,CAACA,CAACA;wBACjDA,EAAEA,CAACA,CAACA,CAACA,IAAIA,CAACA,CAACA,CAACA;4BACVA,IAAIA,CAACA,IAAIA,CAACA,IAAIA,CAACA,GAAGA,CAACA,CAACA;qBACvBA;gBACHA,CAACA;gBAEMH,gCAAQA,GAAfA,UAAgBA,GAAWA;oBAEzBI,IAAIA,CAACA,eAAeA,CAACA,SAASA,CAACA,GAAGA,CAACA,CAACA,SAASA,CAACA,UAAAA,UAAUA;wBAERA,OAAOA,CAACA,GAAGA,CACTA,sBAAsBA;8BACpBA,UAAUA,CAACA,CAACA;oBAClBA,CAACA,EAAEA,UAAAA,KAAKA;wBAENA,OAAOA,CAACA,KAAKA,CAACA,KAAKA,CAACA,CAACA;oBACvBA,CAACA,CAACA,CAACA;oBAEjDA,IAAIA,CAACA,eAAeA,CAACA,GAAGA,CAACA,GAAGA,CAACA,CAACA,SAASA,CAACA,UAAAA,UAAUA;wBAERA,OAAOA,CAACA,GAAGA,CAACA,gBAAgBA;8BACdA,UAAUA,CAACA,CAACA;oBAC5BA,CAACA,EAAEA,UAAAA,KAAKA;wBAENA,OAAOA,CAACA,KAAKA,CAACA,KAAKA,CAACA,CAACA;oBACvBA,CAACA,CAACA,CAACA;oBAE3CA,MAAMA,CAACA,KAAKA,CAACA;gBACfA,CAACA;gBAEDJ,6BAAKA,GAALA,UAAMA,OAAeA;gBAErBK,CAACA;gBAEDL,gCAAQA,GAARA,UAASA,QAAkBA;oBAEzBM,GAAGA,CAACA,CAAYA,UAAQA,EAAnBA,oBAAOA,EAAPA,IAAmBA,CAACA;wBAApBA,IAAIA,GAAGA,GAAIA,QAAQA,IAAZA;wBACVA,IAAIA,CAACA,GAAGA,IAAIA,CAACA,IAAIA,CAACA,SAASA,CAACA,UAAAA,CAACA,IAAGA,OAAAA,CAACA,CAACA,EAAEA,IAAIA,GAAGA,CAACA,EAAEA,EAAdA,CAAcA,CAACA,CAACA;wBAChDA,EAAEA,CAACA,CAACA,CAACA,GAAGA,CAACA,CAACA,CAACA;4BACTA,IAAIA,CAACA,IAAIA,CAACA,CAACA,CAACA,GAAGA,GAAGA,CAACA;qBACtBA;gBACHA,CAACA;gBAEMN,8BAAMA,GAAbA,UAAcA,KAAYA;oBAA1BO,iBAUCA;oBARCA,IAAIA,CAACA,eAAeA,CAACA,cAAcA,CAACA,KAAKA,CAACA;yBACvCA,SAASA,CAACA,UAAAA,MAAMA;wBAEJA,KAAIA,CAACA,IAAIA,CAACA,MAAMA,CAACA,CAACA;oBACpBA,CAACA,EAAEA,UAAAA,KAAKA;wBAENA,OAAOA,CAACA,KAAKA,CAACA,KAAKA,CAACA,CAACA;oBACvBA,CAACA,CAACA,CAACA;gBAClBA,CAACA;gBAnFHP;oBAACA,gBAASA,CAACA;wBACEA,QAAQA,EAAEA,MAAMA;wBAChBA,WAAWA,EAAEA,yBAAyBA;wBACtCA,SAASA,EAAEA,CAACA,EAAEA,CAACA;wBACfA,SAASA,EAAEA,EAAEA;wBACbA,QAAQA,EAAEA,EAAEA;qBACbA,CAACA;;kCA8EZA;gBAADA,oBAACA;YAADA,CAACA,AApFD,IAoFC;YApFD,yCAoFC,CAAA"} -------------------------------------------------------------------------------- /src/main/resources/web/app/bids.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from 'angular2/core'; 2 | import { HTTP_PROVIDERS } from 'angular2/http'; 3 | import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from 'angular2/router'; 4 | 5 | import {AuctionService} from "./auction.service"; 6 | import {Auction} from "./auction"; 7 | import {OnInit} from "angular2/core"; 8 | import {subscribeToResult} from "rxjs/util/subscribeToResult"; 9 | import {AuctionListener} from "./auction"; 10 | 11 | @Component({ 12 | selector: 'bids', 13 | templateUrl: 'app/bids.component.html', 14 | styleUrls: [''], 15 | providers: [], 16 | bindings: [] 17 | }) 18 | export class BidsComponent implements OnInit, AuctionListener 19 | { 20 | public bids:Auction[] = [];//[{"id":"laksdfj", "title":"j test ", "bid":3, "state":"open"}]; 21 | 22 | constructor(private _auctionService:AuctionService) 23 | { 24 | console.log("creating new BidsComponent"); 25 | } 26 | 27 | ngOnInit():any 28 | { 29 | this._auctionService.addAuctionListener(this); 30 | } 31 | 32 | push(bids:Auction[]) 33 | { 34 | for (var bid of bids) { 35 | var i = this.bids.findIndex(x =>x.id == bid.id); 36 | if (i > -1) 37 | this.bids[i] = bid; 38 | } 39 | 40 | for (var bid of bids) { 41 | var i = this.bids.findIndex(x => x.id == bid.id); 42 | if (i == -1) 43 | this.bids.push(bid); 44 | } 45 | } 46 | 47 | public placeBid(bid:Auction) 48 | { 49 | this._auctionService.subscribe(bid).subscribe(subscribed=> 50 | { 51 | console.log( 52 | "auction subscribed: " 53 | + subscribed); 54 | }, error=> 55 | { 56 | console.error(error); 57 | }); 58 | 59 | this._auctionService.bid(bid).subscribe(isAccepted=> 60 | { 61 | console.log("bid accepted: " 62 | + isAccepted); 63 | }, error=> 64 | { 65 | console.error(error); 66 | }); 67 | 68 | return false; 69 | } 70 | 71 | onNew(auction:Auction) 72 | { 73 | } 74 | 75 | onUpdate(auctions:Auction[]) 76 | { 77 | for (var bid of auctions) { 78 | var i = this.bids.findIndex(x =>x.id == bid.id); 79 | if (i > -1) 80 | this.bids[i] = bid; 81 | } 82 | } 83 | 84 | public search(query:string) 85 | { 86 | this._auctionService.searchAuctions(query) 87 | .subscribe(result=> 88 | { 89 | this.push(result); 90 | }, error => 91 | { 92 | console.error(error); 93 | }); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/resources/web/app/login.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Login or Register

3 |
4 |
5 | 6 | 7 |
8 |
9 | 10 | 12 |
13 |
14 | 17 | 20 | {{message}} 21 |
22 |
23 |
-------------------------------------------------------------------------------- /src/main/resources/web/app/login.component.js: -------------------------------------------------------------------------------- 1 | System.register(['angular2/core', './user.service', "./auction.service"], function(exports_1) { 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | var __metadata = (this && this.__metadata) || function (k, v) { 9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 10 | }; 11 | var core_1, user_service_1, auction_service_1; 12 | var LoginComponent; 13 | return { 14 | setters:[ 15 | function (core_1_1) { 16 | core_1 = core_1_1; 17 | }, 18 | function (user_service_1_1) { 19 | user_service_1 = user_service_1_1; 20 | }, 21 | function (auction_service_1_1) { 22 | auction_service_1 = auction_service_1_1; 23 | }], 24 | execute: function() { 25 | LoginComponent = (function () { 26 | function LoginComponent(_userService, _auctionService) { 27 | this._userService = _userService; 28 | this._auctionService = _auctionService; 29 | } 30 | LoginComponent.prototype.login = function (user, password) { 31 | var _this = this; 32 | this._userService.login(user, password).subscribe(function (loggedIn) { 33 | console.log("login: " + loggedIn); 34 | if (loggedIn === "true") { 35 | _this.message = "login successful: " + user; 36 | _this._auctionService.registerForAuctionUpdates(); 37 | } 38 | else { 39 | _this.message = "login failed."; 40 | } 41 | }, function (error) { 42 | console.error(error); 43 | _this.message = "login failed: " + error; 44 | }); 45 | }; 46 | LoginComponent.prototype.create = function (user, password) { 47 | this._userService.create(user, password).subscribe(function (user) { 48 | console.log(user); 49 | }, function (error) { 50 | console.error(error); 51 | }); 52 | }; 53 | LoginComponent = __decorate([ 54 | core_1.Component({ 55 | selector: 'login-form', 56 | templateUrl: 'app/login.component.html', 57 | styleUrls: [''], 58 | bindings: [user_service_1.UserService] 59 | }), 60 | __metadata('design:paramtypes', [user_service_1.UserService, auction_service_1.AuctionService]) 61 | ], LoginComponent); 62 | return LoginComponent; 63 | })(); 64 | exports_1("LoginComponent", LoginComponent); 65 | } 66 | } 67 | }); 68 | //# sourceMappingURL=login.component.js.map -------------------------------------------------------------------------------- /src/main/resources/web/app/login.component.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"login.component.js","sourceRoot":"","sources":["login.component.ts"],"names":["LoginComponent","LoginComponent.constructor","LoginComponent.login","LoginComponent.create"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;YAQA;gBAWEA,wBAAoBA,YAAwBA,EAAUA,eAA8BA;oBAAhEC,iBAAYA,GAAZA,YAAYA,CAAYA;oBAAUA,oBAAeA,GAAfA,eAAeA,CAAeA;gBAEpFA,CAACA;gBAEDD,8BAAKA,GAALA,UAAMA,IAAWA,EAAEA,QAAeA;oBAAlCE,iBAsBCA;oBApBCA,IAAIA,CAACA,YAAYA,CAACA,KAAKA,CAACA,IAAIA,EAAEA,QAAQA,CAACA,CAACA,SAASA,CAC/CA,UAAAA,QAAQA;wBAENA,OAAOA,CAACA,GAAGA,CAACA,SAASA,GAAGA,QAAQA,CAACA,CAACA;wBAElCA,EAAEA,CAACA,CAACA,QAAQA,KAAKA,MAAMA,CAACA,CAACA,CAACA;4BACxBA,KAAIA,CAACA,OAAOA,GAAGA,oBAAoBA,GAAGA,IAAIA,CAACA;4BAE3CA,KAAIA,CAACA,eAAeA,CAACA,yBAAyBA,EAAEA,CAACA;wBACnDA,CAACA;wBACDA,IAAIA,CAACA,CAACA;4BACJA,KAAIA,CAACA,OAAOA,GAAGA,eAAeA,CAACA;wBACjCA,CAACA;oBACHA,CAACA,EACDA,UAAAA,KAAKA;wBAEHA,OAAOA,CAACA,KAAKA,CAACA,KAAKA,CAACA,CAACA;wBAErBA,KAAIA,CAACA,OAAOA,GAAGA,gBAAgBA,GAAGA,KAAKA,CAACA;oBAC1CA,CAACA,CAACA,CAACA;gBACPA,CAACA;gBAEDF,+BAAMA,GAANA,UAAOA,IAAWA,EAAEA,QAAeA;oBAEjCG,IAAIA,CAACA,YAAYA,CAACA,MAAMA,CAACA,IAAIA,EAAEA,QAAQA,CAACA,CAACA,SAASA,CAChDA,UAAAA,IAAIA;wBAEFA,OAAOA,CAACA,GAAGA,CAACA,IAAIA,CAACA,CAACA;oBACpBA,CAACA,EACDA,UAAAA,KAAKA;wBAEHA,OAAOA,CAACA,KAAKA,CAACA,KAAKA,CAACA,CAACA;oBACvBA,CAACA,CAACA,CAACA;gBACPA,CAACA;gBAlDHH;oBAACA,gBAASA,CAACA;wBACEA,QAAQA,EAAEA,YAAYA;wBACtBA,WAAWA,EAAEA,0BAA0BA;wBACvCA,SAASA,EAAEA,CAACA,EAAEA,CAACA;wBACfA,QAAQA,EAAEA,CAACA,0BAAWA,CAACA;qBACxBA,CAACA;;mCA8CZA;gBAADA,qBAACA;YAADA,CAACA,AAnDD,IAmDC;YAnDD,2CAmDC,CAAA"} -------------------------------------------------------------------------------- /src/main/resources/web/app/login.component.ts: -------------------------------------------------------------------------------- 1 | import {Component} from 'angular2/core'; 2 | import {NgForm} from 'angular2/common'; 3 | 4 | import {User} from "./user"; 5 | import {UserService} from './user.service' 6 | import {UserAppComponent} from "./app.component"; 7 | import {AuctionService} from "./auction.service"; 8 | 9 | @Component({ 10 | selector: 'login-form', 11 | templateUrl: 'app/login.component.html', 12 | styleUrls: [''], 13 | bindings: [UserService] 14 | }) 15 | export class LoginComponent 16 | { 17 | user:User; 18 | message:string; 19 | 20 | constructor(private _userService:UserService, private _auctionService:AuctionService) 21 | { 22 | } 23 | 24 | login(user:string, password:string) 25 | { 26 | this._userService.login(user, password).subscribe( 27 | loggedIn => 28 | { 29 | console.log("login: " + loggedIn); 30 | 31 | if (loggedIn === "true") { 32 | this.message = "login successful: " + user; 33 | 34 | this._auctionService.registerForAuctionUpdates(); 35 | } 36 | else { 37 | this.message = "login failed."; 38 | } 39 | }, 40 | error => 41 | { 42 | console.error(error); 43 | 44 | this.message = "login failed: " + error; 45 | }); 46 | } 47 | 48 | create(user:string, password:string) 49 | { 50 | this._userService.create(user, password).subscribe( 51 | user => 52 | { 53 | console.log(user); 54 | }, 55 | error => 56 | { 57 | console.error(error); 58 | }); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/resources/web/app/new-auction.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Create Auction

3 |
4 |
5 | 6 | 7 |
8 |
9 | 10 | 12 |
13 | 16 |
17 |
-------------------------------------------------------------------------------- /src/main/resources/web/app/new-auction.component.js: -------------------------------------------------------------------------------- 1 | System.register(['angular2/core', "./auction.service"], function(exports_1) { 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | var __metadata = (this && this.__metadata) || function (k, v) { 9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 10 | }; 11 | var core_1, auction_service_1; 12 | var NewAuctionComponent; 13 | return { 14 | setters:[ 15 | function (core_1_1) { 16 | core_1 = core_1_1; 17 | }, 18 | function (auction_service_1_1) { 19 | auction_service_1 = auction_service_1_1; 20 | }], 21 | execute: function() { 22 | NewAuctionComponent = (function () { 23 | function NewAuctionComponent(_auctionService) { 24 | this._auctionService = _auctionService; 25 | } 26 | NewAuctionComponent.prototype.create = function (title, bid) { 27 | var _this = this; 28 | this._auctionService.create(title, bid) 29 | .subscribe(function (result) { 30 | _this._auctionService.onAuctionCreate(result); 31 | console.log("new auction :" + result); 32 | }, function (error) { 33 | console.error(error); 34 | }); 35 | }; 36 | NewAuctionComponent = __decorate([ 37 | core_1.Component({ 38 | selector: 'new-auction', 39 | templateUrl: 'app/new-auction.component.html', 40 | styleUrls: [''], 41 | bindings: [] 42 | }), 43 | __metadata('design:paramtypes', [auction_service_1.AuctionService]) 44 | ], NewAuctionComponent); 45 | return NewAuctionComponent; 46 | })(); 47 | exports_1("NewAuctionComponent", NewAuctionComponent); 48 | } 49 | } 50 | }); 51 | //# sourceMappingURL=new-auction.component.js.map -------------------------------------------------------------------------------- /src/main/resources/web/app/new-auction.component.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"new-auction.component.js","sourceRoot":"","sources":["new-auction.component.ts"],"names":["NewAuctionComponent","NewAuctionComponent.constructor","NewAuctionComponent.create"],"mappings":";;;;;;;;;;;;;;;;;;;;;YAOA;gBAQEA,6BAAoBA,eAA8BA;oBAA9BC,oBAAeA,GAAfA,eAAeA,CAAeA;gBAElDA,CAACA;gBAEDD,oCAAMA,GAANA,UAAOA,KAAYA,EAAEA,GAAUA;oBAA/BE,iBAYCA;oBAVCA,IAAIA,CAACA,eAAeA,CAACA,MAAMA,CAACA,KAAKA,EAAEA,GAAGA,CAACA;yBACpCA,SAASA,CAACA,UAAAA,MAAMA;wBAEJA,KAAIA,CAACA,eAAeA,CAACA,eAAeA,CAACA,MAAMA,CAACA,CAACA;wBAC7CA,OAAOA,CAACA,GAAGA,CAACA,eAAeA,GAAGA,MAAMA,CAACA,CAACA;oBACxCA,CAACA,EACDA,UAAAA,KAAKA;wBAEHA,OAAOA,CAACA,KAAKA,CAACA,KAAKA,CAACA,CAACA;oBACvBA,CAACA,CAACA,CAACA;gBAClBA,CAACA;gBAxBHF;oBAACA,gBAASA,CAACA;wBACEA,QAAQA,EAAEA,aAAaA;wBACvBA,WAAWA,EAAEA,gCAAgCA;wBAC7CA,SAASA,EAAEA,CAACA,EAAEA,CAACA;wBACfA,QAAQA,EAAEA,EAAEA;qBACbA,CAACA;;wCAoBZA;gBAADA,0BAACA;YAADA,CAACA,AAzBD,IAyBC;YAzBD,qDAyBC,CAAA"} -------------------------------------------------------------------------------- /src/main/resources/web/app/new-auction.component.ts: -------------------------------------------------------------------------------- 1 | import {Component} from 'angular2/core'; 2 | import {NgForm} from 'angular2/common'; 3 | 4 | import {UserAppComponent} from "./app.component"; 5 | import {AuctionService} from "./auction.service"; 6 | import {AuctionsComponent} from "./auctions.component"; 7 | 8 | @Component({ 9 | selector: 'new-auction', 10 | templateUrl: 'app/new-auction.component.html', 11 | styleUrls: [''], 12 | bindings: [] 13 | }) 14 | export class NewAuctionComponent 15 | { 16 | constructor(private _auctionService:AuctionService) 17 | { 18 | } 19 | 20 | create(title:string, bid:number) 21 | { 22 | this._auctionService.create(title, bid) 23 | .subscribe(result => 24 | { 25 | this._auctionService.onAuctionCreate(result); 26 | console.log("new auction :" + result); 27 | }, 28 | error => 29 | { 30 | console.error(error); 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/resources/web/app/user-main.js: -------------------------------------------------------------------------------- 1 | System.register(['angular2/platform/browser', 'rxjs/Rx', './app.component'], function(exports_1) { 2 | var browser_1, app_component_1; 3 | return { 4 | setters:[ 5 | function (browser_1_1) { 6 | browser_1 = browser_1_1; 7 | }, 8 | function (_1) {}, 9 | function (app_component_1_1) { 10 | app_component_1 = app_component_1_1; 11 | }], 12 | execute: function() { 13 | browser_1.bootstrap(app_component_1.UserAppComponent); 14 | } 15 | } 16 | }); 17 | //# sourceMappingURL=user-main.js.map -------------------------------------------------------------------------------- /src/main/resources/web/app/user-main.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"user-main.js","sourceRoot":"","sources":["user-main.ts"],"names":[],"mappings":";;;;;;;;;;;;YAMA,mBAAS,CAAC,gCAAgB,CAAC,CAAC"} -------------------------------------------------------------------------------- /src/main/resources/web/app/user-main.ts: -------------------------------------------------------------------------------- 1 | import {bootstrap} from 'angular2/platform/browser'; 2 | 3 | import 'rxjs/Rx'; 4 | 5 | import {UserAppComponent} from './app.component'; 6 | 7 | bootstrap(UserAppComponent); 8 | -------------------------------------------------------------------------------- /src/main/resources/web/app/user.js: -------------------------------------------------------------------------------- 1 | System.register([], function(exports_1) { 2 | return { 3 | setters:[], 4 | execute: function() { 5 | } 6 | } 7 | }); 8 | //# sourceMappingURL=user.js.map -------------------------------------------------------------------------------- /src/main/resources/web/app/user.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"user.js","sourceRoot":"","sources":["user.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /src/main/resources/web/app/user.service.js: -------------------------------------------------------------------------------- 1 | System.register(['angular2/core', 'angular2/http', 'rxjs/Observable', './baseurl', "angular2/src/facade/lang"], function(exports_1) { 2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { 3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; 4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; 6 | return c > 3 && r && Object.defineProperty(target, key, r), r; 7 | }; 8 | var __metadata = (this && this.__metadata) || function (k, v) { 9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); 10 | }; 11 | var core_1, http_1, Observable_1, baseurl_1, lang_1; 12 | var UserService; 13 | return { 14 | setters:[ 15 | function (core_1_1) { 16 | core_1 = core_1_1; 17 | }, 18 | function (http_1_1) { 19 | http_1 = http_1_1; 20 | }, 21 | function (Observable_1_1) { 22 | Observable_1 = Observable_1_1; 23 | }, 24 | function (baseurl_1_1) { 25 | baseurl_1 = baseurl_1_1; 26 | }, 27 | function (lang_1_1) { 28 | lang_1 = lang_1_1; 29 | }], 30 | execute: function() { 31 | UserService = (function () { 32 | function UserService(http, _baseUrlProvider) { 33 | this.http = http; 34 | this._baseUrlProvider = _baseUrlProvider; 35 | console.log("creating new UserService: " + http); 36 | this._createUrl = _baseUrlProvider.url + "createUser"; 37 | this._loginUrl = _baseUrlProvider.url + "login"; 38 | } 39 | UserService.prototype.login = function (user, password) { 40 | var body = 'u=' + user + '&' + 'p=' + password; 41 | var headers = new http_1.Headers({ 42 | 'Content-Type': 'application/x-www-form-urlencoded' 43 | }); 44 | var options = new http_1.RequestOptions({ headers: headers }); 45 | return this.http.post(this._loginUrl, body, options) 46 | .map(function (res) { return res.text(); }).catch(this.handleError); 47 | }; 48 | UserService.prototype.create = function (user, password) { 49 | var _this = this; 50 | var body = lang_1.Json.stringify({ "user": user, "password": password }); 51 | var headers = new http_1.Headers({ 52 | 'Content-Type': 'application/json' 53 | }); 54 | var options = new http_1.RequestOptions({ headers: headers }); 55 | return this.http.post(this._createUrl, body, options) 56 | .map(function (res) { return _this.map(res); }).catch(this.handleError); 57 | }; 58 | UserService.prototype.map = function (response) { 59 | console.log(response); 60 | console.log("Set-Cookie: " + response.headers.get("Set-Cookie")); 61 | return response.json(); 62 | }; 63 | UserService.prototype.handleError = function (error) { 64 | console.error(error); 65 | return Observable_1.Observable.throw(error.json().error || 'Server error'); 66 | }; 67 | UserService = __decorate([ 68 | core_1.Injectable(), 69 | __metadata('design:paramtypes', [http_1.Http, baseurl_1.BaseUrlProvider]) 70 | ], UserService); 71 | return UserService; 72 | })(); 73 | exports_1("UserService", UserService); 74 | } 75 | } 76 | }); 77 | //# sourceMappingURL=user.service.js.map -------------------------------------------------------------------------------- /src/main/resources/web/app/user.service.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"user.service.js","sourceRoot":"","sources":["user.service.ts"],"names":["UserService","UserService.constructor","UserService.login","UserService.create","UserService.map","UserService.handleError"],"mappings":"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"} -------------------------------------------------------------------------------- /src/main/resources/web/app/user.service.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from 'angular2/core'; 2 | import {Http, Response, Headers, RequestOptions} from 'angular2/http'; 3 | import {Observable} from 'rxjs/Observable'; 4 | 5 | import {BaseUrlProvider} from './baseurl'; 6 | import {User} from './user'; 7 | import {Request} from "angular2/http"; 8 | import {Json} from "angular2/src/facade/lang"; 9 | import {OnInit} from "angular2/core"; 10 | 11 | @Injectable() 12 | export class UserService 13 | { 14 | private _createUrl; 15 | private _loginUrl; 16 | 17 | constructor(private http:Http, private _baseUrlProvider:BaseUrlProvider) 18 | { 19 | console.log("creating new UserService: " + http); 20 | 21 | this._createUrl = _baseUrlProvider.url + "createUser"; 22 | this._loginUrl = _baseUrlProvider.url + "login"; 23 | } 24 | 25 | login(user:string, password:string) 26 | { 27 | let body = 'u=' + user + '&' + 'p=' + password; 28 | 29 | let headers = new Headers({ 30 | 'Content-Type': 'application/x-www-form-urlencoded' 31 | }); 32 | let options = new RequestOptions({headers: headers}); 33 | 34 | return this.http.post(this._loginUrl, body, options) 35 | .map(res=> res.text()).catch(this.handleError); 36 | } 37 | 38 | create(user:string, password:string) 39 | { 40 | let body = Json.stringify({"user": user, "password": password}); 41 | 42 | let headers = new Headers({ 43 | 'Content-Type': 'application/json' 44 | }); 45 | let options = new RequestOptions({headers: headers}); 46 | 47 | return this.http.post(this._createUrl, body, options) 48 | .map(res=>this.map(res)).catch(this.handleError); 49 | } 50 | 51 | map(response:Response) 52 | { 53 | console.log(response); 54 | 55 | console.log("Set-Cookie: " + response.headers.get("Set-Cookie")); 56 | 57 | return response.json(); 58 | } 59 | 60 | private handleError(error:Response) 61 | { 62 | console.error(error); 63 | return Observable.throw(error.json().error || 'Server error'); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/resources/web/app/user.ts: -------------------------------------------------------------------------------- 1 | export interface User 2 | { 3 | id: String; 4 | name: string; 5 | } 6 | -------------------------------------------------------------------------------- /src/main/resources/web/index-admin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Baratine™ Auction Application 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 38 | 39 | 40 | 41 | 42 | 43 | Loading... 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/main/resources/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Baratine™ Auction Application 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 38 | 39 | 40 | 41 | 42 | 43 | Loading... 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/main/resources/web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular2-tour-of-heroes", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "postinstall": "npm run typings install", 6 | "tsc": "tsc", 7 | "tsc:w": "tsc -w", 8 | "lite": "lite-server", 9 | "start": "concurrent \"npm run tsc:w\" \"npm run lite\" ", 10 | "xstart": "concurrent \"npm run lite\" ", 11 | "typings": "typings" 12 | }, 13 | "license": "ISC", 14 | "dependencies": { 15 | "angular2": "2.0.0-beta.6", 16 | "bootstrap": "^3.3.6", 17 | "es6-promise": "^3.0.2", 18 | "es6-shim": "^0.33.3", 19 | "reflect-metadata": "0.1.2", 20 | "rxjs": "5.0.0-beta.0", 21 | "systemjs": "0.19.20", 22 | "zone.js": "0.5.14" 23 | }, 24 | "devDependencies": { 25 | "concurrently": "^1.0.0", 26 | "lite-server": "^2.0.1", 27 | "typescript": "^1.7.5", 28 | "typings": "^0.6.8", 29 | "sockjs-client": "1.0.3" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/resources/web/styles.css: -------------------------------------------------------------------------------- 1 | h2 { 2 | color: #444; 3 | font-weight: lighter; 4 | } 5 | 6 | body { 7 | margin: 2em; 8 | } 9 | 10 | body, input[text], button { 11 | color: #888; 12 | font-family: Cambria, Georgia; 13 | } 14 | 15 | button { 16 | padding: 0.2em; 17 | font-size: 14px 18 | } 19 | 20 | * { 21 | font-family: Arial; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/resources/web/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "system", 5 | "moduleResolution": "node", 6 | "sourceMap": true, 7 | "emitDecoratorMetadata": true, 8 | "experimentalDecorators": true, 9 | "removeComments": false, 10 | "noImplicitAny": false 11 | }, 12 | "exclude": [ 13 | "node_modules", 14 | "typings/main", 15 | "typings/main.d.ts" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /src/main/resources/web/typings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ambientDependencies": { 3 | "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/AuctionReplayTest.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.util.logging.Logger; 4 | 5 | import javax.inject.Inject; 6 | 7 | import io.baratine.service.Service; 8 | import io.baratine.service.Services; 9 | import io.baratine.vault.IdAsset; 10 | 11 | import com.caucho.junit.ConfigurationBaratine; 12 | import com.caucho.junit.RunnerBaratine; 13 | import com.caucho.junit.ServiceTest; 14 | 15 | import org.junit.Assert; 16 | import org.junit.Test; 17 | import org.junit.runner.RunWith; 18 | 19 | /** 20 | * 21 | */ 22 | @RunWith(RunnerBaratine.class) 23 | @ServiceTest(UserVault.class) 24 | @ServiceTest(AuctionVault.class) 25 | @ServiceTest(AuditServiceImpl.class) 26 | @ServiceTest(AuctionSettlementVault.class) 27 | @ConfigurationBaratine(workDir = "/tmp/baratine", 28 | testTime = ConfigurationBaratine.TEST_TIME, 29 | journalDelay = 12000) 30 | public class AuctionReplayTest 31 | { 32 | private static final Logger log 33 | = Logger.getLogger(AuctionReplayTest.class.getName()); 34 | 35 | @Inject 36 | @Service("public:///user") 37 | UserVaultSync _users; 38 | 39 | @Inject 40 | @Service("public:///auction") 41 | AuctionVaultSync _auctions; 42 | 43 | @Inject 44 | RunnerBaratine _testContext; 45 | 46 | @Inject 47 | Services _services; 48 | 49 | /** 50 | * Tests normal bid. 51 | */ 52 | @Test 53 | public void testAuctionBid() throws InterruptedException 54 | { 55 | UserSync userSpock = createUser("Spock", "test"); 56 | UserSync userKirk = createUser("Kirk", "test"); 57 | 58 | AuctionSync auction = createAuction(userSpock, "book", 15); 59 | 60 | Assert.assertNotNull(auction); 61 | 62 | boolean result = auction.open(); 63 | Assert.assertTrue(result); 64 | 65 | String auctionId = auction.get().getEncodedId(); 66 | 67 | // successful bid 68 | result = auction.bid(new AuctionBid(userKirk.get().getEncodedId(), 20)); 69 | Assert.assertTrue(result); 70 | AuctionData data = auction.get(); 71 | Assert.assertEquals(data.getLastBid().getBid(), 20); 72 | Assert.assertEquals(data.getLastBid().getUserId(), 73 | userKirk.get().getEncodedId()); 74 | 75 | //State.sleep(10); 76 | 77 | _testContext.stopImmediate(); 78 | 79 | _testContext.start(); 80 | 81 | auction = _services.service(AuctionSync.class, auctionId); 82 | 83 | data = auction.get(); 84 | Assert.assertEquals(data.getLastBid().getBid(), 20); 85 | } 86 | 87 | UserSync createUser(String name, String password) 88 | { 89 | IdAsset id = _users.create( 90 | new AuctionSession.UserInitData(name, password, false)); 91 | 92 | return _services.service(UserSync.class, id.toString()); 93 | } 94 | 95 | AuctionSync createAuction(UserSync user, String title, int bid) 96 | { 97 | IdAsset id = _auctions.create( 98 | new AuctionDataInit(user.get().getEncodedId(), 99 | title, 100 | bid)); 101 | 102 | return _services.service(AuctionSync.class, id.toString()); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/AuctionSettleRejectAuctionTest.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.io.IOException; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import javax.inject.Inject; 7 | 8 | import io.baratine.service.Result; 9 | import io.baratine.service.ResultFuture; 10 | import io.baratine.service.Service; 11 | import io.baratine.service.Services; 12 | 13 | import com.caucho.junit.ConfigurationBaratine; 14 | import com.caucho.junit.LogConfig; 15 | import com.caucho.junit.RunnerBaratine; 16 | import com.caucho.junit.ServiceTest; 17 | import com.caucho.junit.State; 18 | 19 | import examples.auction.AuctionSession.UserInitData; 20 | import examples.auction.mock.MockPayPal; 21 | import org.junit.Assert; 22 | import org.junit.Test; 23 | import org.junit.runner.RunWith; 24 | 25 | @RunWith(RunnerBaratine.class) 26 | @ServiceTest(AuctionSettleRejectAuctionTest.AuctionMockVault.class) 27 | @ServiceTest(UserVault.class) 28 | @ServiceTest(AuditServiceImpl.class) 29 | @ServiceTest(AuctionSettlementVault.class) 30 | @ServiceTest(MockPayPal.class) 31 | @ConfigurationBaratine(workDir = "/tmp/baratine", 32 | testTime = ConfigurationBaratine.TEST_TIME) 33 | @LogConfig("com") 34 | public class AuctionSettleRejectAuctionTest 35 | { 36 | @Inject 37 | @Service("/User") 38 | UserAbstractVault _users; 39 | 40 | @Inject 41 | @Service("/Auction") 42 | AuctionVault _auctions; 43 | 44 | @Inject 45 | Services _services; 46 | 47 | @Test 48 | public void testSettle() 49 | throws IOException, InterruptedException 50 | { 51 | UserSync spock = createUser("Spock", "passwd"); 52 | UserSync kirk = createUser("Kirk", "passwd"); 53 | 54 | AuctionSync auction = createAuction(spock.get().getEncodedId(), "Book", 12); 55 | 56 | Assert.assertTrue(auction.open()); 57 | Assert.assertTrue(auction.bid(new AuctionBid(kirk.get().getEncodedId(), 58 | 13))); 59 | Assert.assertEquals(13, auction.get().getLastBid().getBid()); 60 | 61 | auction.close(); 62 | 63 | State.sleep(100); 64 | 65 | Auction.State state = auction.get().getState(); 66 | 67 | Assert.assertEquals(Auction.State.ROLLED_BACK, state); 68 | 69 | String settlementId = auction.getSettlementId(); 70 | 71 | AuctionSettlementSync settlement 72 | = _services.service(AuctionSettlementSync.class, settlementId); 73 | 74 | AuctionSettlement.Status settleStatus = settlement.settleStatus(); 75 | AuctionSettlement.Status refundStatus = settlement.refundStatus(); 76 | 77 | Assert.assertEquals(AuctionSettlement.Status.SETTLE_FAILED, 78 | settleStatus); 79 | Assert.assertEquals(AuctionSettlement.Status.ROLLED_BACK, 80 | refundStatus); 81 | 82 | SettlementTransactionState transactionState 83 | = settlement.getTransactionState(); 84 | 85 | Assert.assertEquals(SettlementTransactionState.UserUpdateState.SUCCESS, 86 | transactionState.getUserSettleState()); 87 | 88 | Assert.assertEquals(SettlementTransactionState.AuctionWinnerUpdateState.REJECTED, 89 | transactionState.getAuctionWinnerUpdateState()); 90 | 91 | Assert.assertEquals(SettlementTransactionState.AuctionWinnerUpdateState.NONE, 92 | transactionState.getAuctionWinnerResetState()); 93 | 94 | Assert.assertEquals(AuctionSettlement.Status.ROLLED_BACK, 95 | transactionState.getRefundStatus()); 96 | } 97 | 98 | private UserSync createUser(final String name, 99 | final String passwd) throws IOException 100 | { 101 | ResultFuture user = new ResultFuture<>(); 102 | 103 | _users.create(new UserInitData(name, passwd, false), 104 | user.then(id -> _services.service(UserSync.class, 105 | id.toString()))); 106 | 107 | return user.get(1, TimeUnit.SECONDS); 108 | } 109 | 110 | private AuctionSync createAuction(String userId, String title, int bid) 111 | { 112 | ResultFuture auction = new ResultFuture<>(); 113 | 114 | _auctions.create(new AuctionDataInit(userId, title, bid), 115 | auction.then(id -> _services.service(AuctionSync.class, 116 | id.toString()))); 117 | return auction.get(1, TimeUnit.SECONDS); 118 | } 119 | 120 | public interface AuctionMockVault extends AuctionAbstractVault 121 | { 122 | 123 | } 124 | 125 | public static class AuctionMock extends AuctionImpl 126 | { 127 | @Override 128 | public void setAuctionWinner(String user, Result result) 129 | { 130 | result.ok(false); 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/AuctionSettleRejectUserTest.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.io.IOException; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import javax.inject.Inject; 7 | 8 | import io.baratine.service.Result; 9 | import io.baratine.service.ResultFuture; 10 | import io.baratine.service.Service; 11 | import io.baratine.service.Services; 12 | 13 | import com.caucho.junit.ConfigurationBaratine; 14 | import com.caucho.junit.LogConfig; 15 | import com.caucho.junit.RunnerBaratine; 16 | import com.caucho.junit.ServiceTest; 17 | import com.caucho.junit.State; 18 | 19 | import examples.auction.AuctionSession.UserInitData; 20 | import examples.auction.mock.MockPayPal; 21 | import org.junit.Assert; 22 | import org.junit.Test; 23 | import org.junit.runner.RunWith; 24 | 25 | @RunWith(RunnerBaratine.class) 26 | @ServiceTest(AuctionSettleRejectUserTest.UserMockVault.class) 27 | @ServiceTest(AuctionVault.class) 28 | @ServiceTest(AuditServiceImpl.class) 29 | @ServiceTest(AuctionSettlementVault.class) 30 | @ServiceTest(MockPayPal.class) 31 | @ConfigurationBaratine(workDir = "/tmp/baratine", 32 | testTime = ConfigurationBaratine.TEST_TIME) 33 | @LogConfig("com") 34 | public class AuctionSettleRejectUserTest 35 | { 36 | @Inject 37 | @Service("/User") 38 | UserAbstractVault _users; 39 | 40 | @Inject 41 | @Service("/Auction") 42 | AuctionVault _auctions; 43 | 44 | @Inject 45 | Services _services; 46 | 47 | @Test 48 | public void testSettle() 49 | throws IOException, InterruptedException 50 | { 51 | UserSync spock = createUser("Spock", "passwd"); 52 | UserSync kirk = createUser("Kirk", "passwd"); 53 | 54 | AuctionSync auction = createAuction(spock.get().getEncodedId(), "Book", 12); 55 | 56 | Assert.assertTrue(auction.open()); 57 | Assert.assertTrue(auction.bid(new AuctionBid(kirk.get().getEncodedId(), 58 | 13))); 59 | Assert.assertEquals(13, auction.get().getLastBid().getBid()); 60 | 61 | auction.close(); 62 | 63 | State.sleep(100); 64 | 65 | Auction.State state = auction.get().getState(); 66 | 67 | Assert.assertEquals(Auction.State.ROLLED_BACK, state); 68 | 69 | String settlementId = auction.getSettlementId(); 70 | 71 | AuctionSettlementSync settlement 72 | = _services.service(AuctionSettlementSync.class, settlementId); 73 | 74 | AuctionSettlement.Status settleStatus = settlement.settleStatus(); 75 | AuctionSettlement.Status refundStatus = settlement.refundStatus(); 76 | 77 | Assert.assertEquals(AuctionSettlement.Status.SETTLE_FAILED, 78 | settleStatus); 79 | Assert.assertEquals(AuctionSettlement.Status.ROLLED_BACK, 80 | refundStatus); 81 | 82 | SettlementTransactionState transactionState 83 | = settlement.getTransactionState(); 84 | 85 | Assert.assertEquals(SettlementTransactionState.UserUpdateState.REJECTED, 86 | transactionState.getUserSettleState()); 87 | 88 | Assert.assertEquals(SettlementTransactionState.AuctionWinnerUpdateState.ROLLED_BACK, 89 | transactionState.getAuctionWinnerResetState()); 90 | 91 | Assert.assertEquals(AuctionSettlement.Status.ROLLED_BACK, 92 | transactionState.getRefundStatus()); 93 | } 94 | 95 | private UserSync createUser(final String name, 96 | final String passwd) throws IOException 97 | { 98 | ResultFuture user = new ResultFuture<>(); 99 | 100 | _users.create(new UserInitData(name, passwd, false), 101 | user.then(id -> _services.service(UserSync.class, 102 | id.toString()))); 103 | 104 | return user.get(1, TimeUnit.SECONDS); 105 | } 106 | 107 | private AuctionSync createAuction(String userId, String title, int bid) 108 | { 109 | ResultFuture auction = new ResultFuture<>(); 110 | 111 | _auctions.create(new AuctionDataInit(userId, title, bid), 112 | auction.then(id -> _services.service(AuctionSync.class, 113 | id.toString()))); 114 | return auction.get(1, TimeUnit.SECONDS); 115 | } 116 | 117 | public interface UserMockVault extends UserAbstractVault 118 | { 119 | } 120 | 121 | public static class UserMock extends UserImpl 122 | { 123 | @Override 124 | public void addWonAuction(String auctionId, Result result) 125 | { 126 | result.ok(false); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/AuctionSettleResumeTest.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.util.logging.Logger; 4 | 5 | import javax.inject.Inject; 6 | 7 | import io.baratine.service.Result; 8 | import io.baratine.service.Service; 9 | import io.baratine.service.Services; 10 | import io.baratine.vault.IdAsset; 11 | 12 | import com.caucho.junit.LogConfig; 13 | import com.caucho.junit.RunnerBaratine; 14 | import com.caucho.junit.ServiceTest; 15 | import com.caucho.junit.State; 16 | 17 | import examples.auction.mock.MockPayPal; 18 | import examples.auction.mock.MockPayment; 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | 23 | /** 24 | */ 25 | @RunWith(RunnerBaratine.class) 26 | @ServiceTest(UserVault.class) 27 | @ServiceTest(AuctionVault.class) 28 | @ServiceTest(AuditServiceImpl.class) 29 | @ServiceTest(AuctionSettlementVault.class) 30 | @ServiceTest(MockPayPal.class) 31 | //@ConfigurationBaratine(workDir = "/tmp/baratine", testTime = ConfigurationBaratine.TEST_TIME) 32 | @LogConfig("com.caucho") 33 | public class AuctionSettleResumeTest 34 | { 35 | private static final Logger log 36 | = Logger.getLogger(AuctionSettleResumeTest.class.getName()); 37 | 38 | @Inject 39 | @Service("public:///User") 40 | UserVaultSync _users; 41 | 42 | @Inject 43 | @Service("public:///Auction") 44 | AuctionVaultSync _auctions; 45 | 46 | @Inject 47 | @Service("public:///PayPal") 48 | MockPayPal _paypal; 49 | 50 | @Inject 51 | Services _services; 52 | 53 | @Test 54 | public void testAuctionSettle() throws InterruptedException 55 | { 56 | UserSync userSpock = createUser("Spock", "test"); 57 | UserSync userKirk = createUser("Kirk", "test"); 58 | 59 | AuctionSync auction = createAuction(userSpock, "book", 1); 60 | 61 | Assert.assertNotNull(auction); 62 | 63 | Assert.assertTrue(auction.open()); 64 | 65 | Assert.assertTrue(auction.bid(new AuctionBid(userKirk.get().getEncodedId(), 66 | 2))); 67 | 68 | _paypal.configure(new MockPayment("sale-id", Payment.PaymentState.pending), 69 | 0, 70 | Result.ignore()); 71 | 72 | Assert.assertTrue(auction.close()); 73 | 74 | AuctionSettlementSync settlement = getSettlement(auction); 75 | 76 | State.sleep(100); 77 | 78 | AuctionSettlement.Status status = settlement.settleStatus(); 79 | 80 | Assert.assertEquals(AuctionSettlement.Status.SETTLING, status); 81 | 82 | AuctionData auctionData = auction.get(); 83 | 84 | Assert.assertEquals(Auction.State.CLOSED, auctionData.getState()); 85 | 86 | UserSync winner = getUser(auctionData.getLastBidder()); 87 | UserData winnerUserData = winner.get(); 88 | 89 | Assert.assertTrue(winnerUserData.getWonAuctions() 90 | .contains(auctionData.getEncodedId())); 91 | 92 | Assert.assertEquals(auctionData.getLastBidder(), 93 | winnerUserData.getEncodedId()); 94 | 95 | SettlementTransactionState state = settlement.getTransactionState(); 96 | 97 | Assert.assertEquals(state.getSettleStatus(), 98 | AuctionSettlement.Status.SETTLING); 99 | 100 | Assert.assertEquals(state.getRefundStatus(), 101 | AuctionSettlement.Status.NONE); 102 | 103 | Assert.assertEquals(state.getAuctionWinnerUpdateState(), 104 | SettlementTransactionState.AuctionWinnerUpdateState.SUCCESS); 105 | Assert.assertEquals(state.getAuctionWinnerResetState(), 106 | SettlementTransactionState.AuctionWinnerUpdateState.NONE); 107 | 108 | Assert.assertEquals(state.getUserSettleState(), 109 | SettlementTransactionState.UserUpdateState.SUCCESS); 110 | Assert.assertEquals(state.getUserResetState(), 111 | SettlementTransactionState.UserUpdateState.NONE); 112 | 113 | Assert.assertEquals(state.getPaymentState(), 114 | SettlementTransactionState.PaymentTxState.PENDING); 115 | Assert.assertEquals(state.getRefundState(), 116 | SettlementTransactionState.PaymentTxState.NONE); 117 | 118 | //retry 119 | _paypal.configure( 120 | new MockPayment("sale-id", Payment.PaymentState.approved), 121 | 0, 122 | Result.ignore()); 123 | 124 | settlement.settleResume(); 125 | 126 | State.sleep(100); 127 | 128 | status = settlement.getTransactionState().getSettleStatus(); 129 | 130 | Assert.assertEquals(AuctionSettlement.Status.SETTLED, status); 131 | 132 | auctionData = auction.get(); 133 | Assert.assertEquals(Auction.State.SETTLED, auctionData.getState()); 134 | 135 | winner = getUser(auctionData.getLastBidder()); 136 | winnerUserData = winner.get(); 137 | 138 | Assert.assertTrue(winnerUserData.getWonAuctions() 139 | .contains(auctionData.getEncodedId())); 140 | 141 | Assert.assertEquals(auctionData.getLastBidder(), 142 | winnerUserData.getEncodedId()); 143 | 144 | state = settlement.getTransactionState(); 145 | 146 | Assert.assertEquals(state.getSettleStatus(), 147 | AuctionSettlement.Status.SETTLED); 148 | 149 | Assert.assertEquals(state.getRefundStatus(), 150 | AuctionSettlement.Status.NONE); 151 | 152 | Assert.assertEquals(state.getAuctionWinnerUpdateState(), 153 | SettlementTransactionState.AuctionWinnerUpdateState.SUCCESS); 154 | Assert.assertEquals(state.getAuctionWinnerResetState(), 155 | SettlementTransactionState.AuctionWinnerUpdateState.NONE); 156 | 157 | Assert.assertEquals(state.getUserSettleState(), 158 | SettlementTransactionState.UserUpdateState.SUCCESS); 159 | Assert.assertEquals(state.getUserResetState(), 160 | SettlementTransactionState.UserUpdateState.NONE); 161 | 162 | Assert.assertEquals(state.getPaymentState(), 163 | SettlementTransactionState.PaymentTxState.SUCCESS); 164 | Assert.assertEquals(state.getRefundState(), 165 | SettlementTransactionState.PaymentTxState.NONE); 166 | 167 | } 168 | 169 | UserSync createUser(String name, String password) 170 | { 171 | IdAsset id 172 | = _users.create(new AuctionSession.UserInitData(name, password, false)); 173 | 174 | return getUser(id.toString()); 175 | } 176 | 177 | UserSync getUser(String id) 178 | { 179 | return _services.service(UserSync.class, id); 180 | } 181 | 182 | AuctionSync createAuction(UserSync user, String title, int bid) 183 | { 184 | IdAsset id = _auctions.create( 185 | new AuctionDataInit(user.get().getEncodedId(), title, bid)); 186 | 187 | return getAuction(id.toString()); 188 | } 189 | 190 | AuctionSync getAuction(String id) 191 | { 192 | return _services.service(AuctionSync.class, id); 193 | } 194 | 195 | AuctionSettlementSync getSettlement(AuctionSync auction) 196 | { 197 | String id = auction.getSettlementId(); 198 | 199 | while (id == null) 200 | id = auction.getSettlementId(); 201 | 202 | System.out.println("AuctionSettleRetryTest.getSettlement " + id); 203 | return _services.service(AuctionSettlementSync.class, id); 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/AuctionSettleRollbackTest.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.io.IOException; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import javax.inject.Inject; 7 | 8 | import io.baratine.service.ResultFuture; 9 | import io.baratine.service.Service; 10 | import io.baratine.service.Services; 11 | 12 | import com.caucho.junit.ConfigurationBaratine; 13 | import com.caucho.junit.RunnerBaratine; 14 | import com.caucho.junit.ServiceTest; 15 | import com.caucho.junit.State; 16 | 17 | import examples.auction.AuctionSession.UserInitData; 18 | import examples.auction.mock.MockPayPal; 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | 23 | @RunWith(RunnerBaratine.class) 24 | @ServiceTest(UserVault.class) 25 | @ServiceTest(AuctionVault.class) 26 | @ServiceTest(AuditServiceImpl.class) 27 | @ServiceTest(AuctionSettlementVault.class) 28 | @ServiceTest(MockPayPal.class) 29 | @ConfigurationBaratine(workDir = "/tmp/baratine", 30 | testTime = ConfigurationBaratine.TEST_TIME) 31 | public class AuctionSettleRollbackTest 32 | { 33 | @Inject 34 | @Service("/User") 35 | UserVault _users; 36 | 37 | @Inject 38 | @Service("/Auction") 39 | AuctionVault _auctions; 40 | 41 | @Inject 42 | @Service("/AuctionSettlement") 43 | AuctionSettlementVault _settlements; 44 | 45 | @Inject 46 | @Service("/PayPal") 47 | MockPayPal _mockPayPal; 48 | 49 | @Inject 50 | Services _services; 51 | 52 | @Inject 53 | RunnerBaratine _baratine; 54 | 55 | @Test 56 | public void test() 57 | throws IOException, InterruptedException 58 | { 59 | UserSync spock = createUser("Spock", "passwd"); 60 | UserSync kirk = createUser("Kirk", "passwd"); 61 | 62 | AuctionSync auction = createAuction(spock.get().getEncodedId(), "Book", 12); 63 | 64 | Assert.assertTrue(auction.open()); 65 | Assert.assertTrue(auction.bid(new AuctionBid(kirk.get().getEncodedId(), 66 | 13))); 67 | Assert.assertEquals(13, auction.get().getLastBid().getBid()); 68 | 69 | auction.close(); 70 | 71 | Auction.State state = auction.get().getState(); 72 | 73 | int counter = 10; 74 | while (state != Auction.State.SETTLED && counter-- > 0) { 75 | state = auction.get().getState(); 76 | State.sleep(100); 77 | } 78 | 79 | Assert.assertEquals(Auction.State.SETTLED, state); 80 | 81 | String settlementId = auction.getSettlementId(); 82 | 83 | AuctionSettlementSync settlement 84 | = _services.service(AuctionSettlementSync.class, settlementId); 85 | 86 | AuctionSettlement.Status settleStatus = settlement.settleStatus(); 87 | AuctionSettlement.Status refundStatus = settlement.refundStatus(); 88 | 89 | Assert.assertEquals(AuctionSettlement.Status.SETTLED, 90 | settleStatus); 91 | Assert.assertEquals(AuctionSettlement.Status.NONE, 92 | refundStatus); 93 | 94 | SettlementTransactionState transactionState 95 | = settlement.getTransactionState(); 96 | 97 | Assert.assertEquals(SettlementTransactionState.AuctionUpdateState.SUCCESS, 98 | transactionState.getAuctionStateUpdateState()); 99 | Assert.assertEquals(SettlementTransactionState.AuctionWinnerUpdateState.SUCCESS, 100 | transactionState.getAuctionWinnerUpdateState()); 101 | Assert.assertEquals(SettlementTransactionState.PaymentTxState.SUCCESS, 102 | transactionState.getPaymentState()); 103 | 104 | // REFUND // 105 | 106 | AuctionSettlement.Status status = settlement.refund(); 107 | 108 | Assert.assertEquals(AuctionSettlement.Status.ROLLED_BACK, status); 109 | 110 | SettlementTransactionState refundState = settlement.getTransactionState(); 111 | 112 | Assert.assertEquals(SettlementTransactionState.UserUpdateState.ROLLED_BACK, 113 | refundState.getUserResetState()); 114 | Assert.assertEquals(SettlementTransactionState.AuctionWinnerUpdateState.ROLLED_BACK, 115 | refundState.getAuctionWinnerResetState()); 116 | Assert.assertEquals(SettlementTransactionState.PaymentTxState.REFUNDED, 117 | refundState.getRefundState()); 118 | } 119 | 120 | private UserSync createUser(final String name, 121 | final String passwd) throws IOException 122 | { 123 | ResultFuture user = new ResultFuture<>(); 124 | 125 | _users.create(new UserInitData(name, passwd, false), 126 | user.then(id -> _services.service(UserSync.class, 127 | id.toString()))); 128 | 129 | return user.get(1, TimeUnit.SECONDS); 130 | } 131 | 132 | private AuctionSync createAuction(String userId, String title, int bid) 133 | { 134 | ResultFuture auction = new ResultFuture<>(); 135 | 136 | _auctions.create(new AuctionDataInit(userId, title, bid), 137 | auction.then(id -> _services.service(AuctionSync.class, 138 | id.toString()))); 139 | return auction.get(1, TimeUnit.SECONDS); 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/AuctionSettleTest.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.io.IOException; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import javax.inject.Inject; 7 | 8 | import io.baratine.service.ResultFuture; 9 | import io.baratine.service.Service; 10 | import io.baratine.service.Services; 11 | 12 | import com.caucho.junit.ConfigurationBaratine; 13 | import com.caucho.junit.RunnerBaratine; 14 | import com.caucho.junit.ServiceTest; 15 | import com.caucho.junit.State; 16 | 17 | import examples.auction.AuctionSession.UserInitData; 18 | import examples.auction.mock.MockPayPal; 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | 23 | @RunWith(RunnerBaratine.class) 24 | @ServiceTest(UserVault.class) 25 | @ServiceTest(AuctionVault.class) 26 | @ServiceTest(AuditServiceImpl.class) 27 | @ServiceTest(AuctionSettlementVault.class) 28 | @ServiceTest(MockPayPal.class) 29 | @ConfigurationBaratine(workDir = "/tmp/baratine", 30 | testTime = ConfigurationBaratine.TEST_TIME) 31 | public class AuctionSettleTest 32 | { 33 | @Inject 34 | @Service("/User") 35 | UserVault _users; 36 | 37 | @Inject 38 | @Service("/Auction") 39 | AuctionVault _auctions; 40 | 41 | @Inject 42 | @Service("/AuctionSettlement") 43 | AuctionSettlementVault _settlements; 44 | 45 | @Inject 46 | @Service("/PayPal") 47 | MockPayPal _mockPayPal; 48 | 49 | @Inject 50 | Services _services; 51 | 52 | @Inject 53 | RunnerBaratine _baratine; 54 | 55 | @Test 56 | public void testSettle() 57 | throws IOException, InterruptedException 58 | { 59 | UserSync spock = createUser("Spock", "passwd"); 60 | UserSync kirk = createUser("Kirk", "passwd"); 61 | 62 | AuctionSync auction = createAuction(spock.get().getEncodedId(), "Book", 12); 63 | 64 | Assert.assertTrue(auction.open()); 65 | Assert.assertTrue(auction.bid(new AuctionBid(kirk.get().getEncodedId(), 66 | 13))); 67 | Assert.assertEquals(13, auction.get().getLastBid().getBid()); 68 | 69 | auction.close(); 70 | 71 | Auction.State state = auction.get().getState(); 72 | 73 | int counter = 10; 74 | while (state != Auction.State.SETTLED && counter-- > 0) { 75 | state = auction.get().getState(); 76 | State.sleep(100); 77 | } 78 | 79 | Assert.assertEquals(Auction.State.SETTLED, state); 80 | 81 | String settlementId = auction.getSettlementId(); 82 | 83 | AuctionSettlementSync settlement 84 | = _services.service(AuctionSettlementSync.class, settlementId); 85 | 86 | AuctionSettlement.Status settleStatus = settlement.settleStatus(); 87 | AuctionSettlement.Status refundStatus = settlement.refundStatus(); 88 | 89 | Assert.assertEquals(AuctionSettlement.Status.SETTLED, 90 | settleStatus); 91 | Assert.assertEquals(AuctionSettlement.Status.NONE, 92 | refundStatus); 93 | 94 | SettlementTransactionState transactionState 95 | = settlement.getTransactionState(); 96 | 97 | Assert.assertEquals(SettlementTransactionState.AuctionUpdateState.SUCCESS, 98 | transactionState.getAuctionStateUpdateState()); 99 | Assert.assertEquals(SettlementTransactionState.AuctionWinnerUpdateState.SUCCESS, 100 | transactionState.getAuctionWinnerUpdateState()); 101 | Assert.assertEquals(SettlementTransactionState.PaymentTxState.SUCCESS, 102 | transactionState.getPaymentState()); 103 | } 104 | 105 | private UserSync createUser(final String name, 106 | final String passwd) throws IOException 107 | { 108 | ResultFuture user = new ResultFuture<>(); 109 | 110 | _users.create(new UserInitData(name, passwd, false), 111 | user.then(id -> _services.service(UserSync.class, 112 | id.toString()))); 113 | 114 | return user.get(1, TimeUnit.SECONDS); 115 | } 116 | 117 | private AuctionSync createAuction(String userId, String title, int bid) 118 | { 119 | ResultFuture auction = new ResultFuture<>(); 120 | 121 | _auctions.create(new AuctionDataInit(userId, title, bid), 122 | auction.then(id -> _services.service(AuctionSync.class, 123 | id.toString()))); 124 | return auction.get(1, TimeUnit.SECONDS); 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/AuctionSettlementEnsureTest.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.io.IOException; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import javax.inject.Inject; 7 | 8 | import io.baratine.service.ResultFuture; 9 | import io.baratine.service.Service; 10 | import io.baratine.service.Services; 11 | 12 | import com.caucho.junit.ConfigurationBaratine; 13 | import com.caucho.junit.RunnerBaratine; 14 | import com.caucho.junit.ServiceTest; 15 | import com.caucho.junit.State; 16 | 17 | import examples.auction.AuctionSession.UserInitData; 18 | import examples.auction.mock.MockPayPal; 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | 23 | @RunWith(RunnerBaratine.class) 24 | @ServiceTest(UserVault.class) 25 | @ServiceTest(AuctionVault.class) 26 | @ServiceTest(AuditServiceImpl.class) 27 | @ServiceTest(AuctionSettlementVault.class) 28 | @ServiceTest(MockPayPal.class) 29 | @ConfigurationBaratine(workDir = "/tmp/baratine", 30 | testTime = ConfigurationBaratine.TEST_TIME) 31 | public class AuctionSettlementEnsureTest 32 | { 33 | @Inject 34 | @Service("/User") 35 | UserVault _users; 36 | 37 | @Inject 38 | @Service("/Auction") 39 | AuctionVault _auctions; 40 | 41 | @Inject 42 | @Service("/AuctionSettlement") 43 | AuctionSettlementVault _settlements; 44 | 45 | @Inject 46 | @Service("/PayPal") 47 | MockPayPal _mockPayPal; 48 | 49 | @Inject 50 | Services _services; 51 | 52 | @Inject 53 | RunnerBaratine _baratine; 54 | 55 | @Test 56 | public void testEnsure() 57 | throws IOException, InterruptedException 58 | { 59 | UserSync spock = createUser("Spock", "passwd"); 60 | UserSync kirk = createUser("Kirk", "passwd"); 61 | 62 | AuctionSync auction = createAuction(spock.get().getEncodedId(), "Book", 12); 63 | 64 | Assert.assertTrue(auction.open()); 65 | Assert.assertTrue(auction.bid(new AuctionBid(kirk.get().getEncodedId(), 66 | 13))); 67 | Assert.assertEquals(13, auction.get().getLastBid().getBid()); 68 | 69 | _mockPayPal.isSettle = false; 70 | 71 | auction.close(); 72 | 73 | String spockId = spock.get().getEncodedId(); 74 | String kirkId = kirk.get().getEncodedId(); 75 | String auctionId = auction.get().getEncodedId(); 76 | 77 | State.sleep(100); 78 | 79 | _baratine.stop(); 80 | 81 | _mockPayPal.isSettle = true; 82 | 83 | _baratine.start(); 84 | 85 | spock = _services.service(UserSync.class, spockId); 86 | kirk = _services.service(UserSync.class, kirkId); 87 | auction = _services.service(AuctionSync.class, auctionId); 88 | 89 | Auction.State state = auction.get().getState(); 90 | 91 | int counter = 100; 92 | while (state != Auction.State.SETTLED && counter-- > 0) { 93 | state = auction.get().getState(); 94 | State.sleep(100); 95 | } 96 | 97 | Assert.assertEquals(Auction.State.SETTLED, state); 98 | 99 | String settlementId = auction.getSettlementId(); 100 | 101 | AuctionSettlementSync settlement 102 | = _services.service(AuctionSettlementSync.class, settlementId); 103 | 104 | AuctionSettlement.Status settleStatus = settlement.settleStatus(); 105 | AuctionSettlement.Status refundStatus = settlement.refundStatus(); 106 | 107 | Assert.assertEquals(AuctionSettlement.Status.SETTLED, 108 | settleStatus); 109 | Assert.assertEquals(AuctionSettlement.Status.NONE, 110 | refundStatus); 111 | 112 | SettlementTransactionState transactionState 113 | = settlement.getTransactionState(); 114 | 115 | Assert.assertEquals(SettlementTransactionState.AuctionUpdateState.SUCCESS, 116 | transactionState.getAuctionStateUpdateState()); 117 | Assert.assertEquals(SettlementTransactionState.AuctionWinnerUpdateState.SUCCESS, 118 | transactionState.getAuctionWinnerUpdateState()); 119 | Assert.assertEquals(SettlementTransactionState.PaymentTxState.SUCCESS, 120 | transactionState.getPaymentState()); 121 | } 122 | 123 | private UserSync createUser(final String name, 124 | final String passwd) throws IOException 125 | { 126 | ResultFuture user = new ResultFuture<>(); 127 | 128 | _users.create(new UserInitData(name, passwd, false), 129 | user.then(id -> _services.service(UserSync.class, 130 | id.toString()))); 131 | 132 | return user.get(1, TimeUnit.SECONDS); 133 | } 134 | 135 | private AuctionSync createAuction(String userId, String title, int bid) 136 | { 137 | ResultFuture auction = new ResultFuture<>(); 138 | 139 | _auctions.create(new AuctionDataInit(userId, title, bid), 140 | auction.then(id -> _services.service(AuctionSync.class, 141 | id.toString()))); 142 | return auction.get(1, TimeUnit.SECONDS); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/AuctionSettlementSync.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | public interface AuctionSettlementSync extends AuctionSettlement 4 | { 5 | Status settle(Auction.Bid bid); 6 | 7 | Status settleResume(); 8 | 9 | Status refund(); 10 | 11 | Status settleStatus(); 12 | 13 | Status refundStatus(); 14 | 15 | SettlementTransactionState getTransactionState(); 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/AuctionSync.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import io.baratine.vault.IdAsset; 4 | 5 | public interface AuctionSync extends Auction 6 | { 7 | IdAsset create(AuctionDataInit initData); 8 | 9 | boolean open(); 10 | 11 | boolean bid(AuctionBid bid) 12 | throws IllegalStateException; 13 | 14 | boolean setAuctionWinner(String user); 15 | 16 | boolean clearAuctionWinner(String user); 17 | 18 | boolean setSettled(); 19 | 20 | boolean setRolledBack(); 21 | 22 | AuctionData get(); 23 | 24 | boolean close(); 25 | 26 | boolean refund(); 27 | 28 | String getSettlementId(); 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/AuctionVaultSync.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.util.List; 4 | 5 | import io.baratine.vault.IdAsset; 6 | 7 | public interface AuctionVaultSync extends AuctionVault 8 | { 9 | IdAsset create(AuctionDataInit data); 10 | 11 | Auction findByTitle(String title); 12 | 13 | List findAuctionDataByTitle(String title); 14 | 15 | List findIdsByTitle(String title); 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/PayPalSync.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | public interface PayPalSync extends PayPal 4 | { 5 | Payment settle(AuctionData auction, 6 | Auction.Bid bid, 7 | CreditCard creditCard, 8 | String payPalRequestId); 9 | 10 | Refund refund(String settlementId, 11 | String payPalRequestId, 12 | String sale); 13 | 14 | void configure(Payment state, long sleep, boolean isSettle); 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/UserReplayTest.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import javax.inject.Inject; 4 | 5 | import io.baratine.service.Service; 6 | import io.baratine.service.ServiceRef; 7 | import io.baratine.service.Services; 8 | import io.baratine.vault.IdAsset; 9 | 10 | import com.caucho.junit.ConfigurationBaratine; 11 | import com.caucho.junit.RunnerBaratine; 12 | import com.caucho.junit.ServiceTest; 13 | 14 | import org.junit.Assert; 15 | import org.junit.Test; 16 | import org.junit.runner.RunWith; 17 | 18 | /** 19 | * Unit test for user create() with journal replay 20 | */ 21 | @RunWith(RunnerBaratine.class) 22 | @ServiceTest(UserVault.class) 23 | @ConfigurationBaratine(workDir = "/tmp/baratine", 24 | testTime = ConfigurationBaratine.TEST_TIME, 25 | journalDelay = 12000) 26 | public class UserReplayTest 27 | { 28 | @Inject 29 | @Service("/User") 30 | UserVaultSync _userManager; 31 | 32 | @Inject 33 | Services _services; 34 | 35 | @Inject 36 | @Service("/User") 37 | ServiceRef _userManagerRef; 38 | 39 | @Inject 40 | RunnerBaratine _baratine; 41 | 42 | /** 43 | * User create correctly sets the user name. 44 | */ 45 | @Test 46 | public void createUser() 47 | { 48 | IdAsset idAsset = _userManager.create( 49 | new AuctionSession.UserInitData("Spock", "Password", false)); 50 | 51 | _baratine.stopImmediate(); 52 | _baratine.start(); 53 | 54 | UserSync user = _services.service(UserSync.class, idAsset.toString()); 55 | 56 | UserData userData = user.get(); 57 | 58 | Assert.assertEquals(idAsset.toString(), userData.getEncodedId()); 59 | Assert.assertEquals("Spock", userData.getName()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/UserSync.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import io.baratine.vault.IdAsset; 4 | 5 | public interface UserSync extends User 6 | { 7 | IdAsset create(AuctionUserSessionImpl.UserInitData user); 8 | 9 | boolean authenticate(String password, 10 | boolean isAdmin); 11 | 12 | UserData get(); 13 | 14 | CreditCard getCreditCard(); 15 | 16 | boolean addWonAuction(String auction); 17 | 18 | boolean removeWonAuction(String auction); 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/UserTest.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import javax.inject.Inject; 6 | 7 | import io.baratine.service.ResultFuture; 8 | import io.baratine.service.Service; 9 | import io.baratine.service.Services; 10 | import io.baratine.vault.IdAsset; 11 | 12 | import com.caucho.junit.RunnerBaratine; 13 | import com.caucho.junit.ServiceTest; 14 | 15 | import examples.auction.AuctionSession.UserInitData; 16 | import org.junit.Assert; 17 | import org.junit.Test; 18 | import org.junit.runner.RunWith; 19 | 20 | /** 21 | * Unit test for simple App. 22 | */ 23 | @RunWith(RunnerBaratine.class) 24 | @ServiceTest(UserVault.class) 25 | public class UserTest 26 | { 27 | @Inject 28 | @Service("/User") 29 | UserVaultSync _userVault; 30 | 31 | @Inject 32 | Services _services; 33 | 34 | /** 35 | * User create correctly sets the user name. 36 | */ 37 | @Test 38 | public void createUser() 39 | { 40 | IdAsset idAsset 41 | = _userVault.create(new UserInitData("Spock", "Password", false)); 42 | 43 | User user = _services.service(User.class, idAsset.toString()); 44 | 45 | ResultFuture userDataResult = new ResultFuture<>(); 46 | 47 | user.get(userDataResult); 48 | 49 | UserData userData = userDataResult.get(1, TimeUnit.SECONDS); 50 | 51 | Assert.assertEquals("Spock", userData.getName()); 52 | } 53 | 54 | @Test 55 | public void authenticateUser() 56 | { 57 | IdAsset idAsset 58 | = _userVault.create(new UserInitData("Spock", "Password", false)); 59 | 60 | User user 61 | = Services.current().service(User.class, idAsset.toString()); 62 | 63 | ResultFuture authResultAllow = new ResultFuture<>(); 64 | user.authenticate("Password", false, authResultAllow); 65 | 66 | Assert.assertTrue(authResultAllow.get(1, TimeUnit.SECONDS)); 67 | 68 | ResultFuture authResultReject = new ResultFuture<>(); 69 | user.authenticate("bogus", false, authResultReject); 70 | 71 | Assert.assertFalse(authResultReject.get(1, TimeUnit.SECONDS)); 72 | } 73 | 74 | @Test 75 | public void findUser() 76 | { 77 | final IdAsset idAsset 78 | = _userVault.create(new UserInitData("Doug", "Password", false)); 79 | 80 | final UserSync user 81 | = _services.service(UserSync.class, idAsset.toString()); 82 | 83 | Assert.assertEquals("Doug", user.get().getName()); 84 | 85 | final User doug = _userVault.findByName("Doug"); 86 | 87 | ResultFuture data = new ResultFuture<>(); 88 | 89 | doug.get(data); 90 | 91 | Assert.assertEquals("DVS1aMAAR3I", 92 | data.get(1, TimeUnit.SECONDS).getEncodedId()); 93 | 94 | final User bogus = _userVault.findByName("bogus"); 95 | 96 | Assert.assertNull(bogus); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/UserVaultSync.java: -------------------------------------------------------------------------------- 1 | package examples.auction; 2 | 3 | import io.baratine.vault.IdAsset; 4 | 5 | public interface UserVaultSync extends UserVault 6 | { 7 | IdAsset create(AuctionUserSession.UserInitData userInitData); 8 | 9 | User findByName(String name); 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/mock/MockPayPal.java: -------------------------------------------------------------------------------- 1 | package examples.auction.mock; 2 | 3 | import io.baratine.service.Result; 4 | import io.baratine.service.Service; 5 | 6 | import examples.auction.Auction; 7 | import examples.auction.AuctionData; 8 | import examples.auction.CreditCard; 9 | import examples.auction.PayPal; 10 | import examples.auction.Payment; 11 | import examples.auction.Refund; 12 | 13 | @Service("/PayPal") 14 | public class MockPayPal implements PayPal 15 | { 16 | public static boolean isSettle = true; 17 | 18 | private Payment _payment = new MockPayment("sale-id-0", 19 | Payment.PaymentState.approved); 20 | private long _sleep = 0; 21 | 22 | @Override 23 | public void settle(AuctionData auction, 24 | Auction.Bid bid, 25 | CreditCard creditCard, 26 | String payPalRequestId, 27 | Result result) 28 | { 29 | if (isSettle) { 30 | try { 31 | Thread.sleep(_sleep); 32 | } catch (InterruptedException e) { 33 | throw new RuntimeException(e); 34 | } 35 | 36 | result.ok(_payment); 37 | } 38 | } 39 | 40 | @Override 41 | public void refund(String settlementId, 42 | String payPalRequestId, 43 | String sale, 44 | Result result) 45 | { 46 | Refund refund = new MockRefund(Refund.RefundState.completed); 47 | 48 | result.ok(refund); 49 | } 50 | 51 | public void configure(Payment payment, 52 | long sleep, 53 | Result result) 54 | { 55 | _payment = payment; 56 | _sleep = sleep; 57 | 58 | result.ok(null); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/mock/MockPayment.java: -------------------------------------------------------------------------------- 1 | package examples.auction.mock; 2 | 3 | import examples.auction.Payment; 4 | 5 | public class MockPayment implements Payment 6 | { 7 | private String _saleId; 8 | private PaymentState _state; 9 | 10 | public MockPayment() 11 | { 12 | } 13 | 14 | public MockPayment(String saleId, PaymentState state) 15 | { 16 | _saleId = saleId; 17 | _state = state; 18 | } 19 | 20 | @Override 21 | public PaymentState getState() 22 | { 23 | return _state; 24 | } 25 | 26 | @Override 27 | public String getSaleId() 28 | { 29 | return _saleId; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/examples/auction/mock/MockRefund.java: -------------------------------------------------------------------------------- 1 | package examples.auction.mock; 2 | 3 | import examples.auction.Refund; 4 | 5 | public class MockRefund implements Refund 6 | { 7 | private RefundState _state; 8 | 9 | public MockRefund() 10 | { 11 | } 12 | 13 | public MockRefund(RefundState state) 14 | { 15 | _state = state; 16 | } 17 | 18 | @Override 19 | public RefundState getStatus() 20 | { 21 | return _state; 22 | } 23 | } 24 | --------------------------------------------------------------------------------