-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ContextMapper/feature/discovery-aggregates…
…-by-spring-resources Discover Aggregates and Entities in Spring Boot discovery strategy
- Loading branch information
Showing
32 changed files
with
1,797 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/main/java/org/contextmapper/discovery/model/Aggregate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright 2019 The Context Mapper Project Team | ||
* | ||
* Licensed 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.contextmapper.discovery.model; | ||
|
||
import org.apache.commons.lang3.builder.EqualsBuilder; | ||
import org.apache.commons.lang3.builder.HashCodeBuilder; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Represents a discovered Aggregate. | ||
* | ||
* @author Stefan Kapferer | ||
*/ | ||
public class Aggregate { | ||
|
||
private String name; | ||
private Set<Entity> entities; | ||
|
||
public Aggregate(String name) { | ||
setName(name); | ||
this.entities = new HashSet<>(); | ||
} | ||
|
||
/** | ||
* Sets the name of this Aggregate. | ||
* | ||
* @param name the name of the Aggregate. | ||
*/ | ||
public void setName(String name) { | ||
if (name == null || "".equals(name)) | ||
throw new IllegalArgumentException("The name of an Aggregate must not be null or empty."); | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* Gets the name of this Aggregate. | ||
* | ||
* @return the name of the Aggregate as String | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* Adds an entity to the Aggregate. | ||
* | ||
* @param entity the entity to be added to the Aggregate | ||
*/ | ||
public void addEntity(Entity entity) { | ||
this.entities.add(entity); | ||
} | ||
|
||
/** | ||
* Adds all entities in the given set to the Aggregate. | ||
* | ||
* @param entities the set of entities to be added to the Aggregate | ||
*/ | ||
public void addEntities(Set<Entity> entities) { | ||
this.entities.addAll(entities); | ||
} | ||
|
||
/** | ||
* Gets the set of entities within the Aggregate. | ||
* | ||
* @return the set of entities which are part of the Aggregate | ||
*/ | ||
public Set<Entity> getEntities() { | ||
return new HashSet<>(entities); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (!(object instanceof Aggregate)) | ||
return false; | ||
|
||
Aggregate bc = (Aggregate) object; | ||
|
||
return new EqualsBuilder() | ||
.append(name, bc.name) | ||
.isEquals(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return new HashCodeBuilder() | ||
.append(name) | ||
.hashCode(); | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
src/main/java/org/contextmapper/discovery/model/Attribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright 2019 The Context Mapper Project Team | ||
* | ||
* Licensed 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.contextmapper.discovery.model; | ||
|
||
import org.apache.commons.lang3.builder.EqualsBuilder; | ||
import org.apache.commons.lang3.builder.HashCodeBuilder; | ||
|
||
/** | ||
* Represents an entity attribute (primitive types). | ||
* For references to other non-primitive types use {@link Reference}. | ||
* | ||
* @author Stefan Kapferer | ||
*/ | ||
public class Attribute { | ||
|
||
private Entity parent; | ||
private String name; | ||
private String type; | ||
private String collectionType; | ||
|
||
public Attribute(String type, String name) { | ||
this.type = type; | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* Gets the name of the attribute. | ||
* | ||
* @return the name of the attribute | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* Gets the type of the attribute. | ||
* | ||
* @return the type of the attribute | ||
*/ | ||
public String getType() { | ||
return type; | ||
} | ||
|
||
/** | ||
* Gets the parent entity containing this attribute. | ||
* | ||
* @return the parent entity containing this attribute | ||
*/ | ||
public Entity getParent() { | ||
return parent; | ||
} | ||
|
||
/** | ||
* Sets the parent entity containing this attribute. | ||
* | ||
* @param parent the parent entity containing this attribute | ||
*/ | ||
public void setParent(Entity parent) { | ||
this.parent = parent; | ||
} | ||
|
||
/** | ||
* Sets the collection type of the reference attribute. | ||
* | ||
* @param collectionType the collection type of the reference attribute | ||
*/ | ||
public void setCollectionType(String collectionType) { | ||
this.collectionType = collectionType; | ||
} | ||
|
||
/** | ||
* Gets the collection type of the reference attribute. | ||
* | ||
* @return the collection type of the reference attribute | ||
*/ | ||
public String getCollectionType() { | ||
return collectionType; | ||
} | ||
|
||
/** | ||
* Returns whether the reference attribute is a collection of references or not. | ||
* | ||
* @return true, if the reference attribute is a collection of references. false otherwise. | ||
*/ | ||
public boolean isCollection() { | ||
return collectionType == null || "".equals(collectionType); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (!(object instanceof Attribute)) | ||
return false; | ||
|
||
Attribute attribute = (Attribute) object; | ||
|
||
return new EqualsBuilder() | ||
.append(parent, attribute.parent) | ||
.append(name, attribute.name) | ||
.isEquals(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return new HashCodeBuilder() | ||
.append(parent) | ||
.append(name) | ||
.hashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.