List of usage examples for org.apache.commons.lang3.tuple Triple getMiddle
public abstract M getMiddle();
Gets the middle element from this triple.
From source file:org.apache.olingo.ext.pojogen.AbstractPOJOGenMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (new File(outputDirectory + File.separator + TOOL_DIR).exists()) { getLog().info("Nothing to do because " + TOOL_DIR + " directory already exists. Clean to update."); return;//from w w w . ja v a 2s. co m } Velocity.addProperty(Velocity.RESOURCE_LOADER, "class"); Velocity.addProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName()); try { final Triple<XMLMetadata, String, Edm> metadata = getMetadata(); for (EdmSchema schema : metadata.getRight().getSchemas()) { namespaces.add(schema.getNamespace().toLowerCase()); } final Map<String, String> entityTypeNames = new HashMap<String, String>(); final Map<String, String> complexTypeNames = new HashMap<String, String>(); final Map<String, String> enumTypeNames = new HashMap<String, String>(); final Map<String, String> termNames = new HashMap<String, String>(); final Map<String, Object> objs = new HashMap<String, Object>(); for (EdmSchema schema : metadata.getRight().getSchemas()) { createUtility(metadata.getRight(), schema, basePackage); // write package-info for the base package final String schemaPath = utility.getNamespace().toLowerCase().replace('.', File.separatorChar); final File base = mkPkgDir(schemaPath); final String pkg = StringUtils.isBlank(basePackage) ? utility.getNamespace().toLowerCase() : basePackage + "." + utility.getNamespace().toLowerCase(); parseObj(base, pkg, "package-info", "package-info.java"); // write package-info for types package final File typesBaseDir = mkPkgDir(schemaPath + "/types"); final String typesPkg = pkg + ".types"; parseObj(typesBaseDir, typesPkg, "package-info", "package-info.java"); for (EdmTerm term : schema.getTerms()) { final String className = utility.capitalize(term.getName()); termNames.put(term.getFullQualifiedName().toString(), typesPkg + "." + className); objs.clear(); objs.put("term", term); parseObj(typesBaseDir, typesPkg, "term", className + ".java", objs); } for (EdmEnumType enumType : schema.getEnumTypes()) { final String className = utility.capitalize(enumType.getName()); enumTypeNames.put(enumType.getFullQualifiedName().toString(), typesPkg + "." + className); objs.clear(); objs.put("enumType", enumType); parseObj(typesBaseDir, typesPkg, "enumType", className + ".java", objs); } final List<EdmComplexType> complexes = new ArrayList<EdmComplexType>(); for (EdmComplexType complex : schema.getComplexTypes()) { complexes.add(complex); final String className = utility.capitalize(complex.getName()); complexTypeNames.put(complex.getFullQualifiedName().toString(), typesPkg + "." + className); objs.clear(); objs.put("complexType", complex); parseObj(typesBaseDir, typesPkg, "complexType", className + ".java", objs); parseObj(typesBaseDir, typesPkg, "complexTypeComposableInvoker", className + "ComposableInvoker.java", objs); parseObj(typesBaseDir, typesPkg, "complexCollection", className + "Collection.java", objs); parseObj(typesBaseDir, typesPkg, "complexCollectionComposableInvoker", className + "CollectionComposableInvoker.java", objs); } for (EdmEntityType entity : schema.getEntityTypes()) { final String className = utility.capitalize(entity.getName()); entityTypeNames.put(entity.getFullQualifiedName().toString(), typesPkg + "." + className); objs.clear(); objs.put("entityType", entity); final Map<String, String> keys; EdmEntityType baseType = null; if (entity.getBaseType() == null) { keys = getUtility().getEntityKeyType(entity); } else { baseType = entity.getBaseType(); objs.put("baseType", getUtility().getJavaType(baseType.getFullQualifiedName().toString())); while (baseType.getBaseType() != null) { baseType = baseType.getBaseType(); } keys = getUtility().getEntityKeyType(baseType); } if (keys.size() > 1) { // create compound key class final String keyClassName = utility .capitalize(baseType == null ? entity.getName() : baseType.getName()) + "Key"; objs.put("keyRef", keyClassName); if (entity.getBaseType() == null) { objs.put("keys", keys); parseObj(typesBaseDir, typesPkg, "entityTypeKey", keyClassName + ".java", objs); } } parseObj(typesBaseDir, typesPkg, "entityType", className + ".java", objs); parseObj(typesBaseDir, typesPkg, "entityComposableInvoker", className + "ComposableInvoker.java", objs); parseObj(typesBaseDir, typesPkg, "entityCollection", className + "Collection.java", objs); parseObj(typesBaseDir, typesPkg, "entityCollectionComposableInvoker", className + "CollectionComposableInvoker.java", objs); } // write container and top entity sets into the base package EdmEntityContainer container = schema.getEntityContainer(); if (container != null) { objs.clear(); objs.put("container", container); objs.put("namespace", schema.getNamespace()); objs.put("complexes", complexes); parseObj(base, pkg, "container", utility.capitalize(container.getName()) + ".java", objs); for (EdmEntitySet entitySet : container.getEntitySets()) { objs.clear(); objs.put("entitySet", entitySet); objs.put("container", container); parseObj(base, pkg, "entitySet", utility.capitalize(entitySet.getName()) + ".java", objs); } } } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final GZIPOutputStream gzos = new GZIPOutputStream(baos); final ObjectOutputStream oos = new ObjectOutputStream(gzos); try { oos.writeObject(metadata.getLeft()); } finally { oos.close(); gzos.close(); baos.close(); } objs.clear(); objs.put("metadata", new String(Base64.encodeBase64(baos.toByteArray()), "UTF-8")); objs.put("metadataETag", metadata.getMiddle()); objs.put("entityTypes", entityTypeNames); objs.put("complexTypes", complexTypeNames); objs.put("enumTypes", enumTypeNames); objs.put("terms", termNames); final String actualBP = StringUtils.isBlank(basePackage) ? StringUtils.EMPTY : basePackage; parseObj(mkdir(actualBP.replace('.', File.separatorChar)), actualBP, "service", "Service.java", objs); } catch (Exception t) { getLog().error(t); throw (t instanceof MojoExecutionException) ? (MojoExecutionException) t : new MojoExecutionException("While executin mojo", t); } }
From source file:org.apache.olingo.ext.proxy.commons.AbstractCollectionInvocationHandler.java
public Collection<T> execute() { if (this.uri != null) { final Triple<List<T>, URI, List<ClientAnnotation>> res = fetchPartial(this.uri.build(), itemRef); this.nextPageURI = res.getMiddle(); if (items == null) { items = res.getLeft();// www. ja v a2s .c om } else { items.clear(); items.addAll(res.getLeft()); } annotations.clear(); annotations.addAll(res.getRight()); } return this; }
From source file:org.apache.olingo.ext.proxy.commons.EntitySetInvocationHandler.java
@SuppressWarnings("unchecked") public <S extends T, SEC extends EntityCollection<S, ?, ?>> SEC execute(final Class<SEC> collTypeRef) { final Class<S> ref = (Class<S>) ClassUtils.extractTypeArg(collTypeRef, AbstractEntitySet.class, AbstractSingleton.class, EntityCollection.class); final Class<S> oref = (Class<S>) ClassUtils.extractTypeArg(this.collItemRef, AbstractEntitySet.class, AbstractSingleton.class, EntityCollection.class); if (!oref.equals(ref)) { uri.appendDerivedEntityTypeSegment( new FullQualifiedName(ClassUtils.getNamespace(ref), ClassUtils.getEntityTypeName(ref)) .toString());/*from w w w . ja va 2 s.c o m*/ } final List<ClientAnnotation> anns = new ArrayList<ClientAnnotation>(); final Triple<List<T>, URI, List<ClientAnnotation>> entitySet = fetchPartial(uri.build(), (Class<T>) ref); anns.addAll(entitySet.getRight()); final EntityCollectionInvocationHandler<S> entityCollectionHandler = new EntityCollectionInvocationHandler<S>( service, (List<S>) entitySet.getLeft(), collTypeRef, this.baseURI, uri); entityCollectionHandler.setAnnotations(anns); entityCollectionHandler.nextPageURI = entitySet.getMiddle(); return (SEC) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { collTypeRef }, entityCollectionHandler); }
From source file:org.apache.olingo.ext.proxy.commons.EntitySetInvocationHandler.java
@SuppressWarnings("unchecked") public <S extends T, SEC extends EntityCollection<S, ?, ?>> SEC fetchWholeEntitySet(final URIBuilder uriBuilder, final Class<S> typeRef, final Class<SEC> collTypeRef) { final List<S> res = new ArrayList<S>(); final List<ClientAnnotation> anns = new ArrayList<ClientAnnotation>(); URI nextURI = uriBuilder.build(); while (nextURI != null) { final Triple<List<T>, URI, List<ClientAnnotation>> entitySet = fetchPartial(nextURI, (Class<T>) typeRef); res.addAll((List<S>) entitySet.getLeft()); nextURI = entitySet.getMiddle(); anns.addAll(entitySet.getRight()); }/* w ww . j a v a 2 s . c o m*/ final EntityCollectionInvocationHandler<S> entityCollectionHandler = new EntityCollectionInvocationHandler<S>( service, res, collTypeRef, targetEntitySetURI, uriBuilder); entityCollectionHandler.setAnnotations(anns); return (SEC) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { collTypeRef }, entityCollectionHandler); }
From source file:org.apache.olingo.ext.proxy.commons.EntitySetIterator.java
private void goOn() { final Triple<List<T>, URI, List<ClientAnnotation>> entitySet = esi.fetchPartial(this.next, this.esi.getTypeRef()); this.current = entitySet.getLeft().iterator(); this.next = entitySet.getMiddle(); }
From source file:org.apache.pulsar.compaction.CompactedTopicTest.java
@Test public void testEntryLookup() throws Exception { BookKeeper bk = pulsar.getBookKeeperClientFactory().create(this.conf, null); Triple<Long, List<Pair<MessageIdData, Long>>, List<Pair<MessageIdData, Long>>> compactedLedgerData = buildCompactedLedger( bk, 500);// ww w .j a v a2 s . co m List<Pair<MessageIdData, Long>> positions = compactedLedgerData.getMiddle(); List<Pair<MessageIdData, Long>> idsInGaps = compactedLedgerData.getRight(); LedgerHandle lh = bk.openLedger(compactedLedgerData.getLeft(), Compactor.COMPACTED_TOPIC_LEDGER_DIGEST_TYPE, Compactor.COMPACTED_TOPIC_LEDGER_PASSWORD); long lastEntryId = lh.getLastAddConfirmed(); AsyncLoadingCache<Long, MessageIdData> cache = CompactedTopicImpl.createCache(lh, 50); MessageIdData firstPositionId = positions.get(0).getLeft(); Pair<MessageIdData, Long> lastPosition = positions.get(positions.size() - 1); // check ids before and after ids in compacted ledger Assert.assertEquals(CompactedTopicImpl.findStartPoint(new PositionImpl(0, 0), lastEntryId, cache).get(), Long.valueOf(0)); Assert.assertEquals( CompactedTopicImpl.findStartPoint(new PositionImpl(Long.MAX_VALUE, 0), lastEntryId, cache).get(), Long.valueOf(CompactedTopicImpl.NEWER_THAN_COMPACTED)); // entry 0 is never in compacted ledger due to how we generate dummy Assert.assertEquals(CompactedTopicImpl .findStartPoint(new PositionImpl(firstPositionId.getLedgerId(), 0), lastEntryId, cache).get(), Long.valueOf(0)); // check next id after last id in compacted ledger Assert.assertEquals( CompactedTopicImpl.findStartPoint(new PositionImpl(lastPosition.getLeft().getLedgerId(), lastPosition.getLeft().getEntryId() + 1), lastEntryId, cache).get(), Long.valueOf(CompactedTopicImpl.NEWER_THAN_COMPACTED)); // shuffle to make cache work hard Collections.shuffle(positions, r); Collections.shuffle(idsInGaps, r); // Check ids we know are in compacted ledger for (Pair<MessageIdData, Long> p : positions) { PositionImpl pos = new PositionImpl(p.getLeft().getLedgerId(), p.getLeft().getEntryId()); Long got = CompactedTopicImpl.findStartPoint(pos, lastEntryId, cache).get(); Assert.assertEquals(got, Long.valueOf(p.getRight())); } // Check ids we know are in the gaps of the compacted ledger for (Pair<MessageIdData, Long> gap : idsInGaps) { PositionImpl pos = new PositionImpl(gap.getLeft().getLedgerId(), gap.getLeft().getEntryId()); Assert.assertEquals(CompactedTopicImpl.findStartPoint(pos, lastEntryId, cache).get(), Long.valueOf(gap.getRight())); } }
From source file:org.apache.syncope.client.console.panels.DashboardOverviewPanel.java
public DashboardOverviewPanel(final String id) { super(id);/*w w w . j av a 2 s .c o m*/ NumbersInfo numbers = restClient.numbers(); WebMarkupContainer container = new WebMarkupContainer("container"); container.setOutputMarkupId(true); add(container); totalUsers = new NumberWidget("totalUsers", "bg-yellow", numbers.getTotalUsers(), getString("users"), "ion ion-person"); container.add(totalUsers); totalGroups = new NumberWidget("totalGroups", "bg-red", numbers.getTotalGroups(), getString("groups"), "ion ion-person-stalker"); container.add(totalGroups); Triple<Integer, String, String> built = buildTotalAny1OrRoles(numbers); totalAny1OrRoles = new NumberWidget("totalAny1OrRoles", "bg-green", built.getLeft(), built.getMiddle(), built.getRight()); container.add(totalAny1OrRoles); built = buildTotalAny2OrResources(numbers); totalAny2OrResources = new NumberWidget("totalAny2OrResources", "bg-aqua", built.getLeft(), built.getMiddle(), built.getRight()); container.add(totalAny2OrResources); usersByStatus = new UsersByStatusWidget("usersByStatus", numbers.getUsersByStatus()); container.add(usersByStatus); completeness = new CompletenessWidget("completeness", numbers.getConfCompleteness()); container.add(completeness); anyByRealm = new AnyByRealmWidget("anyByRealm", numbers.getUsersByRealm(), numbers.getGroupsByRealm(), numbers.getAnyType1(), numbers.getAny1ByRealm(), numbers.getAnyType2(), numbers.getAny2ByRealm()); container.add(anyByRealm); load = new LoadWidget("load", restClient.system()); container.add(load); container.add(new IndicatorAjaxTimerBehavior(Duration.seconds(60)) { private static final long serialVersionUID = -4426283634345968585L; @Override protected void onTimer(final AjaxRequestTarget target) { NumbersInfo numbers = restClient.numbers(); if (totalUsers.refresh(numbers.getTotalUsers())) { target.add(totalUsers); } if (totalGroups.refresh(numbers.getTotalGroups())) { target.add(totalGroups); } Triple<Integer, String, String> updatedBuild = buildTotalAny1OrRoles(numbers); if (totalAny1OrRoles.refresh(updatedBuild.getLeft())) { target.add(totalAny1OrRoles); } updatedBuild = buildTotalAny2OrResources(numbers); if (totalAny2OrResources.refresh(updatedBuild.getLeft())) { target.add(totalAny2OrResources); } if (usersByStatus.refresh(numbers.getUsersByStatus())) { target.add(usersByStatus); } if (completeness.refresh(numbers.getConfCompleteness())) { target.add(completeness); } if (anyByRealm.refresh(numbers.getUsersByRealm(), numbers.getGroupsByRealm(), numbers.getAnyType1(), numbers.getAny1ByRealm(), numbers.getAnyType2(), numbers.getAny2ByRealm())) { target.add(anyByRealm); } load.refresh(restClient.system()); target.add(load); } }); }
From source file:org.apache.syncope.core.logic.AbstractJobLogic.java
protected List<JobTO> doListJobs() { List<JobTO> jobTOs = new ArrayList<>(); try {/*from w ww. j a v a2 s . c o m*/ for (JobKey jobKey : scheduler.getScheduler() .getJobKeys(GroupMatcher.jobGroupEquals(Scheduler.DEFAULT_GROUP))) { JobTO jobTO = new JobTO(); Triple<JobType, String, String> reference = getReference(jobKey); if (reference != null) { jobTOs.add(jobTO); jobTO.setType(reference.getLeft()); jobTO.setRefKey(reference.getMiddle()); jobTO.setRefDesc(reference.getRight()); List<? extends Trigger> jobTriggers = scheduler.getScheduler().getTriggersOfJob(jobKey); if (jobTriggers.isEmpty()) { jobTO.setScheduled(false); } else { jobTO.setScheduled(true); jobTO.setStart(jobTriggers.get(0).getStartTime()); } jobTO.setRunning(jobManager.isRunning(jobKey)); } } } catch (SchedulerException e) { LOG.debug("Problems while retrieving scheduled jobs", e); } return jobTOs; }
From source file:org.apache.syncope.core.logic.ResourceLogic.java
@PreAuthorize("hasRole('" + StandardEntitlement.RESOURCE_GET_CONNOBJECT + "')") @Transactional(readOnly = true)//from w w w. j av a 2 s . c o m public ConnObjectTO readConnObject(final String key, final String anyTypeKey, final String anyKey) { Triple<ExternalResource, AnyType, Provision> init = connObjectInit(key, anyTypeKey); // 1. find any Any<?> any = init.getMiddle().getKind() == AnyTypeKind.USER ? userDAO.find(anyKey) : init.getMiddle().getKind() == AnyTypeKind.ANY_OBJECT ? anyObjectDAO.find(anyKey) : groupDAO.find(anyKey); if (any == null) { throw new NotFoundException(init.getMiddle() + " " + anyKey); } // 2. build connObjectKeyItem Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(init.getRight()); if (!connObjectKeyItem.isPresent()) { throw new NotFoundException( "ConnObjectKey mapping for " + init.getMiddle() + " " + anyKey + " on resource '" + key + "'"); } Optional<String> connObjectKeyValue = mappingManager.getConnObjectKeyValue(any, init.getRight()); // 3. determine attributes to query Set<MappingItem> linkinMappingItems = virSchemaDAO.findByProvision(init.getRight()).stream() .map(virSchema -> virSchema.asLinkingMappingItem()).collect(Collectors.toSet()); Iterator<MappingItem> mapItems = new IteratorChain<>(init.getRight().getMapping().getItems().iterator(), linkinMappingItems.iterator()); // 4. read from the underlying connector Connector connector = connFactory.getConnector(init.getLeft()); ConnectorObject connectorObject = connector.getObject(init.getRight().getObjectClass(), AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKeyValue.get()), MappingUtils.buildOperationOptions(mapItems)); if (connectorObject == null) { throw new NotFoundException("Object " + connObjectKeyValue.get() + " with class " + init.getRight().getObjectClass() + " not found on resource " + key); } // 5. build result Set<Attribute> attributes = connectorObject.getAttributes(); if (AttributeUtil.find(Uid.NAME, attributes) == null) { attributes.add(connectorObject.getUid()); } if (AttributeUtil.find(Name.NAME, attributes) == null) { attributes.add(connectorObject.getName()); } return ConnObjectUtils.getConnObjectTO(connectorObject); }
From source file:org.apache.syncope.core.logic.SAML2SPLogic.java
@PreAuthorize("hasRole('" + StandardEntitlement.ANONYMOUS + "')") public SAML2RequestTO createLoginRequest(final String spEntityID, final String idpEntityID) { check();/* w w w.j av a 2s . c o m*/ // 1. look for IdP SAML2IdPEntity idp = StringUtils.isBlank(idpEntityID) ? cache.getFirst() : cache.get(idpEntityID); if (idp == null) { if (StringUtils.isBlank(idpEntityID)) { List<SAML2IdP> all = saml2IdPDAO.findAll(); if (!all.isEmpty()) { idp = getIdP(all.get(0).getKey()); } } else { idp = getIdP(idpEntityID); } } if (idp == null) { throw new NotFoundException( StringUtils.isBlank(idpEntityID) ? "Any SAML 2.0 IdP" : "SAML 2.0 IdP '" + idpEntityID + "'"); } if (idp.getSSOLocation(idp.getBindingType()) == null) { throw new IllegalArgumentException("No SingleSignOnService available for " + idp.getId()); } // 2. create AuthnRequest Issuer issuer = new IssuerBuilder().buildObject(); issuer.setValue(spEntityID); NameIDPolicy nameIDPolicy = new NameIDPolicyBuilder().buildObject(); if (idp.supportsNameIDFormat(NameIDType.TRANSIENT)) { nameIDPolicy.setFormat(NameIDType.TRANSIENT); } else if (idp.supportsNameIDFormat(NameIDType.PERSISTENT)) { nameIDPolicy.setFormat(NameIDType.PERSISTENT); } else { throw new IllegalArgumentException("Could not find supported NameIDFormat for IdP " + idpEntityID); } nameIDPolicy.setAllowCreate(true); nameIDPolicy.setSPNameQualifier(spEntityID); AuthnContextClassRef authnContextClassRef = new AuthnContextClassRefBuilder().buildObject(); authnContextClassRef.setAuthnContextClassRef(AuthnContext.PPT_AUTHN_CTX); RequestedAuthnContext requestedAuthnContext = new RequestedAuthnContextBuilder().buildObject(); requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.EXACT); requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef); AuthnRequest authnRequest = new AuthnRequestBuilder().buildObject(); authnRequest.setID("_" + UUID_GENERATOR.generate().toString()); authnRequest.setForceAuthn(false); authnRequest.setIsPassive(false); authnRequest.setVersion(SAMLVersion.VERSION_20); authnRequest.setProtocolBinding(idp.getBindingType().getUri()); authnRequest.setIssueInstant(new DateTime()); authnRequest.setIssuer(issuer); authnRequest.setNameIDPolicy(nameIDPolicy); authnRequest.setRequestedAuthnContext(requestedAuthnContext); authnRequest.setDestination(idp.getSSOLocation(idp.getBindingType()).getLocation()); SAML2RequestTO requestTO = new SAML2RequestTO(); requestTO.setIdpServiceAddress(authnRequest.getDestination()); requestTO.setBindingType(idp.getBindingType()); try { // 3. generate relay state as JWT Map<String, Object> claims = new HashMap<>(); claims.put(JWT_CLAIM_IDP_DEFLATE, idp.isUseDeflateEncoding()); Triple<String, String, Date> relayState = accessTokenDataBinder.generateJWT(authnRequest.getID(), JWT_RELAY_STATE_DURATION, claims); // 4. sign and encode AuthnRequest switch (idp.getBindingType()) { case REDIRECT: requestTO.setRelayState(URLEncoder.encode(relayState.getMiddle(), StandardCharsets.UTF_8.name())); requestTO.setContent( URLEncoder.encode(saml2rw.encode(authnRequest, true), StandardCharsets.UTF_8.name())); requestTO.setSignAlg(URLEncoder.encode(saml2rw.getSigAlgo(), StandardCharsets.UTF_8.name())); requestTO.setSignature( URLEncoder.encode(saml2rw.sign(requestTO.getContent(), requestTO.getRelayState()), StandardCharsets.UTF_8.name())); break; case POST: default: requestTO.setRelayState(relayState.getMiddle()); saml2rw.sign(authnRequest); requestTO.setContent(saml2rw.encode(authnRequest, idp.isUseDeflateEncoding())); } } catch (Exception e) { LOG.error("While generating AuthnRequest", e); SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Unknown); sce.getElements().add(e.getMessage()); throw sce; } return requestTO; }