Commit 528b594c authored by Christos Tranoris's avatar Christos Tranoris
Browse files

adding search and find resources by category or name

parent 802e6a2f
Loading
Loading
Loading
Loading
Loading
+146 −1
Original line number Diff line number Diff line
# org.etsi.osl.tmf.api

TMF OpenAPIs implementation.
TMF OpenAPIs implementation for the OpenSlice ETSI project. This module implements multiple TeleManagement Forum (TMF) REST APIs with Spring Boot, Apache Camel messaging, JPA persistence, and event-driven architecture.

## Overview

This module provides implementations of the following TMF OpenAPIs:

| API Code | Name | Package |
|----------|------|---------|
| ri639 | Resource Inventory Management | `org.etsi.osl.tmf.ri639` |
| rcm634 | Resource Catalog Management | `org.etsi.osl.tmf.rcm634` |
| scm633 | Service Catalog Management | `org.etsi.osl.tmf.scm633` |
| sim638 | Service Inventory Management | `org.etsi.osl.tmf.sim638` |
| so641 | Service Ordering Management | `org.etsi.osl.tmf.so641` |
| pcm620 | Product Catalog Management | `org.etsi.osl.tmf.pcm620` |
| pom622 | Product Ordering Management | `org.etsi.osl.tmf.pom622` |
| cm629 | Customer Management | `org.etsi.osl.tmf.cm629` |
| pm628 | Performance Management | `org.etsi.osl.tmf.pm628` |
| am642 | Alarm Management | `org.etsi.osl.tmf.am642` |
| am666 | Account Management | `org.etsi.osl.tmf.am666` |
| am651 | Agreement Management | `org.etsi.osl.tmf.am651` |

## Architecture

Each TMF API implementation follows a consistent 3-layer architecture:

```
org.etsi.osl.tmf.<api-code>/
├── api/                    # REST Controllers & Apache Camel Routes
│   ├── *Api.java          # Interface (auto-generated from OpenAPI)
│   ├── *ApiController.java # REST Controller implementation
│   └── *ApiRouteBuilder.java # Apache Camel route definitions
├── repo/                   # JPA Repositories
│   └── *Repository.java   # Spring Data JPA repository interfaces
└── reposervices/          # Business Logic Layer
    └── *RepoService.java  # Service classes with business logic
```

## Build & Run

### Building
```bash
mvn clean install
```

### Running Tests
```bash
# All tests
mvn test

# Single test class
mvn test -Dtest=ServiceCatalogManagementNotificationEndToEndTest

# Single test method
mvn test -Dtest=ServiceCatalogManagementNotificationEndToEndTest#testCompleteServiceCatalogManagementNotificationFlow
```

### Running Application
```bash
mvn spring-boot:run
```

## Key Features

- **Apache Camel Integration**: Message-driven routes for async operations via JMS queues/topics
- **Event-Driven Architecture**: Automatic notification publishing when entities change
- **JPA Persistence**: Hibernate ORM with H2 (test) and MySQL (production)
- **OAuth2 Security**: Keycloak integration with Spring Security
- **HTTP Callbacks**: Subscribe to resource/service changes via REST callbacks
- **Transaction Management**: Proper handling of distributed transactions with Camel

## Resource Inventory API (ri639) - Recent Updates

### New Category-based Query Routes

The Resource Inventory API now supports retrieving resources filtered by category:

#### CATALOG_GET_RESOURCE_BY_CATEGORY Route
- **Endpoint**: `jms:queue:CATALOG.GET.RESOURCE_BY_CATEGORY`
- **Header Parameter**: `category` (String) - The category to filter by
- **Response**: JSON array of resource summaries
- **Fields Returned**: `id`, `@type`, `name`, `category`, `description`
- **Usage**: Quick listing of resources without full entity details

#### Service Methods

1. **getResourcesByCategory(String category)**
   - Lightweight resource summaries as `List<Map<String, Object>>`
   - Efficient HQL querying
   - Ordered by resource name

2. **getDetailedResourcesByCategory(String categoryName)**
   - Full `List<Resource>` entities with all relationships
   - Eagerly initializes lazy collections (characteristics, notes, related parties, etc.)
   - Error handling and transaction management included

### Example Usage

```java
// Via ProducerTemplate
template.sendBodyAndHeaders(
    "jms:queue:CATALOG.GET.RESOURCE_BY_CATEGORY",
    null,
    Map.of("category", "NetworkEquipment")
);

// Direct method call - lightweight
List<Map<String, Object>> resources =
    resourceRepoService.getResourcesByCategory("NetworkEquipment");

// Direct method call - detailed
List<Resource> detailedResources =
    resourceRepoService.getDetailedResourcesByCategory("NetworkEquipment");
```

## Database Configuration

- **Production**: MySQL (see `application.yml`)
- **Testing**: H2 in-memory with MySQL compatibility mode (see `application-testing.yml`)
- **ORM**: Hibernate/JPA with custom `LocalMysqlDialect`
- **Connection Pooling**: HikariCP

## Testing

- Base class: `org.etsi.osl.services.api.BaseIT`
- Profile: `@ActiveProfiles("testing")`
- Database: H2 in-memory (auto-configured)
- Thread safety: 3 forks, alphabetical order, no parallelism
- Memory optimization: JaCoCo disabled, connection pool size reduced

## Documentation

See `CLAUDE.md` for detailed architecture documentation, testing best practices, and implementation guidelines for developers.

## Dependencies

- Spring Boot (Web, JPA, Security, ActiveMQ)
- Apache Camel
- Keycloak
- Hibernate
- Lombok
- MapStruct
- Mockito

## License

Licensed under the Apache License 2.0. See LICENSE file for details.
+1 −1
Original line number Diff line number Diff line
@@ -303,7 +303,7 @@ public class ResourceRepoService {
          "LEFT JOIN FETCH r.resourceRelationship " +
          "LEFT JOIN FETCH r.attachment " +
          "LEFT JOIN FETCH r.activationFeature " +
          "WHERE r.category = :category " +
          "WHERE r.category LIKE :category " +
          "ORDER BY r.name ASC";

      List<Resource> result = session.createQuery(hql, Resource.class)