Search in sources :

Example 11 with Subscription

use of org.ligoj.app.model.Subscription in project ligoj-api by ligoj.

the class PluginsClassLoaderTest method newSubscription.

private Subscription newSubscription() {
    Subscription subscription = new Subscription();
    Node node = new Node();
    node.setId("service:id:ldap:server1");
    Node tool = new Node();
    tool.setId("service:id:ldap");
    Node service = new Node();
    service.setId("service:id");
    tool.setRefined(service);
    node.setRefined(tool);
    subscription.setNode(node);
    subscription.setId(42);
    return subscription;
}
Also used : Node(org.ligoj.app.model.Node) Subscription(org.ligoj.app.model.Subscription)

Example 12 with Subscription

use of org.ligoj.app.model.Subscription in project ligoj-api by ligoj.

the class ToVoConverter method apply.

@Override
public ProjectVo apply(final Project entity) {
    final ProjectVo vo = new ProjectVo();
    vo.copyAuditData(entity, userConverter);
    DescribedBean.copy(entity, vo);
    vo.setPkey(entity.getPkey());
    vo.setTeamLeader(userConverter.apply(entity.getTeamLeader()));
    // Build the subscriptions
    final Map<Integer, SubscriptionVo> subscriptions = new TreeMap<>();
    for (final Object[] resultSet : this.subscriptionsAndParam) {
        // Add subscription value
        final ParameterValue parameterValue = (ParameterValue) resultSet[1];
        addVo(subscriptions, (Subscription) resultSet[0]).getParameters().put(parameterValue.getParameter().getId(), ParameterValueResource.parseValue(parameterValue, new ParameterValueVo()));
    }
    // Merge with subscription without parameters
    entity.getSubscriptions().forEach(s -> addVo(subscriptions, s));
    // Return the subscription to order by the related node
    vo.setSubscriptions(subscriptions.values().stream().sorted(Comparator.comparing(s -> s.getNode().getId(), String::compareTo)).collect(Collectors.toList()));
    return vo;
}
Also used : ParameterValueResource(org.ligoj.app.resource.node.ParameterValueResource) NodeStatus(org.ligoj.app.api.NodeStatus) SubscriptionVo(org.ligoj.app.resource.subscription.SubscriptionVo) HashMap(java.util.HashMap) EventVo(org.ligoj.app.resource.node.EventVo) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ParameterValueVo(org.ligoj.app.resource.node.ParameterValueVo) List(java.util.List) NodeResource(org.ligoj.app.resource.node.NodeResource) TreeMap(java.util.TreeMap) Map(java.util.Map) UserOrg(org.ligoj.app.iam.UserOrg) Subscription(org.ligoj.app.model.Subscription) Comparator(java.util.Comparator) ParameterValue(org.ligoj.app.model.ParameterValue) Project(org.ligoj.app.model.Project) DescribedBean(org.ligoj.bootstrap.core.DescribedBean) ParameterValueVo(org.ligoj.app.resource.node.ParameterValueVo) ParameterValue(org.ligoj.app.model.ParameterValue) TreeMap(java.util.TreeMap) SubscriptionVo(org.ligoj.app.resource.subscription.SubscriptionVo)

Example 13 with Subscription

use of org.ligoj.app.model.Subscription in project ligoj-api by ligoj.

the class SubscriptionResource method delete.

/**
 * Delete entity and cascaded associations : parameters, events then subscription.
 *
 * @param id
 *            the entity identifier.
 * @param deleteRemoteData
 *            When <code>true</code>, remote data will be also destroyed.
 * @throws Exception
 *             When the delete fails. Managed at JAX-RS level.
 */
@Path("{id:\\d+}/{deleteRemoteData}")
@DELETE
public void delete(@PathParam("id") final int id, @PathParam("deleteRemoteData") final boolean deleteRemoteData) throws Exception {
    final Subscription entity = checkVisibleSubscription(id);
    checkManagedProject(entity.getProject().getId());
    // Delete the events
    eventRepository.deleteAllBy("subscription", entity);
    // Delegate the deletion
    deleteWithTasks(entity.getNode().getId(), id, deleteRemoteData);
    parameterValueResource.deleteBySubscription(id);
    repository.delete(entity);
}
Also used : Subscription(org.ligoj.app.model.Subscription) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 14 with Subscription

use of org.ligoj.app.model.Subscription in project ligoj-api by ligoj.

the class SubscriptionResource method toEntity.

/**
 * {@link SubscriptionEditionVo} to JPA entity transformer.
 *
 * @param vo
 *            The object to convert.
 * @param project
 *            The related project.
 * @param node
 *            The related node.
 * @return The mapped entity.
 */
public static Subscription toEntity(final SubscriptionEditionVo vo, final Project project, final Node node) {
    final Subscription entity = new Subscription();
    entity.setProject(project);
    entity.setId(vo.getId());
    entity.setNode(node);
    return entity;
}
Also used : Subscription(org.ligoj.app.model.Subscription)

Example 15 with Subscription

use of org.ligoj.app.model.Subscription in project ligoj-api by ligoj.

the class TestAbstractConfiguredServicePlugin method checkVisibilityKo.

@Test
public void checkVisibilityKo() {
    final Subscription subscription = new Subscription();
    final Node node = new Node();
    node.setId("service:s:t:i");
    subscription.setNode(node);
    subscription.setId(2000);
    Assertions.assertThrows(EntityNotFoundException.class, () -> {
        resource.checkVisibility(subscription, "any");
    });
}
Also used : Node(org.ligoj.app.model.Node) Subscription(org.ligoj.app.model.Subscription) Test(org.junit.jupiter.api.Test)

Aggregations

Subscription (org.ligoj.app.model.Subscription)43 Test (org.junit.jupiter.api.Test)22 Path (javax.ws.rs.Path)10 Node (org.ligoj.app.model.Node)10 AbstractServerTest (org.ligoj.app.AbstractServerTest)9 IOException (java.io.IOException)7 GET (javax.ws.rs.GET)7 POST (javax.ws.rs.POST)7 HashMap (java.util.HashMap)6 Transactional (javax.transaction.Transactional)6 Produces (javax.ws.rs.Produces)6 Map (java.util.Map)5 Optional (java.util.Optional)5 PathParam (javax.ws.rs.PathParam)5 MediaType (javax.ws.rs.core.MediaType)5 Slf4j (lombok.extern.slf4j.Slf4j)5 File (java.io.File)4 Date (java.util.Date)4 Function (java.util.function.Function)4 DELETE (javax.ws.rs.DELETE)4