You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2012/12/07 19:16:21 UTC

[1/12] git commit: ISIS-188: refactoring artifactIds - examples

Updated Branches:
  refs/heads/master 255ef5146 -> 782a86bb2


ISIS-188: refactoring artifactIds - examples


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/782a86bb
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/782a86bb
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/782a86bb

Branch: refs/heads/master
Commit: 782a86bb29506c83b0abb386017b9f06623aefbc
Parents: 789c619
Author: Dan Haywood <da...@apache.org>
Authored: Fri Dec 7 18:15:57 2012 +0000
Committer: Dan Haywood <da...@apache.org>
Committed: Fri Dec 7 18:15:57 2012 +0000

----------------------------------------------------------------------
 .../claims/dom/claim/ClaimRepositoryDefault.java   |  133 +++++++++++++++
 .../dom/employee/EmployeeRepositoryDefault.java    |   59 +++++++
 2 files changed, 192 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/782a86bb/example/application/claims/dom/src/main/java/org/apache/isis/example/claims/dom/claim/ClaimRepositoryDefault.java
----------------------------------------------------------------------
diff --git a/example/application/claims/dom/src/main/java/org/apache/isis/example/claims/dom/claim/ClaimRepositoryDefault.java b/example/application/claims/dom/src/main/java/org/apache/isis/example/claims/dom/claim/ClaimRepositoryDefault.java
new file mode 100644
index 0000000..b526e39
--- /dev/null
+++ b/example/application/claims/dom/src/main/java/org/apache/isis/example/claims/dom/claim/ClaimRepositoryDefault.java
@@ -0,0 +1,133 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.example.claims.dom.claim;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.isis.applib.AbstractFactoryAndRepository;
+import org.apache.isis.applib.filter.Filter;
+import org.apache.isis.applib.value.Date;
+
+public class ClaimRepositoryDefault extends AbstractFactoryAndRepository implements ClaimRepository {
+
+    // {{ Id, iconName
+    @Override
+    public String getId() {
+        return "claims";
+    }
+
+    public String iconName() {
+        return "ClaimRepository";
+    }
+
+    // }}
+
+    // {{ action: allClaims
+    @Override
+    public List<Claim> allClaims() {
+        return allInstances(Claim.class);
+    }
+
+    // }}
+
+    // {{ action: findClaims
+    @Override
+    public List<Claim> findClaims(final String description) {
+        return allMatches(Claim.class, description);
+    }
+
+    // }}
+
+    // {{ action: claimsFor
+    @Override
+    public List<Claim> claimsFor(final Claimant claimant) {
+        final Claim pattern = newTransientInstance(Claim.class);
+        pattern.setDescription(null);
+        pattern.setApprover(null);
+        pattern.setStatus(null);
+        pattern.setDate(null);
+        pattern.setClaimant(claimant);
+        return allMatches(Claim.class, pattern);
+    }
+
+    // }}
+
+    // {{ action: newClaim
+    @Override
+    public Claim newClaim(final Claimant claimant) {
+        final Claim claim = newTransientInstance(Claim.class);
+        if (claimant != null) {
+            claim.setClaimant(claimant);
+            claim.setApprover(claimant.getDefaultApprover());
+        }
+        return claim;
+    }
+
+    // }}
+
+    // {{ action: newClaimWithDescription
+    @Override
+    public Claim newClaimWithDescription(final Claimant claimant, final String description) {
+        final Claim claim = newClaim(claimant);
+        claim.setDescription(description);
+        return claim;
+    }
+
+    // }}
+
+    // {{ action: claimsSince
+    @Override
+    public List<Claim> claimsSince(final Claimant claimant, final Date since) {
+        return allMatches(Claim.class, new Filter<Claim>() {
+
+            @Override
+            public boolean accept(final Claim pojo) {
+                return pojo.getClaimant() == claimant && pojo.getDate() != null && pojo.getDate().isGreaterThan(since);
+            }
+        });
+    }
+
+    public String validateClaimsSince(final Claimant claimant, final Date since) {
+        final Date today = new Date();
+        return since.isGreaterThan(today) ? "cannot be after today" : null;
+    }
+
+    // }}
+
+    @Override
+    public int countClaimsFor(final Claimant claimant) {
+        return claimsFor(claimant).size();
+    }
+
+    @Override
+    public Claim mostRecentClaim(final Claimant claimant) {
+        final List<Claim> claims = claimsFor(claimant);
+        Collections.sort(claims, new Comparator<Claim>() {
+            @Override
+            public int compare(final Claim o1, final Claim o2) {
+                return o1.getDate().isLessThan(o2.getDate()) ? +1 : -1;
+            }
+        });
+        return claims.size() > 0 ? claims.get(0) : null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/782a86bb/example/application/claims/dom/src/main/java/org/apache/isis/example/claims/dom/employee/EmployeeRepositoryDefault.java
----------------------------------------------------------------------
diff --git a/example/application/claims/dom/src/main/java/org/apache/isis/example/claims/dom/employee/EmployeeRepositoryDefault.java b/example/application/claims/dom/src/main/java/org/apache/isis/example/claims/dom/employee/EmployeeRepositoryDefault.java
new file mode 100644
index 0000000..d756874
--- /dev/null
+++ b/example/application/claims/dom/src/main/java/org/apache/isis/example/claims/dom/employee/EmployeeRepositoryDefault.java
@@ -0,0 +1,59 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.example.claims.dom.employee;
+
+import java.util.List;
+
+import org.apache.isis.applib.AbstractFactoryAndRepository;
+
+public class EmployeeRepositoryDefault extends AbstractFactoryAndRepository implements EmployeeRepository {
+
+    // {{ Id, iconName
+    @Override
+    public String getId() {
+        return "claimants";
+    }
+
+    public String iconName() {
+        return "EmployeeRepository";
+    }
+
+    // }}
+
+    // {{ action: allEmployees
+    @Override
+    public List<Employee> allEmployees() {
+        return allInstances(Employee.class);
+    }
+
+    // }}
+
+    // {{ action: findEmployees
+    @Override
+    public List<Employee> findEmployees(final String name) {
+        return allMatches(Employee.class, name);
+    }
+
+    // }}
+    @Override
+    public EmployeeTakeOn newEmployee() {
+        return newTransientInstance(EmployeeTakeOn.class);
+    }
+}