Skip to content

Commit

Permalink
fix: remove unused stuff and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StephGit committed Jan 3, 2025
1 parent d9001ec commit 48a7071
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
import ch.puzzle.itc.mobiliar.business.function.entity.AmwFunctionEntity;
import ch.puzzle.itc.mobiliar.business.property.entity.MikEntity;
import ch.puzzle.itc.mobiliar.business.resourcegroup.control.ResourceRepository;
import ch.puzzle.itc.mobiliar.business.resourcegroup.control.ResourceTypeRepository;
import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceEntity;
import ch.puzzle.itc.mobiliar.business.resourcegroup.entity.ResourceTypeEntity;
import ch.puzzle.itc.mobiliar.business.template.entity.RevisionInformation;
import ch.puzzle.itc.mobiliar.business.utils.Identifiable;
import ch.puzzle.itc.mobiliar.common.exception.NotFoundException;
import org.hibernate.Hibernate;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory;

Expand All @@ -46,12 +44,8 @@ public class FunctionService {
@Inject
ResourceRepository resourceRepository;

@Inject
ResourceTypeRepository resourceTypeRepository;

@Inject
EntityManager entityManager;

/**
* Returns all (overwritable) functions, which are defined on all parent resource types of the given resource instance - except the functions which are already defined on the given resource instance.
*/
Expand Down Expand Up @@ -90,10 +84,6 @@ public List<AmwFunctionEntity> getAllOverwritableSupertypeFunctions(ResourceType
private Map<String, AmwFunctionEntity> getAllTypeAndSuperTypeFunctions(ResourceTypeEntity resourceTypeEntity) {
Map<String, AmwFunctionEntity> superTypeFunctions = new LinkedHashMap<>();
if (resourceTypeEntity != null) {
if (!Hibernate.isInitialized(resourceTypeEntity.getFunctions())) {
resourceTypeEntity = resourceTypeRepository.loadWithFunctionsAndMiksForId(resourceTypeEntity.getId());
}

for (AmwFunctionEntity function : resourceTypeEntity.getFunctions()) {
AmwFunctionEntity functionWithMik = functionRepository.getFunctionByIdWithMiksAndParentChildFunctions(function.getId());
superTypeFunctions.put(function.getName(), functionWithMik);
Expand All @@ -116,7 +106,6 @@ private Map<String, AmwFunctionEntity> getAllTypeAndSuperTypeFunctions(ResourceT
* <li>All functions of the resource</li>
* <li>Functions of the parent resourceTypes if not overwritten by the resource itself</li>
* </ul>
*
* @param resource
* @return a list of AmwFunctions
*/
Expand All @@ -132,7 +121,6 @@ public List<AmwFunctionEntity> getAllFunctionsForResource(ResourceEntity resourc

/**
* Find the function for the given mik
*
* @param functions
* @param mik
* @return AmwFunctionEntity
Expand Down Expand Up @@ -228,19 +216,13 @@ private List<AmwFunctionEntity> findAllResourceFunctionsByName(ResourceEntity re
private Map<String, AmwFunctionEntity> getAllSubTypeAndResourceFunctions(ResourceTypeEntity resourceTypeEntity) {
Map<String, AmwFunctionEntity> subTypeFunctions = new LinkedHashMap<>();

if (!Hibernate.isInitialized(resourceTypeEntity.getResources())) {
resourceTypeEntity = resourceTypeRepository.loadWithResources(resourceTypeEntity.getId());
}

for (ResourceEntity resource : resourceTypeEntity.getResources()) {
resource = resourceRepository.loadWithFunctionsAndMiksForId(resource.getId());
for (AmwFunctionEntity function : resource.getFunctions()) {
subTypeFunctions.put(function.getName(), function);
}
}

for (ResourceTypeEntity subResourceType : resourceTypeEntity.getChildrenResourceTypes()) {
subResourceType = resourceTypeRepository.loadWithFunctionsAndMiksForId(subResourceType.getId());
for (AmwFunctionEntity function : subResourceType.getFunctions()) {
subTypeFunctions.put(function.getName(), function);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,4 @@ public ResourceTypeEntity getByName(String resourceTypeName) {
public ResourceTypeEntity getResourceType(Integer resourceTypeId) {
return entityManager.find(ResourceTypeEntity.class, resourceTypeId);
}

public ResourceTypeEntity loadWithResources(Integer id) {
List<ResourceTypeEntity> entity = entityManager
.createQuery("select r from ResourceTypeEntity r " +
"left join fetch r.resources f " +
"where r.id=:resTypeId", ResourceTypeEntity.class)
.setParameter("resTypeId", id).setMaxResults(1).getResultList();
return entity.isEmpty() ? null : entity.get(0);
}
}

0 comments on commit 48a7071

Please sign in to comment.