Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [REST API] Fix ServiceConfigurations to return KapuaIllegalArgument instead of 204 #4064

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import org.eclipse.kapua.KapuaEntityNotFoundException;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.KapuaIllegalArgumentException;
import org.eclipse.kapua.app.api.core.model.ScopeId;
import org.eclipse.kapua.app.api.core.resources.AbstractKapuaResource;
import org.eclipse.kapua.commons.configuration.metatype.EmptyTocd;
Expand Down Expand Up @@ -86,10 +87,11 @@
}
for (ServiceComponentConfiguration serviceComponentConfiguration : serviceConfiguration.getComponentConfigurations()) {
Class<KapuaService> configurableServiceClass = (Class<KapuaService>) Class.forName(serviceComponentConfiguration.getId()).asSubclass(KapuaService.class);
if (KapuaConfigurableService.class.isAssignableFrom(configurableServiceClass)) {
KapuaConfigurableService configurableService = (KapuaConfigurableService) locator.getService(configurableServiceClass);
configurableService.setConfigValues(scopeId, account.getScopeId(), serviceComponentConfiguration.getProperties());
if (!KapuaConfigurableService.class.isAssignableFrom(configurableServiceClass)) {
throw new KapuaIllegalArgumentException("serviceComponentConfiguration.id", serviceComponentConfiguration.getId());

Check warning on line 91 in rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/ServiceConfigurations.java

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/ServiceConfigurations.java#L91

Added line #L91 was not covered by tests
}
KapuaConfigurableService configurableService = (KapuaConfigurableService) locator.getService(configurableServiceClass);
configurableService.setConfigValues(scopeId, account.getScopeId(), serviceComponentConfiguration.getProperties());

Check warning on line 94 in rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/ServiceConfigurations.java

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/ServiceConfigurations.java#L93-L94

Added lines #L93 - L94 were not covered by tests
}
return Response.noContent().build();
}
Expand All @@ -102,17 +104,18 @@
@PathParam("serviceId") String serviceId
) throws KapuaException, ClassNotFoundException {
Class<KapuaService> configurableServiceClass = (Class<KapuaService>) Class.forName(serviceId).asSubclass(KapuaService.class);
if (KapuaConfigurableService.class.isAssignableFrom(configurableServiceClass)) {
KapuaConfigurableService configurableService = (KapuaConfigurableService) locator.getService(configurableServiceClass);
KapuaTocd metadata = configurableService.getConfigMetadata(scopeId);
Map<String, Object> values = configurableService.getConfigValues(scopeId);
if (metadata != null && !(metadata instanceof EmptyTocd)) {
ServiceComponentConfiguration serviceComponentConfiguration = serviceConfigurationFactory.newComponentConfigurationInstance(metadata.getId());
serviceComponentConfiguration.setDefinition(metadata);
serviceComponentConfiguration.setName(metadata.getName());
serviceComponentConfiguration.setProperties(values);
return serviceComponentConfiguration;
}
if (!KapuaConfigurableService.class.isAssignableFrom(configurableServiceClass)) {
throw new KapuaIllegalArgumentException("service.pid", serviceId);

Check warning on line 108 in rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/ServiceConfigurations.java

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/ServiceConfigurations.java#L108

Added line #L108 was not covered by tests
}
KapuaConfigurableService configurableService = (KapuaConfigurableService) locator.getService(configurableServiceClass);
KapuaTocd metadata = configurableService.getConfigMetadata(scopeId);
Map<String, Object> values = configurableService.getConfigValues(scopeId);

Check warning on line 112 in rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/ServiceConfigurations.java

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/ServiceConfigurations.java#L110-L112

Added lines #L110 - L112 were not covered by tests
if (metadata != null && !(metadata instanceof EmptyTocd)) {
ServiceComponentConfiguration serviceComponentConfiguration = serviceConfigurationFactory.newComponentConfigurationInstance(metadata.getId());
serviceComponentConfiguration.setDefinition(metadata);
serviceComponentConfiguration.setName(metadata.getName());
serviceComponentConfiguration.setProperties(values);
return serviceComponentConfiguration;

Check warning on line 118 in rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/ServiceConfigurations.java

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/ServiceConfigurations.java#L114-L118

Added lines #L114 - L118 were not covered by tests
}
return null;
}
Expand All @@ -131,10 +134,11 @@
throw new KapuaEntityNotFoundException(Account.TYPE, scopeId);
}
Class<KapuaService> configurableServiceClass = (Class<KapuaService>) Class.forName(serviceId).asSubclass(KapuaService.class);
if (KapuaConfigurableService.class.isAssignableFrom(configurableServiceClass)) {
KapuaConfigurableService configurableService = (KapuaConfigurableService) locator.getService(configurableServiceClass);
configurableService.setConfigValues(scopeId, account.getScopeId(), serviceComponentConfiguration.getProperties());
if (!KapuaConfigurableService.class.isAssignableFrom(configurableServiceClass)) {
throw new KapuaIllegalArgumentException("service.pid", serviceId);

Check warning on line 138 in rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/ServiceConfigurations.java

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/ServiceConfigurations.java#L138

Added line #L138 was not covered by tests
}
KapuaConfigurableService configurableService = (KapuaConfigurableService) locator.getService(configurableServiceClass);
configurableService.setConfigValues(scopeId, account.getScopeId(), serviceComponentConfiguration.getProperties());

Check warning on line 141 in rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/ServiceConfigurations.java

View check run for this annotation

Codecov / codecov/patch

rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/ServiceConfigurations.java#L140-L141

Added lines #L140 - L141 were not covered by tests
return Response.noContent().build();
}

Expand Down
Loading